diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
commit | 6249432407af8730c10bccc7894c0725fcaf5e47 (patch) | |
tree | 3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /mert/mert.cpp | |
parent | 59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff) |
beautify
Diffstat (limited to 'mert/mert.cpp')
-rw-r--r-- | mert/mert.cpp | 170 |
1 files changed, 87 insertions, 83 deletions
diff --git a/mert/mert.cpp b/mert/mert.cpp index e53c86be2..b73c536d1 100644 --- a/mert/mert.cpp +++ b/mert/mert.cpp @@ -30,7 +30,8 @@ using namespace std; using namespace MosesTuning; -namespace { +namespace +{ const char kDefaultOptimizer[] = "powell"; const char kDefaultScorer[] = "BLEU"; @@ -46,10 +47,11 @@ const char kOutputFile[] = "weights.txt"; /** * Runs an optimisation, or a random restart. */ -class OptimizationTask : public Moses::Task { - public: +class OptimizationTask : public Moses::Task +{ +public: OptimizationTask(Optimizer* optimizer, const Point& point) - : m_optimizer(optimizer), m_point(point) {} + : m_optimizer(optimizer), m_point(point) {} ~OptimizationTask() {} @@ -76,7 +78,7 @@ class OptimizationTask : public Moses::Task { return m_point; } - private: +private: // Do not allow the user to instanciate without arguments. OptimizationTask() {} @@ -85,7 +87,8 @@ class OptimizationTask : public Moses::Task { statscore_t m_score; }; -bool WriteFinalWeights(const char* filename, const Point& point) { +bool WriteFinalWeights(const char* filename, const Point& point) +{ ofstream ofs(filename); if (!ofs) { cerr << "Cannot open " << filename << endl; @@ -165,91 +168,92 @@ struct ProgramOption { size_t shard_count; ProgramOption() - : to_optimize_str(""), - pdim(-1), - ntry(1), - nrandom(0), - seed(0), - has_seed(false), - optimize_type(kDefaultOptimizer), - scorer_type(kDefaultScorer), - scorer_config(""), - scorer_file(kDefaultScorerFile), - feature_file(kDefaultFeatureFile), - init_file(kDefaultInitFile), - positive_string(kDefaultPositiveString), - sparse_weights_file(kDefaultSparseWeightsFile), - num_threads(1), - shard_size(0), - shard_count(0) { } + : to_optimize_str(""), + pdim(-1), + ntry(1), + nrandom(0), + seed(0), + has_seed(false), + optimize_type(kDefaultOptimizer), + scorer_type(kDefaultScorer), + scorer_config(""), + scorer_file(kDefaultScorerFile), + feature_file(kDefaultFeatureFile), + init_file(kDefaultInitFile), + positive_string(kDefaultPositiveString), + sparse_weights_file(kDefaultSparseWeightsFile), + num_threads(1), + shard_size(0), + shard_count(0) { } }; -void ParseCommandOptions(int argc, char** argv, ProgramOption* opt) { +void ParseCommandOptions(int argc, char** argv, ProgramOption* opt) +{ int c; int option_index; while ((c = getopt_long(argc, argv, "o:r:d:n:m:t:s:S:F:v:p:P:", long_options, &option_index)) != -1) { switch (c) { - case 'o': - opt->to_optimize_str = string(optarg); - break; - case 'd': - opt->pdim = strtol(optarg, NULL, 10); - break; - case 'n': - opt->ntry = strtol(optarg, NULL, 10); - break; - case 'm': - opt->nrandom = strtol(optarg, NULL, 10); - break; - case 'r': - opt->seed = strtol(optarg, NULL, 10); - opt->has_seed = true; - break; - case 't': - opt->optimize_type = string(optarg); - break; - case's': - opt->scorer_type = string(optarg); - break; - case 'c': - opt->scorer_config = string(optarg); - break; - case 'S': - opt->scorer_file = string(optarg); - break; - case 'F': - opt->feature_file = string(optarg); - break; - case 'i': - opt->init_file = string(optarg); - break; - case 'p': - opt->sparse_weights_file=string(optarg); - break; - case 'v': - setverboselevel(strtol(optarg, NULL, 10)); - break; + case 'o': + opt->to_optimize_str = string(optarg); + break; + case 'd': + opt->pdim = strtol(optarg, NULL, 10); + break; + case 'n': + opt->ntry = strtol(optarg, NULL, 10); + break; + case 'm': + opt->nrandom = strtol(optarg, NULL, 10); + break; + case 'r': + opt->seed = strtol(optarg, NULL, 10); + opt->has_seed = true; + break; + case 't': + opt->optimize_type = string(optarg); + break; + case's': + opt->scorer_type = string(optarg); + break; + case 'c': + opt->scorer_config = string(optarg); + break; + case 'S': + opt->scorer_file = string(optarg); + break; + case 'F': + opt->feature_file = string(optarg); + break; + case 'i': + opt->init_file = string(optarg); + break; + case 'p': + opt->sparse_weights_file=string(optarg); + break; + case 'v': + setverboselevel(strtol(optarg, NULL, 10)); + break; #ifdef WITH_THREADS - case 'T': - opt->num_threads = strtol(optarg, NULL, 10); - if (opt->num_threads < 1) opt->num_threads = 1; - break; + case 'T': + opt->num_threads = strtol(optarg, NULL, 10); + if (opt->num_threads < 1) opt->num_threads = 1; + break; #endif - case 'a': - opt->shard_count = strtof(optarg, NULL); - break; - case 'b': - opt->shard_size = strtof(optarg, NULL); - break; - case 'h': - usage(0); - break; - case 'P': - opt->positive_string = string(optarg); - break; - default: - usage(1); + case 'a': + opt->shard_count = strtof(optarg, NULL); + break; + case 'b': + opt->shard_size = strtof(optarg, NULL); + break; + case 'h': + usage(0); + break; + case 'P': + opt->positive_string = string(optarg); + break; + default: + usage(1); } } } @@ -353,7 +357,7 @@ int main(int argc, char **argv) // it make sense to know what parameter set were used to generate the nbest boost::scoped_ptr<Scorer> scorer( - ScorerFactory::getScorer(option.scorer_type, option.scorer_config)); + ScorerFactory::getScorer(option.scorer_type, option.scorer_config)); //load data Data data(scorer.get(), option.sparse_weights_file); |