Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Point.h « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55d173215b1a38673bd71442655515e38c73b67a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef POINT_H
#define POINT_H

#include <fstream>
#include <map>
#include <vector>
#include "Types.h"

class FeatureStats;
class Optimizer;

/**
 * A class that handles the subset of the Feature weight on which
 * we run the optimization.
 */
class Point : public vector<parameter_t>
{
  friend class Optimizer;
private:
  /**
   * The indices over which we optimize.
   */
  static vector<unsigned int> optindices;

  /**
   * Dimension of optindices and of the parent vector.
   */
  static unsigned int dim;

  /**
   * Fixed weights in case of partial optimzation.
   */
  static map<unsigned int,parameter_t> fixedweights;

  /**
   * Total size of the parameter space; we have
   * pdim = FixedWeight.size() + optinidices.size().
   */
  static unsigned int pdim;
  static unsigned int ncall;

  /**
   * The limits for randomization, both vectors are of full length, pdim.
   */
  static vector<parameter_t> m_min;
  static vector<parameter_t> m_max;

  statscore_t score_;

public:
  static unsigned int getdim() {
    return dim;
  }
  static unsigned int getpdim() {
    return pdim;
  }
  static void setpdim(size_t pd) {
    pdim = pd;
  }
  static void setdim(size_t d) {
    dim = d;
  }
  static bool OptimizeAll() {
    return fixedweights.empty();
  }

  Point();
  Point(const vector<parameter_t>& init,
        const vector<parameter_t>& min,
        const vector<parameter_t>& max);
  ~Point();

  void Randomize();

  // Compute the feature function
  double operator*(const FeatureStats&) const;
  Point operator+(const Point&) const;
  void operator+=(const Point&);
  Point operator*(float) const;

  /**
   * Write the Whole featureweight to a stream (ie pdim float).
   */
  friend ostream& operator<<(ostream& o,const Point& P);

  void Normalize() { NormalizeL2(); }
  void NormalizeL2();
  void NormalizeL1();

  /**
   * Return a vector of size pdim where all weights have been
   * put (including fixed ones).
   */
  vector<parameter_t> GetAllWeights() const;

  statscore_t GetScore() const {
    return score_;
  }

  void SetScore(statscore_t score) { score_ = score; }
};

#endif  // POINT_H