2012-02-20 04:46:08 +04:00
|
|
|
#ifndef MERT_POINT_H_
|
|
|
|
#define MERT_POINT_H_
|
2011-11-12 02:59:50 +04:00
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
#include <ostream>
|
2011-11-14 10:15:30 +04:00
|
|
|
#include <map>
|
2008-05-14 15:32:17 +04:00
|
|
|
#include <vector>
|
2008-05-15 23:09:01 +04:00
|
|
|
#include "Types.h"
|
2008-05-15 14:57:20 +04:00
|
|
|
|
2011-11-14 10:15:30 +04:00
|
|
|
class FeatureStats;
|
2008-05-15 14:57:20 +04:00
|
|
|
class Optimizer;
|
|
|
|
|
2011-11-12 03:58:23 +04:00
|
|
|
/**
|
|
|
|
* A class that handles the subset of the Feature weight on which
|
|
|
|
* we run the optimization.
|
|
|
|
*/
|
2011-11-12 04:51:27 +04:00
|
|
|
class Point : public vector<parameter_t>
|
2011-02-24 15:42:19 +03:00
|
|
|
{
|
2008-05-15 14:57:20 +04:00
|
|
|
friend class Optimizer;
|
2012-03-10 12:12:34 +04:00
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
private:
|
2011-11-12 03:58:23 +04:00
|
|
|
/**
|
|
|
|
* The indices over which we optimize.
|
|
|
|
*/
|
2012-03-10 12:12:34 +04:00
|
|
|
static vector<unsigned int> m_opt_indices;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
2012-03-10 12:12:34 +04:00
|
|
|
* Dimension of m_opt_indices and of the parent vector.
|
2011-11-12 03:58:23 +04:00
|
|
|
*/
|
2012-03-10 12:12:34 +04:00
|
|
|
static unsigned int m_dim;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fixed weights in case of partial optimzation.
|
|
|
|
*/
|
2012-03-10 12:12:34 +04:00
|
|
|
static map<unsigned int,parameter_t> m_fixed_weights;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Total size of the parameter space; we have
|
2012-03-10 12:12:34 +04:00
|
|
|
* m_pdim = FixedWeight.size() + optinidices.size().
|
2011-11-12 03:58:23 +04:00
|
|
|
*/
|
2012-03-10 12:12:34 +04:00
|
|
|
static unsigned int m_pdim;
|
|
|
|
static unsigned int m_ncall;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
2012-03-10 12:12:34 +04:00
|
|
|
* The limits for randomization, both vectors are of full length, m_pdim.
|
2011-11-12 03:58:23 +04:00
|
|
|
*/
|
2011-07-04 01:01:16 +04:00
|
|
|
static vector<parameter_t> m_min;
|
|
|
|
static vector<parameter_t> m_max;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
statscore_t m_score;
|
2011-11-12 11:39:57 +04:00
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
public:
|
2012-03-10 12:12:34 +04:00
|
|
|
static unsigned int getdim() { return m_dim; }
|
|
|
|
static void setdim(size_t d) { m_dim = d; }
|
|
|
|
|
|
|
|
static unsigned int getpdim() { return m_pdim; }
|
|
|
|
static void setpdim(size_t pd) { m_pdim = pd; }
|
2012-02-27 19:35:42 +04:00
|
|
|
|
|
|
|
static void set_optindices(const vector<unsigned int>& indices) {
|
2012-03-10 12:12:34 +04:00
|
|
|
m_opt_indices = indices;
|
2012-02-27 19:35:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const vector<unsigned int>& get_optindices() {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_opt_indices;
|
2012-02-27 19:35:42 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
static bool OptimizeAll() {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_fixed_weights.empty();
|
2011-11-12 04:40:01 +04:00
|
|
|
}
|
2011-11-12 04:51:27 +04:00
|
|
|
|
2011-11-12 11:50:18 +04:00
|
|
|
Point();
|
2011-07-04 01:01:16 +04:00
|
|
|
Point(const vector<parameter_t>& init,
|
2011-11-12 04:51:27 +04:00
|
|
|
const vector<parameter_t>& min,
|
|
|
|
const vector<parameter_t>& max);
|
2011-11-12 11:50:18 +04:00
|
|
|
~Point();
|
|
|
|
|
2011-07-04 01:01:16 +04:00
|
|
|
void Randomize();
|
2008-05-16 11:09:15 +04:00
|
|
|
|
2011-11-12 03:58:23 +04:00
|
|
|
// Compute the feature function
|
2011-11-12 11:39:57 +04:00
|
|
|
double operator*(const FeatureStats&) const;
|
|
|
|
Point operator+(const Point&) const;
|
2011-09-15 21:45:35 +04:00
|
|
|
void operator+=(const Point&);
|
2011-11-12 11:39:57 +04:00
|
|
|
Point operator*(float) const;
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
2012-03-10 12:12:34 +04:00
|
|
|
* Write the Whole featureweight to a stream (ie m_pdim float).
|
2011-11-12 03:58:23 +04:00
|
|
|
*/
|
2008-05-15 18:04:42 +04:00
|
|
|
friend ostream& operator<<(ostream& o,const Point& P);
|
2011-11-12 04:40:01 +04:00
|
|
|
|
|
|
|
void Normalize() { NormalizeL2(); }
|
2008-05-27 20:50:52 +04:00
|
|
|
void NormalizeL2();
|
|
|
|
void NormalizeL1();
|
2011-11-12 03:58:23 +04:00
|
|
|
|
|
|
|
/**
|
2012-03-10 12:12:34 +04:00
|
|
|
* Return a vector of size m_pdim where all weights have been
|
2011-11-12 03:58:23 +04:00
|
|
|
* put (including fixed ones).
|
|
|
|
*/
|
2011-11-12 11:39:57 +04:00
|
|
|
vector<parameter_t> GetAllWeights() const;
|
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
statscore_t GetScore() const { return m_score; }
|
|
|
|
void SetScore(statscore_t score) { m_score = score; }
|
2008-05-14 15:32:17 +04:00
|
|
|
};
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_POINT_H
|