diff options
author | jfouet <jfouet@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-15 14:57:20 +0400 |
---|---|---|
committer | jfouet <jfouet@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-15 14:57:20 +0400 |
commit | bfe36611108453efefa0ae0cba384c4f7dac4ebb (patch) | |
tree | c714cbaf181b3dddd873e31e67c8c195777eccce /mert/Point.cpp | |
parent | c2c30717e07b5ef3ef7b8f48e29f364c92e71d82 (diff) |
implementation of optimization on a subset of the parameters + debug mode in the makefile
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1695 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert/Point.cpp')
-rw-r--r-- | mert/Point.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/mert/Point.cpp b/mert/Point.cpp index 1bb6adbd8..a5f56a460 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -2,12 +2,23 @@ #include<cmath> #include <cassert> using namespace std; -void Point::randomize(const vector<lambda>& min,const vector<lambda>& max){ + + +vector<unsigned> Point::optindices; + +unsigned Point::dim=0; + +map<unsigned,lambda> Point::fixedweights; + +unsigned Point::pdim=0; + + +void Point::Randomize(const vector<lambda>& min,const vector<lambda>& max){ for (int i=0; i<size(); i++) operator[](i)= min[i] + (float)random()/RAND_MAX * (max[i]-min[i]); } -void Point::normalize(){ +void Point::Normalize(){ lambda norm=0.0; for (int i=0; i<size(); i++) norm+= operator[](i)*operator[](i); @@ -18,12 +29,19 @@ void Point::normalize(){ } } -double Point::operator*(FeatureStats& F)const{ +double Point::operator*(const FeatureStats& F)const{ double prod=0.0; -for (int i=0; i<size(); i++) - prod+= operator[](i)*F.get(i); + if(OptimizeAll()) + for (unsigned i=0; i<size(); i++) + prod+= operator[](i)*F.get(i); + else{ + for (unsigned i=0; i<size(); i++) + prod+= operator[](i)*F.get(optindices[i]); + for(map<unsigned,float >::iterator it=fixedweights.begin();it!=fixedweights.end();it++) + prod+=it->second*F.get(it->first); + } + return prod; } - Point Point::operator+(const Point& p2)const{ assert(p2.size()==size()); Point Res(*this); @@ -33,10 +51,28 @@ Point Point::operator+(const Point& p2)const{ return Res; }; -Point Point::operator*(float& l)const{ +Point Point::operator*(float l)const{ Point Res(*this); for(unsigned i=0;i<size();i++) Res[i]*=l; Res.score=numeric_limits<statscore>::max(); return Res; }; + + +vector<lambda> Point::GetAllWeights()const{ + vector<lambda> w; + if(OptimizeAll()){ + w=*this; + }else{ + w.resize(pdim); + for (int i=0; i<size(); i++) + w[optindices[i]]=operator[](i); + for(map<unsigned,float >::iterator it=fixedweights.begin();it!=fixedweights.end();it++) + w[it->first]=it->second; + } + return w; +}; + + + |