/* * Load Train Data (Signatures and respective names) from a directory * Returns the number of signatures read * TODO: make this windows compatible */ TrainData *Database::loadTrainDataFromDir(string dir, int *n) { Sig sig; vector<string> files = vector<string>(); string fname, temp; char buf[1024]; unsigned int ii; TrainData *data; getFileList(dir, files); data = new TrainData [files.size()]; getcwd(buf, 1024); // save current dir // cout << "Changing CWD to " << dir << "." << endl; chdir(dir.c_str()); // change current dir to data dir for (ii = 0; ii < files.size(); ii++) { fname = files[ii]; // cout << "Reading " << fname << "." << endl; sig.load(fname); data[ii].name = filenameToName(files[ii]); // Get Name from sig file data[ii].sigArr = sig.toArray(); // convert sig to array data[ii].value = (double) tableLookup(data[ii].name); /* get value * (table index) */ } // cout << "Back to previous CWD." << endl; chdir(buf); // change back to original working dir // cout << "Read a total of " << ii << " files." << endl; *n = ii; return data; }
int NeuralNet::test(string filePath, double *prob) { Sig testSig; double temp; double *test; int max, ii; testSig.load(filePath); test = testSig.toArray(); /* feed the test data to the net */ bp->ffwd(test); for (ii = 0 ; ii < numRes ; ii++) { if ((prob[ii] = bp->Out(ii)) > temp) { /* the highest value of the output nodes * will determine the actual result * i.e. who the test signature belongs to */ temp = bp->Out(ii); max = ii; } } return max; }