int ParseFloats( const char *pText, float *pFloat, int count ) { const char *pTemp = pText; int index = 0; while ( pTemp && count > 0 ) { // Skip current token / float pTemp = SkipText( pTemp ); // Skip any whitespace in between pTemp = SkipSpace( pTemp ); if ( pTemp ) { // Parse a float pFloat[index] = (float)atof( pTemp ); count--; index++; } } if ( count == 0 ) return 1; return 0; }
/* <c5400> ../engine/tmessage.c:177 */ NOXREF int ParseFloats(const char *pText, float *pFloat, int count) { const char *pTemp = pText; int index = 0; while (pTemp && count > 0) { pTemp = SkipText(pTemp); pTemp = SkipSpace(pTemp); if (pTemp) { pFloat[index] = (float)Q_atof(pTemp); count--; index++; } } if (count == 0) return 1; return 0; }
bool NeuralNet::ParseNorms(char *pData) { // null vectors int i; for(i = 0; i < mNInp16; i++) { mpNormMeans16[i] = 0.0f; mpNormDevs16[i] = 1.0f; } // mean vector char *pt = pData; pt = SkipSpaces(pt); if(strncmp(pt, "vec", strlen("vec")) != 0) { return false; } pt += strlen("vec"); pt = SkipSpaces(pt); int len; if(!GetIntValue(pt, &len)) { return false; } pt = SkipText(pt); float *pvct = mpNormMeans16; for(i = 0; i < mNInp; i++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pvct)) { return false; } pvct++; pt = SkipText(pt); } // standard deviation vector pt = SkipSpaces(pt); if(strncmp(pt, "vec", strlen("vec")) != 0) { return false; } pt += strlen("vec"); pt = SkipSpaces(pt); if(!GetIntValue(pt, &len)) { return false; } pt = SkipText(pt); pvct = mpNormDevs16; for(i = 0; i < mNInp; i++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pvct)) { return false; } pvct++; pt = SkipText(pt); } // puts("means"); // DumpMatrix(mpNormMeans16, 1, mNInp16, mNInp16); // puts("devs"); // DumpMatrix(mpNormDevs16, 1, mNInp16, mNInp16); return true; }
bool NeuralNet::ParseWeights(char *pData) { // null matrixes memset((void *)mpInpHidMatrix, 0, mNHid16 * mNInp16 * sizeof(float)); memset((void *)mpHidOutMatrix, 0, mNOut16 * mNHid16 * sizeof(float)); memset((void *)mpHiddenBiases, 0, mNHid16 * sizeof(float)); memset((void *)mpOutputBiases, 0, mNOut16 * sizeof(float)); // input to hidden matrix char *pt = pData; pt = SkipSpaces(pt); if(strncmp(pt, "weigvec", strlen("weigvec")) != 0) { return false; } pt += strlen("weigvec"); pt = SkipSpaces(pt); int n_inp_hid; if(!GetIntValue(pt, &n_inp_hid)) { return false; } pt = SkipText(pt); float *pmat = mpInpHidMatrix16; int i; for(i = 0; i < mNHid; i++) { int j; for(j = 0; j < mNInp; j++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pmat)) { return false; } pmat++; pt = SkipText(pt); } for(j = mNInp; j < mNInp16; j++) { *pmat = 0.0f; pmat++; } } // hidden to output matrix pt = SkipSpaces(pt); if(strncmp(pt, "weigvec", strlen("weigvec")) != 0) { return false; } pt += strlen("weigvec"); pt = SkipSpaces(pt); int n_hid_out; if(!GetIntValue(pt, &n_hid_out)) { return false; } pt = SkipText(pt); pmat = mpHidOutMatrix16; for(i = 0; i < mNOut; i++) { int j; for(j = 0; j < mNHid; j++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pmat)) { return false; } pmat++; pt = SkipText(pt); } for(j = mNHid; j < mNHid16; j++) { *pmat = 0.0f; pmat++; } } // hidden biases pt = SkipSpaces(pt); if(strncmp(pt, "biasvec", strlen("biasvec")) != 0) { return false; } pt += strlen("biasvec"); pt = SkipSpaces(pt); int n_biases_hid; if(!GetIntValue(pt, &n_biases_hid)) { return false; } pt = SkipText(pt); float *pvec = mpHiddenBiases16; for(i = 0; i < mNHid; i++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pvec)) { return false; } pvec++; pt = SkipText(pt); } // output biases pt = SkipSpaces(pt); if(strncmp(pt, "biasvec", strlen("biasvec")) != 0) { return false; } pt += strlen("biasvec"); pt = SkipSpaces(pt); int n_biases_out; if(!GetIntValue(pt, &n_biases_out)) { return false; } pt = SkipText(pt); pvec = mpOutputBiases16; for(i = 0; i < mNOut; i++) { pt = SkipSpaces(pt); if(!GetFloatValue(pt, pvec)) { return false; } pvec++; pt = SkipText(pt); } return true; }