diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 04:24:19 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 04:24:19 +0400 |
commit | 664ffe0130e76a32571965a5f9fce1f6ff176ae1 (patch) | |
tree | 098ca4c906c675ae023d3c8d729afc675ee9e62b /mert/evaluator.cpp | |
parent | 0fc56ae869a41ee77220b2468d4a0c1e2afd14aa (diff) |
Fix indentation.
Diffstat (limited to 'mert/evaluator.cpp')
-rw-r--r-- | mert/evaluator.cpp | 220 |
1 files changed, 109 insertions, 111 deletions
diff --git a/mert/evaluator.cpp b/mert/evaluator.cpp index e4625382e..c0c10f444 100644 --- a/mert/evaluator.cpp +++ b/mert/evaluator.cpp @@ -33,10 +33,8 @@ void usage() cerr<<"[--rseed|-r] the random seed for bootstraping (defaults to system clock)"<<endl; cerr<<"[--help|-h] print this message and exit"<<endl; exit(1); - } - static struct option long_options[] = { {"sctype",required_argument,0,'s'}, {"scconfig",required_argument,0,'c'}, @@ -65,27 +63,27 @@ int main(int argc, char** argv) int c; while ((c=getopt_long (argc,argv, "s:c:R:C:b:r:h", long_options, &option_index)) != -1) { switch(c) { - case 's': - scorerType = string(optarg); - break; - case 'c': - scorerConfig = string(optarg); - break; - case 'R': - reference = string(optarg); - break; - case 'C': - candidate = string(optarg); - break; - case 'b': - bootstrap = atoi(optarg); - break; - case 'r': - seed = strtol(optarg, NULL, 10); - hasSeed = true; - break; - default: - usage(); + case 's': + scorerType = string(optarg); + break; + case 'c': + scorerConfig = string(optarg); + break; + case 'R': + reference = string(optarg); + break; + case 'C': + candidate = string(optarg); + break; + case 'b': + bootstrap = atoi(optarg); + break; + case 'r': + seed = strtol(optarg, NULL, 10); + hasSeed = true; + break; + default: + usage(); } } @@ -101,30 +99,30 @@ int main(int argc, char** argv) } try { - vector<string> refFiles; - vector<string> candFiles; + vector<string> refFiles; + vector<string> candFiles; - if (reference.length() == 0) throw runtime_error("You have to specify at least one reference file."); - split(reference,',',refFiles); + if (reference.length() == 0) throw runtime_error("You have to specify at least one reference file."); + split(reference,',',refFiles); - if (candidate.length() == 0) throw runtime_error("You have to specify at least one candidate file."); - split(candidate,',',candFiles); + if (candidate.length() == 0) throw runtime_error("You have to specify at least one candidate file."); + split(candidate,',',candFiles); - scorer = ScorerFactory::getScorer(scorerType,scorerConfig); - cerr << "Using scorer: " << scorer->getName() << endl; + scorer = ScorerFactory::getScorer(scorerType,scorerConfig); + cerr << "Using scorer: " << scorer->getName() << endl; - scorer->setReferenceFiles(refFiles); - PrintUserTime("Reference files loaded"); + scorer->setReferenceFiles(refFiles); + PrintUserTime("Reference files loaded"); - for (vector<string>::const_iterator it = candFiles.begin(); it != candFiles.end(); ++it) - { - evaluate(*it); - } + for (vector<string>::const_iterator it = candFiles.begin(); it != candFiles.end(); ++it) + { + evaluate(*it); + } - PrintUserTime("Evaluation done"); + PrintUserTime("Evaluation done"); - delete scorer; + delete scorer; return EXIT_SUCCESS; } catch (const exception& e) { @@ -136,89 +134,89 @@ int main(int argc, char** argv) void evaluate(const string& candFile) { - ifstream cand(candFile.c_str()); - if (!cand.good()) throw runtime_error("Error opening candidate file"); - - vector<ScoreStats> entries; - - // Loading sentences and preparing statistics - ScoreStats scoreentry; - string line; - while (getline(cand, line)) - { - scorer->prepareStats(entries.size(), line, scoreentry); - entries.push_back(scoreentry); - } - - PrintUserTime("Candidate file " + candFile + " loaded and stats prepared"); - - int n = entries.size(); - if (bootstrap) - { - vector<float> scores; - for (int i = 0; i < bootstrap; ++i) - { - ScoreData* scoredata = new ScoreData(*scorer); - for (int j = 0; j < n; ++j) - { - int randomIndex = random() % n; - string str_j = int2string(j); - scoredata->add(entries[randomIndex], str_j); - } - scorer->setScoreData(scoredata); - candidates_t candidates(n, 0); - float score = scorer->score(candidates); - scores.push_back(score); - delete scoredata; - } - - float avg = average(scores); - float dev = stdDeviation(scores, avg); - - cout.setf(ios::fixed,ios::floatfield); - cout.precision(4); - cout << "File: " << candFile << "\t" << scorer->getName() << " Average score: " << avg << "\tStandard deviation: " << dev << endl; - } - else - { - ScoreData* scoredata = new ScoreData(*scorer); - for (int sid = 0; sid < n; ++sid) - { - string str_sid = int2string(sid); - scoredata->add(entries[sid], str_sid); - } - scorer->setScoreData(scoredata); - candidates_t candidates(n, 0); - float score = scorer->score(candidates); - delete scoredata; - - cout.setf(ios::fixed,ios::floatfield); - cout.precision(4); - cout << "File: " << candFile << "\t" << scorer->getName() << " Score: " << score << endl; - } + ifstream cand(candFile.c_str()); + if (!cand.good()) throw runtime_error("Error opening candidate file"); + + vector<ScoreStats> entries; + + // Loading sentences and preparing statistics + ScoreStats scoreentry; + string line; + while (getline(cand, line)) + { + scorer->prepareStats(entries.size(), line, scoreentry); + entries.push_back(scoreentry); + } + + PrintUserTime("Candidate file " + candFile + " loaded and stats prepared"); + + int n = entries.size(); + if (bootstrap) + { + vector<float> scores; + for (int i = 0; i < bootstrap; ++i) + { + ScoreData* scoredata = new ScoreData(*scorer); + for (int j = 0; j < n; ++j) + { + int randomIndex = random() % n; + string str_j = int2string(j); + scoredata->add(entries[randomIndex], str_j); + } + scorer->setScoreData(scoredata); + candidates_t candidates(n, 0); + float score = scorer->score(candidates); + scores.push_back(score); + delete scoredata; + } + + float avg = average(scores); + float dev = stdDeviation(scores, avg); + + cout.setf(ios::fixed,ios::floatfield); + cout.precision(4); + cout << "File: " << candFile << "\t" << scorer->getName() << " Average score: " << avg << "\tStandard deviation: " << dev << endl; + } + else + { + ScoreData* scoredata = new ScoreData(*scorer); + for (int sid = 0; sid < n; ++sid) + { + string str_sid = int2string(sid); + scoredata->add(entries[sid], str_sid); + } + scorer->setScoreData(scoredata); + candidates_t candidates(n, 0); + float score = scorer->score(candidates); + delete scoredata; + + cout.setf(ios::fixed,ios::floatfield); + cout.precision(4); + cout << "File: " << candFile << "\t" << scorer->getName() << " Score: " << score << endl; + } } string int2string(int n) { - stringstream ss; - ss << n; - return ss.str(); + stringstream ss; + ss << n; + return ss.str(); } float average(const vector<float>& list) { - float sum = 0; - for (vector<float>::const_iterator it = list.begin(); it != list.end(); ++it) - sum += *it; - - return sum / list.size(); + float sum = 0; + for (vector<float>::const_iterator it = list.begin(); it != list.end(); ++it) + sum += *it; + + return sum / list.size(); } float stdDeviation(const vector<float>& list, float avg) { - vector<float> tmp; - for (vector<float>::const_iterator it = list.begin(); it != list.end(); ++it) - tmp.push_back(pow(*it - avg, 2)); + vector<float> tmp; + for (vector<float>::const_iterator it = list.begin(); it != list.end(); ++it) + tmp.push_back(pow(*it - avg, 2)); - return sqrt(average(tmp)); + return sqrt(average(tmp)); } |