ZGen  0.2.0
a linearization system for natural language.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
param.h
Go to the documentation of this file.
1 #ifndef __ZGEN_ML_PERCEPTRON_PARAM_H__
2 #define __ZGEN_ML_PERCEPTRON_PARAM_H__
3 
4 #include "settings.h"
5 
6 namespace ZGen {
7 
8 namespace MachineLearning {
9 
10 namespace Perceptron {
11 
14 struct Parameter {
15  Parameter() : w(0), w_sum(0), w_time(0) {}
16 
18  : w(_w), w_sum(_w_sum), w_time(_w_time) {}
19 
22  int w_time;
23 
25 
26  template<class Archive>
27  void serialize(Archive & ar, const unsigned int version) {
28  ar & w & w_sum;
29  }
30 
31  floatval_t dot(bool avg) {
32  if (avg) {
33  return w_sum;
34  } else {
35  return w;
36  }
37  }
38 
39  void add(int now, floatval_t scale) {
40  int elapsed = now - w_time;
41  floatval_t upd = scale;
42  floatval_t cur_val = w;
43  w = cur_val + upd;
44  w_sum += elapsed * cur_val + upd;
45  w_time = now;
46  }
47 
48  void flush(int now) {
49  w_sum += (now - w_time) * w;
50  w_time = now;
51  }
52 };
53 
54 } // end for namespace Perceptron
55 
56 } // end for namespace Machinelearning
57 
58 } // end for namespace ZGen
59 
60 #endif // end for __ZGEN_ML_PERCEPTRON_PARAM_H__
Parameter(floatval_t _w, floatval_t _w_sum, floatval_t _w_time)
Definition: param.h:17
floatval_t dot(bool avg)
Definition: param.h:31
void add(int now, floatval_t scale)
Definition: param.h:39
void serialize(Archive &ar, const unsigned int version)
Definition: param.h:27
double floatval_t
Definition: settings.h:24
floatval_t w_sum
Definition: param.h:21
floatval_t w
Definition: param.h:20
void flush(int now)
Definition: param.h:48
friend class boost::serialization::access
Definition: param.h:24