diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-10 12:12:34 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-10 12:12:34 +0400 |
commit | e7a2483b2296be98441a8df286612fe3f37ef613 (patch) | |
tree | 60dd9e1fc444391437237df6a68b2806d1156446 /mert/Point.cpp | |
parent | ed6e6f00b1b73a99d9177b984835af063ccf690f (diff) |
mert: Prefix private members with "m_" except TER.
Squashed commit of the following:
- Clean up PRO.
- Clean up ScoreStats.
- Clean up ScoreData.
- Clean up ScoreArray.
- Remove unnecessary headers.
- Clean up ScopedVector.
- Clean up Point.
- Clean up PerScorer.
- Clean up Optimizer.
- Clean up MergeScorer.
- Clean up InterpolatedScorer.
- Clean up FileStream.
- Clean up FeatureStats.
- Remove inefficient string concatenation.
- Clean up FeatureData.
- Clean up FeatureArray.
- Clean up Data.
Diffstat (limited to 'mert/Point.cpp')
-rw-r--r-- | mert/Point.cpp | 107 |
1 files changed, 55 insertions, 52 deletions
diff --git a/mert/Point.cpp b/mert/Point.cpp index fe371ef53..ae5dbc21b 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -8,41 +8,41 @@ using namespace std; -vector<unsigned> Point::optindices; +vector<unsigned> Point::m_opt_indices; -unsigned Point::dim = 0; +unsigned Point::m_dim = 0; -map<unsigned,statscore_t> Point::fixedweights; +map<unsigned,statscore_t> Point::m_fixed_weights; -unsigned Point::pdim = 0; -unsigned Point::ncall = 0; +unsigned Point::m_pdim = 0; +unsigned Point::m_ncall = 0; vector<parameter_t> Point::m_min; vector<parameter_t> Point::m_max; -Point::Point() : vector<parameter_t>(dim), score_(0.0) {} +Point::Point() : vector<parameter_t>(m_dim), m_score(0.0) {} -//Can initialize from a vector of dim or pdim +//Can initialize from a vector of dim or m_pdim Point::Point(const vector<parameter_t>& init, const vector<parameter_t>& min, const vector<parameter_t>& max) - : vector<parameter_t>(Point::dim), score_(0.0) + : vector<parameter_t>(Point::m_dim), m_score(0.0) { - m_min.resize(Point::dim); - m_max.resize(Point::dim); - if(init.size()==dim) { - for (unsigned int i=0; i<Point::dim; i++) { - operator[](i)=init[i]; + m_min.resize(Point::m_dim); + m_max.resize(Point::m_dim); + if (init.size() == m_dim) { + for (unsigned int i = 0; i < Point::m_dim; i++) { + operator[](i) = init[i]; m_min[i] = min[i]; m_max[i] = max[i]; } } else { - CHECK(init.size()==pdim); - CHECK(optindices.size() == Point::dim); - for (unsigned int i=0; i<Point::dim; i++) { - operator[](i)=init[optindices[i]]; - m_min[i] = min[optindices[i]]; - m_max[i] = max[optindices[i]]; + CHECK(init.size() == m_pdim); + CHECK(m_opt_indices.size() == Point::m_dim); + for (unsigned int i = 0; i < Point::m_dim; i++) { + operator[](i) = init[m_opt_indices[i]]; + m_min[i] = min[m_opt_indices[i]]; + m_max[i] = max[m_opt_indices[i]]; } } } @@ -51,9 +51,9 @@ Point::~Point() {} void Point::Randomize() { - CHECK(m_min.size()==Point::dim); - CHECK(m_max.size()==Point::dim); - for (unsigned int i=0; i<size(); i++) { + CHECK(m_min.size() == Point::m_dim); + CHECK(m_max.size() == Point::m_dim); + for (unsigned int i = 0; i < size(); i++) { operator[](i) = m_min[i] + static_cast<float>(random()) / static_cast<float>(RAND_MAX) * (m_max[i] - m_min[i]); } @@ -61,16 +61,17 @@ void Point::Randomize() double Point::operator*(const FeatureStats& F) const { - ncall++; // to track performance - double prod=0.0; - if(OptimizeAll()) + m_ncall++; // to track performance + double prod = 0.0; + if (OptimizeAll()) for (unsigned i=0; i<size(); i++) - prod+= operator[](i)*F.get(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); + for (unsigned i = 0; i < size(); i++) + prod += operator[](i) * F.get(m_opt_indices[i]); + for(map<unsigned, float>::iterator it = m_fixed_weights.begin(); + it != m_fixed_weights.end(); ++it) + prod += it->second * F.get(it->first); } return prod; } @@ -83,7 +84,7 @@ Point Point::operator+(const Point& p2) const Res[i] += p2[i]; } - Res.score_ = numeric_limits<statscore_t>::max(); + Res.m_score = numeric_limits<statscore_t>::max(); return Res; } @@ -93,7 +94,7 @@ void Point::operator+=(const Point& p2) for (unsigned i = 0; i < size(); i++) { operator[](i) += p2[i]; } - score_ = numeric_limits<statscore_t>::max(); + m_score = numeric_limits<statscore_t>::max(); } Point Point::operator*(float l) const @@ -102,14 +103,14 @@ Point Point::operator*(float l) const for (unsigned i = 0; i < size(); i++) { Res[i] *= l; } - Res.score_ = numeric_limits<statscore_t>::max(); + Res.m_score = numeric_limits<statscore_t>::max(); return Res; } ostream& operator<<(ostream& o, const Point& P) { vector<parameter_t> w = P.GetAllWeights(); - for (unsigned int i = 0; i < Point::pdim; i++) { + for (unsigned int i = 0; i < Point::m_pdim; i++) { o << w[i] << " "; } return o; @@ -118,24 +119,24 @@ ostream& operator<<(ostream& o, const Point& P) 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; + 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; + 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; } } @@ -143,14 +144,16 @@ void Point::NormalizeL1() vector<parameter_t> Point::GetAllWeights()const { vector<parameter_t> w; - if(OptimizeAll()) { - w=*this; + if (OptimizeAll()) { + w = *this; } 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.resize(m_pdim); + for (unsigned int i = 0; i < size(); i++) + w[m_opt_indices[i]] = operator[](i); + for (map<unsigned, float>::iterator it = m_fixed_weights.begin(); + it != m_fixed_weights.end(); ++it) { w[it->first]=it->second; + } } return w; } |