mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 14:05:29 +03:00
Add prefixe 'g_' to global variables in mert/evaluator.cpp
While the size of mert/evaluator.cpp is still relatively small, adding the marker to the variables allows us to easily distinguish them from local variables.
This commit is contained in:
parent
c5b9d80171
commit
f9eac588e7
@ -14,18 +14,18 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Scorer* scorer;
|
|
||||||
int bootstrap = 0;
|
|
||||||
void evaluate(const string& candFile);
|
void evaluate(const string& candFile);
|
||||||
void addStats(vector<int>& stats1, const vector<int>& stats2);
|
void addStats(vector<int>& stats1, const vector<int>& stats2);
|
||||||
float average(const vector<float>& list);
|
float average(const vector<float>& list);
|
||||||
float stdDeviation(const vector<float>& list, float avg);
|
float stdDeviation(const vector<float>& list, float avg);
|
||||||
string int2string(int n);
|
string int2string(int n);
|
||||||
|
|
||||||
bool moreFiles = false;
|
Scorer* g_scorer = NULL;
|
||||||
bool moreScorers = false;
|
int g_bootstrap = 0;
|
||||||
|
|
||||||
float alpha = 0.05;
|
bool g_has_more_files = false;
|
||||||
|
bool g_has_more_scorers = false;
|
||||||
|
const float g_alpha = 0.05;
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ int main(int argc, char** argv)
|
|||||||
candidate = string(optarg);
|
candidate = string(optarg);
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
bootstrap = atoi(optarg);
|
g_bootstrap = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
seed = strtol(optarg, NULL, 10);
|
seed = strtol(optarg, NULL, 10);
|
||||||
@ -102,7 +102,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bootstrap)
|
if (g_bootstrap)
|
||||||
{
|
{
|
||||||
if (hasSeed) {
|
if (hasSeed) {
|
||||||
cerr << "Seeding random numbers with " << seed << endl;
|
cerr << "Seeding random numbers with " << seed << endl;
|
||||||
@ -118,8 +118,6 @@ int main(int argc, char** argv)
|
|||||||
vector<string> candFiles;
|
vector<string> candFiles;
|
||||||
vector<string> scorerTypes;
|
vector<string> scorerTypes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (reference.length() == 0) throw runtime_error("You have to specify at least one reference file.");
|
if (reference.length() == 0) throw runtime_error("You have to specify at least one reference file.");
|
||||||
split(reference,',',refFiles);
|
split(reference,',',refFiles);
|
||||||
|
|
||||||
@ -128,18 +126,18 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
if (scorerType.length() == 0) throw runtime_error("You have to specify at least one scorer.");
|
if (scorerType.length() == 0) throw runtime_error("You have to specify at least one scorer.");
|
||||||
split(scorerType,';',scorerTypes);
|
split(scorerType,';',scorerTypes);
|
||||||
|
|
||||||
if (candFiles.size() > 1) moreFiles = true;
|
if (candFiles.size() > 1) g_has_more_files = true;
|
||||||
if (scorerTypes.size() > 1) moreScorers = true;
|
if (scorerTypes.size() > 1) g_has_more_scorers = true;
|
||||||
|
|
||||||
for (vector<string>::const_iterator fileIt = candFiles.begin(); fileIt != candFiles.end(); ++fileIt)
|
for (vector<string>::const_iterator fileIt = candFiles.begin(); fileIt != candFiles.end(); ++fileIt)
|
||||||
{
|
{
|
||||||
for (vector<string>::const_iterator scorerIt = scorerTypes.begin(); scorerIt != scorerTypes.end(); ++scorerIt)
|
for (vector<string>::const_iterator scorerIt = scorerTypes.begin(); scorerIt != scorerTypes.end(); ++scorerIt)
|
||||||
{
|
{
|
||||||
scorer = ScorerFactory::getScorer(*scorerIt,scorerConfig);
|
g_scorer = ScorerFactory::getScorer(*scorerIt,scorerConfig);
|
||||||
scorer->setReferenceFiles(refFiles);
|
g_scorer->setReferenceFiles(refFiles);
|
||||||
evaluate(*fileIt);
|
evaluate(*fileIt);
|
||||||
delete scorer;
|
delete g_scorer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,43 +161,43 @@ void evaluate(const string& candFile)
|
|||||||
string line;
|
string line;
|
||||||
while (getline(cand, line))
|
while (getline(cand, line))
|
||||||
{
|
{
|
||||||
scorer->prepareStats(entries.size(), line, scoreentry);
|
g_scorer->prepareStats(entries.size(), line, scoreentry);
|
||||||
entries.push_back(scoreentry);
|
entries.push_back(scoreentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = entries.size();
|
int n = entries.size();
|
||||||
if (bootstrap)
|
if (g_bootstrap)
|
||||||
{
|
{
|
||||||
vector<float> scores;
|
vector<float> scores;
|
||||||
for (int i = 0; i < bootstrap; ++i)
|
for (int i = 0; i < g_bootstrap; ++i)
|
||||||
{
|
{
|
||||||
// TODO: Use smart pointer for exceptional-safety.
|
// TODO: Use smart pointer for exceptional-safety.
|
||||||
ScoreData* scoredata = new ScoreData(*scorer);
|
ScoreData* scoredata = new ScoreData(*g_scorer);
|
||||||
for (int j = 0; j < n; ++j)
|
for (int j = 0; j < n; ++j)
|
||||||
{
|
{
|
||||||
int randomIndex = random() % n;
|
int randomIndex = random() % n;
|
||||||
string str_j = int2string(j);
|
string str_j = int2string(j);
|
||||||
scoredata->add(entries[randomIndex], str_j);
|
scoredata->add(entries[randomIndex], str_j);
|
||||||
}
|
}
|
||||||
scorer->setScoreData(scoredata);
|
g_scorer->setScoreData(scoredata);
|
||||||
candidates_t candidates(n, 0);
|
candidates_t candidates(n, 0);
|
||||||
float score = scorer->score(candidates);
|
float score = g_scorer->score(candidates);
|
||||||
scores.push_back(score);
|
scores.push_back(score);
|
||||||
delete scoredata;
|
delete scoredata;
|
||||||
}
|
}
|
||||||
|
|
||||||
float avg = average(scores);
|
float avg = average(scores);
|
||||||
|
|
||||||
sort(scores.begin(), scores.end());
|
sort(scores.begin(), scores.end());
|
||||||
|
|
||||||
int lbIdx = scores.size() * (alpha / 2);
|
int lbIdx = scores.size() * (g_alpha / 2);
|
||||||
int rbIdx = scores.size() * (1 - alpha / 2);
|
int rbIdx = scores.size() * (1 - g_alpha / 2);
|
||||||
|
|
||||||
float lb = scores[lbIdx];
|
float lb = scores[lbIdx];
|
||||||
float rb = scores[rbIdx];
|
float rb = scores[rbIdx];
|
||||||
|
|
||||||
if (moreFiles) cout << candFile << "\t";
|
if (g_has_more_files) cout << candFile << "\t";
|
||||||
if (moreScorers) cout << scorer->getName() << "\t";
|
if (g_has_more_scorers) cout << g_scorer->getName() << "\t";
|
||||||
|
|
||||||
cout.setf(ios::fixed,ios::floatfield);
|
cout.setf(ios::fixed,ios::floatfield);
|
||||||
cout.precision(4);
|
cout.precision(4);
|
||||||
@ -208,20 +206,20 @@ void evaluate(const string& candFile)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Use smart pointer for exceptional-safety.
|
// TODO: Use smart pointer for exceptional-safety.
|
||||||
ScoreData* scoredata = new ScoreData(*scorer);
|
ScoreData* scoredata = new ScoreData(*g_scorer);
|
||||||
for (int sid = 0; sid < n; ++sid)
|
for (int sid = 0; sid < n; ++sid)
|
||||||
{
|
{
|
||||||
string str_sid = int2string(sid);
|
string str_sid = int2string(sid);
|
||||||
scoredata->add(entries[sid], str_sid);
|
scoredata->add(entries[sid], str_sid);
|
||||||
}
|
}
|
||||||
scorer->setScoreData(scoredata);
|
g_scorer->setScoreData(scoredata);
|
||||||
candidates_t candidates(n, 0);
|
candidates_t candidates(n, 0);
|
||||||
float score = scorer->score(candidates);
|
float score = g_scorer->score(candidates);
|
||||||
delete scoredata;
|
delete scoredata;
|
||||||
|
|
||||||
if (moreFiles) cout << candFile << "\t";
|
if (g_has_more_files) cout << candFile << "\t";
|
||||||
if (moreScorers) cout << scorer->getName() << "\t";
|
if (g_has_more_scorers) cout << g_scorer->getName() << "\t";
|
||||||
|
|
||||||
cout.setf(ios::fixed,ios::floatfield);
|
cout.setf(ios::fixed,ios::floatfield);
|
||||||
cout.precision(4);
|
cout.precision(4);
|
||||||
cout << score << endl;
|
cout << score << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user