diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 11:39:57 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 11:39:57 +0400 |
commit | df0874df89429dc940df75b125a02362e3b1b539 (patch) | |
tree | bb4717e3b488c8be15b813395514dfa07a9921d1 /mert/Point.cpp | |
parent | fdcd148cac32bca8993e5e8b10e56f86f5f7e522 (diff) |
Make Point::score a private by defining accessor/mutator.
Diffstat (limited to 'mert/Point.cpp')
-rw-r--r-- | mert/Point.cpp | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/mert/Point.cpp b/mert/Point.cpp index 590225358..58f1e4fb1 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -1,60 +1,27 @@ #include "Point.h" -#include<cmath> -#include<cstdlib> +#include <cmath> +#include <cstdlib> #include <cassert> -using namespace std; +using namespace std; vector<unsigned> Point::optindices; -unsigned Point::dim=0; +unsigned Point::dim = 0; map<unsigned,statscore_t> Point::fixedweights; -unsigned Point::pdim=0; -unsigned Point::ncall=0; +unsigned Point::pdim = 0; +unsigned Point::ncall = 0; vector<parameter_t> Point::m_min; vector<parameter_t> Point::m_max; -void Point::Randomize() -{ - assert(m_min.size()==Point::dim); - assert(m_max.size()==Point::dim); - for (unsigned int i=0; i<size(); i++) - operator[](i)= m_min[i] - + (float)random()/(float)RAND_MAX * (float)(m_max[i]-m_min[i]); -} - -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) { - norm=sqrt(norm); - for (unsigned int i=0; i<size(); i++) - operator[](i)/=norm; - } -} - - -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; - } -} - //Can initialize from a vector of dim or pdim Point::Point(const vector<parameter_t>& init, - const vector<parameter_t>& min, - const vector<parameter_t>& max - ):vector<parameter_t>(Point::dim) + const vector<parameter_t>& min, + const vector<parameter_t>& max) + : vector<parameter_t>(Point::dim), score_(0.0f) { m_min.resize(Point::dim); m_max.resize(Point::dim); @@ -74,8 +41,17 @@ Point::Point(const vector<parameter_t>& init, } } +void Point::Randomize() +{ + assert(m_min.size()==Point::dim); + assert(m_max.size()==Point::dim); + for (unsigned int i=0; i<size(); i++) { + operator[](i) = m_min[i] + + (float)random()/(float)RAND_MAX * (float)(m_max[i]-m_min[i]); + } +} -double Point::operator*(const FeatureStats& F)const +double Point::operator*(const FeatureStats& F) const { ncall++; // to track performance double prod=0.0; @@ -91,43 +67,71 @@ double Point::operator*(const FeatureStats& F)const return prod; } -Point Point::operator+(const Point& p2)const +Point Point::operator+(const Point& p2) const { - assert(p2.size()==size()); + assert(p2.size() == size()); Point Res(*this); - for(unsigned i=0; i<size(); i++) - Res[i]+=p2[i]; - Res.score=numeric_limits<statscore_t>::max(); + for (unsigned i = 0; i < size(); i++) { + Res[i] += p2[i]; + } + + Res.score_ = numeric_limits<statscore_t>::max(); return Res; } void Point::operator+=(const Point& p2) { - assert(p2.size()==size()); - for(unsigned i=0; i<size(); i++) - operator[](i)+=p2[i]; - score=numeric_limits<statscore_t>::max(); + assert(p2.size() == size()); + for (unsigned i = 0; i < size(); i++) { + operator[](i) += p2[i]; + } + score_ = numeric_limits<statscore_t>::max(); } -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_t>::max(); + 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) +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++) + vector<parameter_t> w = P.GetAllWeights(); + for (unsigned int i = 0; i < Point::pdim; i++) { o << w[i] << " "; -// o << "=> " << P.GetScore(); + } return o; } +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) { + norm=sqrt(norm); + for (unsigned int i=0; i<size(); i++) + operator[](i)/=norm; + } +} + + +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; + } +} + + vector<parameter_t> Point::GetAllWeights()const { vector<parameter_t> w; @@ -142,6 +146,3 @@ vector<parameter_t> Point::GetAllWeights()const } return w; } - - - |