diff options
author | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-02-24 15:42:19 +0300 |
---|---|---|
committer | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-02-24 15:42:19 +0300 |
commit | 148c1e8305fbcf8dc0acd021fe5825842e0b3c8d (patch) | |
tree | 04041cbc625ff61db8d94471c6d2d1c61264f653 /mert/Point.cpp | |
parent | a59ad11b58acf5dd64ec6f5990bb4ef5b74ebf28 (diff) |
run beautify.perl. Consistent formatting for .h & .cpp files
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3899 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert/Point.cpp')
-rw-r--r-- | mert/Point.cpp | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/mert/Point.cpp b/mert/Point.cpp index dc88cba20..af57aaa98 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -10,22 +10,24 @@ vector<unsigned> Point::optindices; unsigned Point::dim=0; map<unsigned,statscore_t> Point::fixedweights; - + unsigned Point::pdim=0; unsigned Point::ncall=0; -void Point::Randomize(const vector<parameter_t>& min,const vector<parameter_t>& max){ +void Point::Randomize(const vector<parameter_t>& min,const vector<parameter_t>& max) +{ assert(min.size()==Point::dim); assert(max.size()==Point::dim); for (unsigned int i=0; i<size(); i++) operator[](i)= min[i] + (float)random()/(float)RAND_MAX * (float)(max[i]-min[i]); } -void Point::NormalizeL2(){ +void Point::NormalizeL2() +{ parameter_t norm=0.0; for (unsigned int i=0; i<size(); i++) norm+= operator[](i)*operator[](i); - if(norm!=0.0){ + if(norm!=0.0) { norm=sqrt(norm); for (unsigned int i=0; i<size(); i++) operator[](i)/=norm; @@ -33,22 +35,24 @@ void Point::NormalizeL2(){ } -void Point::NormalizeL1(){ +void Point::NormalizeL1() +{ parameter_t norm=0.0; for (unsigned int i=0; i<size(); i++) norm+= abs(operator[](i)); - if(norm!=0.0){ - for (unsigned int i=0; i<size(); i++) - operator[](i)/=norm; - } + if(norm!=0.0) { + for (unsigned int i=0; i<size(); i++) + operator[](i)/=norm; + } } //Can initialize from a vector of dim or pdim -Point::Point(const vector<parameter_t>& init):vector<parameter_t>(Point::dim){ - if(init.size()==dim){ +Point::Point(const vector<parameter_t>& init):vector<parameter_t>(Point::dim) +{ + if(init.size()==dim) { for (unsigned int i=0; i<Point::dim; i++) operator[](i)=init[i]; - }else{ + } else { assert(init.size()==pdim); for (unsigned int i=0; i<Point::dim; i++) operator[](i)=init[optindices[i]]; @@ -56,59 +60,64 @@ Point::Point(const vector<parameter_t>& init):vector<parameter_t>(Point::dim){ }; -double Point::operator*(const FeatureStats& F)const{ +double Point::operator*(const FeatureStats& F)const +{ ncall++;//to track performance double prod=0.0; if(OptimizeAll()) for (unsigned i=0; i<size(); i++) prod+= operator[](i)*F.get(i); - else{ + 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++) + 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{ +Point Point::operator+(const Point& p2)const +{ assert(p2.size()==size()); Point Res(*this); - for(unsigned i=0;i<size();i++) + for(unsigned i=0; i<size(); i++) Res[i]+=p2[i]; Res.score=numeric_limits<statscore_t>::max(); return Res; }; -Point Point::operator*(float l)const{ +Point Point::operator*(float l)const +{ Point Res(*this); - for(unsigned i=0;i<size();i++) + for(unsigned i=0; i<size(); i++) Res[i]*=l; Res.score=numeric_limits<statscore_t>::max(); return Res; }; - ostream& operator<<(ostream& o,const Point& P){ - vector<parameter_t> w=P.GetAllWeights(); +ostream& operator<<(ostream& o,const Point& P) +{ + vector<parameter_t> w=P.GetAllWeights(); // o << "[" << Point::pdim << "] "; - for(unsigned int i=0;i<Point::pdim;i++) - o << w[i] << " "; + for(unsigned int i=0; i<Point::pdim; i++) + o << w[i] << " "; // o << "=> " << P.GetScore(); - return o; + return o; }; -vector<parameter_t> Point::GetAllWeights()const{ +vector<parameter_t> Point::GetAllWeights()const +{ vector<parameter_t> w; - if(OptimizeAll()){ + if(OptimizeAll()) { w=*this; - }else{ + } else { w.resize(pdim); for (unsigned 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; + for(map<unsigned,float >::iterator it=fixedweights.begin(); it!=fixedweights.end(); it++) + w[it->first]=it->second; } return w; }; - + |