mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
Pass parameters by const reference.
This commit is contained in:
parent
e08392962a
commit
82c683758f
@ -32,7 +32,7 @@ inline float intersect(float m1, float b1, float m2, float b2)
|
||||
|
||||
} // namespace
|
||||
|
||||
Optimizer::Optimizer(unsigned Pd, vector<unsigned> i2O, vector<parameter_t> start, unsigned int nrandom)
|
||||
Optimizer::Optimizer(unsigned Pd, const vector<unsigned>& i2O, const vector<parameter_t>& start, unsigned int nrandom)
|
||||
: m_scorer(NULL), m_feature_data(), m_num_random_directions(nrandom)
|
||||
{
|
||||
// Warning: the init vector is a full set of parameters, of dimension m_pdim!
|
||||
@ -65,7 +65,7 @@ statscore_t Optimizer::GetStatScore(const Point& param) const
|
||||
return score;
|
||||
}
|
||||
|
||||
map<float,diff_t >::iterator AddThreshold(map<float,diff_t >& thresholdmap, float newt, pair<unsigned,unsigned> newdiff)
|
||||
map<float,diff_t >::iterator AddThreshold(map<float,diff_t >& thresholdmap, float newt, const pair<unsigned,unsigned>& newdiff)
|
||||
{
|
||||
map<float,diff_t>::iterator it = thresholdmap.find(newt);
|
||||
if (it != thresholdmap.end()) {
|
||||
@ -348,7 +348,7 @@ statscore_t Optimizer::Run(Point& P) const
|
||||
}
|
||||
|
||||
|
||||
vector<statscore_t> Optimizer::GetIncStatScore(vector<unsigned> thefirst, vector<vector <pair<unsigned,unsigned> > > thediffs) const
|
||||
vector<statscore_t> Optimizer::GetIncStatScore(const vector<unsigned>& thefirst, const vector<vector <pair<unsigned,unsigned> > >& thediffs) const
|
||||
{
|
||||
CHECK(m_scorer);
|
||||
|
||||
@ -495,7 +495,7 @@ OptimizerFactory::OptType OptimizerFactory::GetOType(const string& type)
|
||||
return((OptType)thetype);
|
||||
}
|
||||
|
||||
Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim, vector<unsigned> i2o, vector<parameter_t> start, const string& type, unsigned int nrandom)
|
||||
Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim, const vector<unsigned>& i2o, const vector<parameter_t>& start, const string& type, unsigned int nrandom)
|
||||
{
|
||||
OptType T = GetOType(type);
|
||||
if (T == NOPTIMIZER) {
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef float featurescore;
|
||||
|
||||
class Point;
|
||||
|
||||
/**
|
||||
@ -25,7 +23,7 @@ protected:
|
||||
unsigned int m_num_random_directions;
|
||||
|
||||
public:
|
||||
Optimizer(unsigned Pd, vector<unsigned> i2O, vector<parameter_t> start, unsigned int nrandom);
|
||||
Optimizer(unsigned Pd, const vector<unsigned>& i2O, const vector<parameter_t>& start, unsigned int nrandom);
|
||||
|
||||
void SetScorer(Scorer *scorer) { m_scorer = scorer; }
|
||||
void SetFeatureData(FeatureDataHandle feature_data) { m_feature_data = feature_data; }
|
||||
@ -59,7 +57,7 @@ public:
|
||||
|
||||
statscore_t GetStatScore(const Point& param) const;
|
||||
|
||||
vector<statscore_t> GetIncStatScore(vector<unsigned> ref, vector<vector<pair<unsigned,unsigned> > >) const;
|
||||
vector<statscore_t> GetIncStatScore(const vector<unsigned>& ref, const vector<vector<pair<unsigned,unsigned> > >& diffs) const;
|
||||
|
||||
/**
|
||||
* Get the optimal Lambda and the best score in a particular direction from a given Point.
|
||||
@ -77,7 +75,7 @@ class SimpleOptimizer : public Optimizer
|
||||
private:
|
||||
const float kEPS;
|
||||
public:
|
||||
SimpleOptimizer(unsigned dim, vector<unsigned> i2O, vector<parameter_t> start, unsigned int nrandom)
|
||||
SimpleOptimizer(unsigned dim, const vector<unsigned>& i2O, const vector<parameter_t>& start, unsigned int nrandom)
|
||||
: Optimizer(dim, i2O, start,nrandom), kEPS(0.0001) {}
|
||||
virtual statscore_t TrueRun(Point&) const;
|
||||
};
|
||||
@ -90,7 +88,7 @@ class RandomDirectionOptimizer : public Optimizer
|
||||
private:
|
||||
const float kEPS;
|
||||
public:
|
||||
RandomDirectionOptimizer(unsigned dim, vector<unsigned> i2O, vector<parameter_t> start, unsigned int nrandom)
|
||||
RandomDirectionOptimizer(unsigned dim, const vector<unsigned>& i2O, const vector<parameter_t>& start, unsigned int nrandom)
|
||||
: Optimizer(dim, i2O, start, nrandom), kEPS(0.0001) {}
|
||||
virtual statscore_t TrueRun(Point&) const;
|
||||
};
|
||||
@ -101,7 +99,7 @@ public:
|
||||
class RandomOptimizer : public Optimizer
|
||||
{
|
||||
public:
|
||||
RandomOptimizer(unsigned dim, vector<unsigned> i2O, vector<parameter_t> start, unsigned int nrandom)
|
||||
RandomOptimizer(unsigned dim, const vector<unsigned>& i2O, const vector<parameter_t>& start, unsigned int nrandom)
|
||||
: Optimizer(dim, i2O, start, nrandom) {}
|
||||
virtual statscore_t TrueRun(Point&) const;
|
||||
};
|
||||
@ -110,7 +108,7 @@ class OptimizerFactory
|
||||
{
|
||||
public:
|
||||
static vector<string> GetTypeNames();
|
||||
static Optimizer* BuildOptimizer(unsigned dim, vector<unsigned> tooptimize, vector<parameter_t> start, const string& type, unsigned int nrandom);
|
||||
static Optimizer* BuildOptimizer(unsigned dim, const vector<unsigned>& to_optimize, const vector<parameter_t>& start, const string& type, unsigned int nrandom);
|
||||
|
||||
private:
|
||||
OptimizerFactory() {}
|
||||
|
Loading…
Reference in New Issue
Block a user