void testhmm(string race, int index) { cout << "Testing with replay " << index << endl; Hmm hmm; hmm.loadFromRace(race); vector<unsigned long>* replay = loadReplayData(race, index); cout << "Replay length: " << replay->size() << endl << "Rep:"; for (vector<unsigned long>::iterator it = replay->begin(); it != replay->end(); it++) { cout.width(3); cout << (*it); } for (unsigned int i = 0; i < replay->size(); i++) { unsigned int missed = 0, j; cout << endl << "Pre:"; for (j = 0; j < i; j++) { cout.width(3); cout << replay->at(j); hmm.observe(replay->at(j)); } vector<unsigned long> *seq = hmm.predictMaxSeq(replay->size() - i); for (unsigned int k = j; k < replay->size(); k++) { cout.width(3); unsigned long prediction = seq->at(k - j); if (prediction != replay->at(k)){ missed++; cout << red << prediction; } else { cout << green << prediction; } } cout << white << " (" << (1.0 - missed / (double)(replay->size() - i)) << ")" << endl; hmm.reset(); delete seq; } }
void testdata(string race, int numLines, int *trials, int *correct, int advance) { Hmm hmm; hmm.loadFromRace(race); string filename = race + "/data.csv"; ifstream infile(filename.c_str()); string line; for (int z = 0; z < numLines; z++) { vector<unsigned long>* replay = loadReplayData(race, z); for (unsigned int i = 0; i < replay->size(); i++) { unsigned int missed = 0, j; for (j = 0; j < i; j++) { hmm.observe(replay->at(j)); } vector<unsigned long> *seq = hmm.predictMaxSeq(advance); for (unsigned int k = j - 1 + advance; k < replay->size() && k < j + advance; k++) { unsigned long prediction = seq->at(k - j); if (prediction == replay->at(k)){ correct[k]++; } trials[k]++; } hmm.reset(); delete seq; } cerr << "Ran " << z << " from " << numLines << endl; } }