ModErn Text Analysis
META Enumerates Textual Applications
trellis.h
Go to the documentation of this file.
1 
10 #ifndef META_SEQUENCE_TRELLIS_H_
11 #define META_SEQUENCE_TRELLIS_H_
12 
13 #include <vector>
14 #include <unordered_map>
15 
16 #include "meta.h"
17 #include "sequence/observation.h"
18 #include "util/dense_matrix.h"
19 
20 namespace meta
21 {
22 namespace sequence
23 {
24 
28 class trellis
29 {
30  protected:
33 
34  public:
42  trellis(uint64_t size, uint64_t labels);
43 
47  uint64_t size() const;
48 
56  void probability(uint64_t idx, const label_id& tag, double prob);
57 
65  double probability(uint64_t idx, const label_id& tag) const;
66 };
67 
73 class forward_trellis : public trellis
74 {
75  private:
77  std::vector<double> normalizers_;
78 
79  public:
87  forward_trellis(uint64_t size, uint64_t labels);
88 
93  double normalizer(uint64_t idx) const;
94 
100  void normalize(uint64_t idx);
101 };
102 
108 class viterbi_trellis : public trellis
109 {
110  private:
113 
114  public:
122  viterbi_trellis(uint64_t size, uint64_t labels);
123 
132  void previous_tag(uint64_t idx, const label_id& current,
133  const label_id& previous);
134 
140  const label_id& previous_tag(uint64_t idx, const label_id& current) const;
141 };
142 }
143 }
144 #endif
util::dense_matrix< double > trellis_
storage for the scores
Definition: trellis.h:32
Contains top-level namespace documentation for the META toolkit.
Special trellis for the normalized forward algorithm.
Definition: trellis.h:73
double normalizer(uint64_t idx) const
Definition: trellis.cpp:60
void previous_tag(uint64_t idx, const label_id &current, const label_id &previous)
Sets the back pointer for the given time step and label to the given label.
Definition: trellis.cpp:42
viterbi_trellis(uint64_t size, uint64_t labels)
Constructs a viterbi_trellis with the given number of time steps and labels.
Definition: trellis.cpp:36
std::vector< double > normalizers_
storage for the normalizers for each time step
Definition: trellis.h:77
Special trellis for the Viterbi algorithm.
Definition: trellis.h:108
forward_trellis(uint64_t size, uint64_t labels)
Constructs a forward_trellis with the given number of time steps and labels.
Definition: trellis.cpp:54
uint64_t size() const
Definition: trellis.cpp:21
trellis(uint64_t size, uint64_t labels)
Constructs a new trellis with the given number of time steps and labels.
Definition: trellis.cpp:15
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
void normalize(uint64_t idx)
Performs normalization on the given time step and stores the normalizer.
Definition: trellis.cpp:65
util::dense_matrix< label_id > paths_
storage for the back pointers
Definition: trellis.h:112
Basic trellis for holding score data for the forward/backward algorithm.
Definition: trellis.h:28
void probability(uint64_t idx, const label_id &tag, double prob)
Sets the value in the trellis for the given time step and label.
Definition: trellis.cpp:26