mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
3878135f8b
In the commit 4b6232b757
,
I thought I had fixed the bug around the tuning on a subset of
features by checking whether pdim and the length of the
active features which you want to optimize in the tuning.
However, it was wrong. I should set Point::optindices
appropriately according to specified the subset.
113 lines
2.3 KiB
C++
113 lines
2.3 KiB
C++
#ifndef MERT_POINT_H_
|
|
#define MERT_POINT_H_
|
|
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <vector>
|
|
#include "Types.h"
|
|
|
|
class FeatureStats;
|
|
class Optimizer;
|
|
|
|
/**
|
|
* A class that handles the subset of the Feature weight on which
|
|
* we run the optimization.
|
|
*/
|
|
class Point : public vector<parameter_t>
|
|
{
|
|
friend class Optimizer;
|
|
private:
|
|
/**
|
|
* The indices over which we optimize.
|
|
*/
|
|
static vector<unsigned int> optindices;
|
|
|
|
/**
|
|
* Dimension of optindices and of the parent vector.
|
|
*/
|
|
static unsigned int dim;
|
|
|
|
/**
|
|
* Fixed weights in case of partial optimzation.
|
|
*/
|
|
static map<unsigned int,parameter_t> fixedweights;
|
|
|
|
/**
|
|
* Total size of the parameter space; we have
|
|
* pdim = FixedWeight.size() + optinidices.size().
|
|
*/
|
|
static unsigned int pdim;
|
|
static unsigned int ncall;
|
|
|
|
/**
|
|
* The limits for randomization, both vectors are of full length, pdim.
|
|
*/
|
|
static vector<parameter_t> m_min;
|
|
static vector<parameter_t> m_max;
|
|
|
|
statscore_t score_;
|
|
|
|
public:
|
|
static unsigned int getdim() {
|
|
return dim;
|
|
}
|
|
static unsigned int getpdim() {
|
|
return pdim;
|
|
}
|
|
static void setpdim(size_t pd) {
|
|
pdim = pd;
|
|
}
|
|
static void setdim(size_t d) {
|
|
dim = d;
|
|
}
|
|
|
|
static void set_optindices(const vector<unsigned int>& indices) {
|
|
optindices = indices;
|
|
}
|
|
|
|
static const vector<unsigned int>& get_optindices() {
|
|
return optindices;
|
|
}
|
|
|
|
static bool OptimizeAll() {
|
|
return fixedweights.empty();
|
|
}
|
|
|
|
Point();
|
|
Point(const vector<parameter_t>& init,
|
|
const vector<parameter_t>& min,
|
|
const vector<parameter_t>& max);
|
|
~Point();
|
|
|
|
void Randomize();
|
|
|
|
// Compute the feature function
|
|
double operator*(const FeatureStats&) const;
|
|
Point operator+(const Point&) const;
|
|
void operator+=(const Point&);
|
|
Point operator*(float) const;
|
|
|
|
/**
|
|
* Write the Whole featureweight to a stream (ie pdim float).
|
|
*/
|
|
friend ostream& operator<<(ostream& o,const Point& P);
|
|
|
|
void Normalize() { NormalizeL2(); }
|
|
void NormalizeL2();
|
|
void NormalizeL1();
|
|
|
|
/**
|
|
* Return a vector of size pdim where all weights have been
|
|
* put (including fixed ones).
|
|
*/
|
|
vector<parameter_t> GetAllWeights() const;
|
|
|
|
statscore_t GetScore() const {
|
|
return score_;
|
|
}
|
|
|
|
void SetScore(statscore_t score) { score_ = score; }
|
|
};
|
|
|
|
#endif // MERT_POINT_H
|