Beispiel #1
0
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;
	}
}
Beispiel #2
0
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;
	}
}
Beispiel #3
0
void testBuildingStats() {
	Hmm hmm;
	hmm.loadFromRace("P");
	BuildingStats stats;

    stats.readStatsFile("Z/stats.csv");
    stats.readOurStatsFile("P/stats.csv");
    stats.readRepliesFile("Z/replies.csv");
    int rep_state = stats.getReplyState(11);
    set<string> search;
    search.insert("Reaver");
    search.insert("Observer");
    int state = stats.getClosestState(search);
    int state2 = stats.getClosestState2(search);
    cout << state << " " << state2 << endl;
    set<string>* unitTypes = stats.decodeState(state);
    for (set<string>::iterator it = unitTypes->begin(); it != unitTypes->end(); it++) {
        cout << *it << ",";
    }
    cout << endl << endl;;
    set<string>* unitTypes2 = stats.decodeState(state2);
    for (set<string>::iterator it = unitTypes2->begin(); it != unitTypes2->end(); it++) {
        cout << *it << ",";
    }
    cout << endl;
}
Beispiel #4
0
void trainhmm(string race, int numStates, int maxIterations)
{
	Hmm hmm;
	hmm.makeEmitAndTransFiles(race, numStates);
	hmm.loadFromRace(race);
	ifstream istrm((race + "/data.csv").c_str());

	vector<vector<unsigned long>*> trainingSequences;
	hmm.readSeqs(istrm, trainingSequences);
	hmm.baumWelch(trainingSequences, maxIterations);
	hmm.saveProbs(race + "/hmm");
}