realv Layer::signalWeighting(FeatureVector _signal, Mat _weights) { if (_signal.getLength() != ((uint) _weights.cols)) { throw length_error("Layer : Uncorrect length between signal and weights"); } realv sum = 0; for (uint i = 0; i < _signal.getLength(); i++) { sum += _signal[i] * _weights.at<realv>(0, i); } return sum; }
realv SEMeasurer::totalError(FeatureVector _output, FeatureVector _target) { if (_output.getLength() != _target.getLength()) { throw length_error("SE : Output and target do not have the same size"); } realv result = 0; for (uint i = 0; i < _output.getLength(); i++) { result += (_output[i] - _target[i]) * (_output[i] - _target[i]); } err = result; return err; }
ErrorVector SEMeasurer::errorPerUnit(FeatureVector _output, FeatureVector _target) { if (_output.getLength() != _target.getLength()) { throw length_error("SEMeasurer : Output and target do not have the same size"); } ErrorVector result(_output.getLength()); for (uint i = 0; i < _output.getLength(); i++) { result[i] = (_output[i] - _target[i]) * (_output[i] - _target[i]); } errPerUnit = result; return result; }
int main(int argc, char* argv[]) { vector<string> arguments; arguments.push_back("classification dataset"); arguments.push_back("save folder for the dataset, the folder must contain a lab, labTrain and htk subfolder"); arguments.push_back("model length, to suppres short training samples"); cout << helper("Create HTK learning files", "Create HTK learning files using a classification dataset.", arguments) << endl; if (argc != arguments.size() + 1) { cerr << "Not enough arguments, " << argc-1 << " given and "<< arguments.size()<<" required" << endl; return EXIT_FAILURE; } ClassificationDataset datasetBasic; datasetBasic.load(argv[1]); cout << "Loaded dataset" << endl; string saveLocation = argv[2]; vector<FeatureVector> sequence; int length = atoi(argv[3]); FeatureVector sample; AEMeasurer ae; ostringstream dictionnaryFileLocation; ostringstream htkScpFileLocation; ostringstream labScpFileLocation; map<string,string> dictionnary; dictionnaryFileLocation << saveLocation << "dictionnary.scp"; htkScpFileLocation << saveLocation << "dataFiles.scp"; labScpFileLocation << saveLocation << "labFiles.scp"; ofstream dictionnaryFile(dictionnaryFileLocation.str().c_str()); ofstream htkScp(htkScpFileLocation.str().c_str()); ofstream labScp(labScpFileLocation.str().c_str()); for (uint j = 0; j < datasetBasic.getNumSequences(); j++) { sequence = datasetBasic[j]; vector<string> target = datasetBasic.getSequenceClasses(j); if(sequence.size()>target.size()*length){ ostringstream sequenceFile, wordFile,wordFile2; ostringstream word, spacedLetters; sequenceFile << saveLocation << "htkn/" << j <<".htk"; wordFile << saveLocation << "lab/"<<j <<".lab"; wordFile2 << saveLocation << "labTrain/"<<j <<".lab"; htkScp << sequenceFile.str() << endl; labScp << wordFile.str() << endl; ofstream outputSequence(sequenceFile.str().c_str()); ofstream outputWord(wordFile.str().c_str()); ofstream outputWord2(wordFile2.str().c_str()); for (uint k = 0; k < sequence.size(); k++) { sample = sequence[k]; for (uint i = 0; i < sample.getLength(); i++) { outputSequence << sample[i] <<" " ; } outputSequence << endl; } for(uint k=0; k < target.size();k++){ outputWord << target[k] << endl; outputWord2 << target[k] ; word << target[k] ; spacedLetters << target[k] << " "; } dictionnary.insert(pair<string,string>(word.str(),spacedLetters.str())); outputWord.close(); outputSequence.close(); } } map<string,string>::iterator it ; for(it=dictionnary.begin();it!=dictionnary.end();it++){ dictionnaryFile << (*it).first << " " << (*it).second << endl; } return EXIT_SUCCESS; }