ZGen  0.2.0
a linearization system for natural language.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
learner.h
Go to the documentation of this file.
1 #ifndef __ZGEN_BESTFIRST_LEARNING_LEARNER_H__
2 #define __ZGEN_BESTFIRST_LEARNING_LEARNER_H__
3 
8 
9 namespace ZGen {
10 
11 namespace BestFirst {
12 
13 class Learner {
14 public:
16  enum { CONVERGED = 0,
20 
21  Learner(Model* model, int max_iteration= 1);
22 
28  void config_model(Model* model);
29 
35  void config_timestamp(int timestamp);
36 
54  int learn(const SpanSet& gold_spans,
55  SpanMaxHeap& agenda);
56 
57 private:
68  bool test_convergence(int nr_gold_spans, const SpanSet& gold_spans);
69 
78  void learn_one_iteration();
79 
85  void load_sortedlist_from_agenda(SpanMaxHeap& agenda);
86 
92  void load_agenda_from_sortedlist(SpanMaxHeap& agenda);
93 
99  void load_agenda_from_sortedlist(const SpanSet& gold_spans,
100  SpanMaxHeap& agenda);
101 
107  int count_number_of_gold_spans_in_sortedlist(const SpanSet& gold_spans);
108 
118  int collect_positive_spans(int nr_gold_spans,
119  const SpanSet& gold_spans);
120 
130  int collect_negative_spans(int nr_gold_spans,
131  const SpanSet& gold_spans);
132 
138  void increase_positive_spans(const std::vector<Span*>& positive_spans);
139 
144  void decrease_negative_spans(const std::vector<Span*>& negative_spans);
145 
151  void score_spans_in_sortedlist();
152 private:
154  Model* model;
155  int max_iteration;
156  int timestamp;
157  std::vector<Span *> positive_spans;
158  std::vector<Span *> negative_spans;
159  std::vector<Span *> sorted_span_list;
160 };
161 
162 } // end for namespace BestFirst
163 
164 } // end for namespace ZGen
165 
166 #endif // end for __ZGEN_BESTFIRST_LEARNING_PERCEPTRON__
void config_model(Model *model)
Definition: learner.h:13
boost::unordered_set< Span *, SpanPtrHash, SpanPtrEqual > SpanSet
Definition: span_types.h:12
Definition: learner.h:16
boost::heap::priority_queue< Span *, boost::heap::compare< SpanPtrLess > > SpanMaxHeap
Definition: span_types.h:14
int learn(const SpanSet &gold_spans, SpanMaxHeap &agenda)
Definition: learner.cc:26
void config_timestamp(int timestamp)
Definition: learner.cc:20
Definition: model.h:12
Learner(Model *model, int max_iteration=1)
Definition: learner.cc:11