-
Notifications
You must be signed in to change notification settings - Fork 36
/
viterbi_decoder.h
69 lines (57 loc) · 1.47 KB
/
viterbi_decoder.h
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
/*
* viterbi_decoder.h
*
* Created on: Feb 2, 2014
* Author: bishan
*/
#ifndef VITERBI_DECODER_H_
#define VITERBI_DECODER_H_
#include <iostream>
#include <vector>
#include <queue>
#include "node.h"
#include "scoped_ptr.h"
#include "freelist.h"
using namespace std;
namespace CRFPP {
struct QueueElement {
Node *node;
QueueElement *next;
double fx;
double gx;
};
class QueueElementComp {
public:
const bool operator()(QueueElement *q1,
QueueElement *q2)
{ return(q1->fx > q2->fx); }
};
class ViterbiDecoder {
public:
ViterbiDecoder() : nbest_(0), inference_type(0), cost_(0),
xsize_(0), ysize_(0) {}
~ViterbiDecoder() {
}
private:
scoped_ptr<std::priority_queue <QueueElement*, std::vector <QueueElement *>,
QueueElementComp> > agenda_;
scoped_ptr<FreeList <QueueElement> > nbest_freelist_;
int xsize_;
int ysize_;
int inference_type ;
void viterbiwithConstraints(vector<vector<Node*> > &node_,
vector<unsigned short int> &result_);
void viterbi(vector<vector<Node*> > &node_,
vector<unsigned short int> &result_);
bool initNbest(vector<vector<Node*> > &node_);
public:
unsigned int nbest_ : 11;
double cost_;
bool next(vector<unsigned short int> &result_);
void inference(int xsize, int ysize, vector<vector<Node*> > &chain,
vector<unsigned short int> &result_);
size_t nbest() const { return nbest_; }
void set_nbest(size_t nbest) { nbest_ = nbest; }
};
} /* namespace CRFPP */
#endif /* VITERBI_DECODER_H_ */