Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTetsuo Kiso <tetsuo-s@is.naist.jp>2012-03-18 08:08:38 +0400
committerTetsuo Kiso <tetsuo-s@is.naist.jp>2012-03-18 08:08:38 +0400
commit54233d327052793807fc44583334dd3b396176e5 (patch)
treedb01a4c85371b5d9669d2e82e366af42504b42fd /mert/OptimizerFactory.cpp
parent38c662d4e036558ce07cc4c469d11631b8186be8 (diff)
Create files for OptimizerFactory class; add the unit test.
Diffstat (limited to 'mert/OptimizerFactory.cpp')
-rw-r--r--mert/OptimizerFactory.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/mert/OptimizerFactory.cpp b/mert/OptimizerFactory.cpp
new file mode 100644
index 000000000..06b50d20b
--- /dev/null
+++ b/mert/OptimizerFactory.cpp
@@ -0,0 +1,66 @@
+#include "OptimizerFactory.h"
+#include "Optimizer.h"
+
+using namespace std;
+
+vector<string> OptimizerFactory::m_type_names;
+
+void OptimizerFactory::SetTypeNames()
+{
+ if (m_type_names.empty()) {
+ m_type_names.resize(NOPTIMIZER);
+ m_type_names[POWELL] = "powell";
+ m_type_names[RANDOM_DIRECTION] = "random-direction";
+ m_type_names[RANDOM] = "random";
+ // Add new type there
+ }
+}
+vector<string> OptimizerFactory::GetTypeNames()
+{
+ if (m_type_names.empty())
+ SetTypeNames();
+ return m_type_names;
+}
+
+OptimizerFactory::OptimizerType OptimizerFactory::GetOptimizerType(const string& type)
+{
+ unsigned int t;
+ if (m_type_names.empty())
+ SetTypeNames();
+ for (t = 0; t < m_type_names.size(); t++)
+ if (m_type_names[t] == type)
+ break;
+ return((OptimizerType)t);
+}
+
+Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim,
+ const vector<unsigned>& i2o,
+ const vector<parameter_t>& start,
+ const string& type,
+ unsigned int nrandom)
+{
+ OptimizerType opt_type = GetOptimizerType(type);
+ if (opt_type == NOPTIMIZER) {
+ cerr << "Error: unknown Optimizer type " << type << endl;
+ cerr << "Known Algorithm are:" << endl;
+ unsigned int t;
+ for (t = 0; t < m_type_names.size(); t++)
+ cerr << m_type_names[t] << endl;
+ throw ("unknown Optimizer Type");
+ }
+
+ switch (opt_type) {
+ case POWELL:
+ return new SimpleOptimizer(dim, i2o, start, nrandom);
+ break;
+ case RANDOM_DIRECTION:
+ return new RandomDirectionOptimizer(dim, i2o, start, nrandom);
+ break;
+ case RANDOM:
+ return new RandomOptimizer(dim, i2o, start, nrandom);
+ break;
+ default:
+ cerr << "Error: unknown optimizer" << type << endl;
+ return NULL;
+ }
+}