-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrfthread.h
More file actions
64 lines (60 loc) · 2.21 KB
/
crfthread.h
File metadata and controls
64 lines (60 loc) · 2.21 KB
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
//
// Created by ngs on 28/06/2018.
//
#ifndef CRF_CRFTHREAD_H
#define CRF_CRFTHREAD_H
#include <pthread.h>
#include "node.h"
#include "path.h"
#include "common.h"
#include <vector>
#include <map>
#include <string>
#include <thread>
class CRFThread{
public:
CRFThread(std::vector<Node> *ptr_stratnode, std::vector<Node> *ptr_stoonode,
std::vector<std::vector<std::vector<Node *>>> node_matrix, std::vector<double> *ptr_Z,
std::vector<double> *ptr_e);
CRFThread(std::vector<Node> *ptr_start_node, std::vector<Node> *ptr_stop_node,
std::vector<std::vector<std::vector<Node *>>> node_matrix);
~CRFThread();
void CRFThreadRun(int x_size, int y_size, int seq_no, std::vector<double> *ptr_w_vector);
void CRFThreadViterbi(int x_size, int y_size, int seq_no, std::vector<double> *ptr_w_vector);
void ForwardBackward(int x_size, int y_size, int seq_no);
void CalcCost(int x_size, int y_size, int seq_no,std::vector<double> *ptr_w_vector);
void CalcFeatureExpectation(int x_size, int y_size, int seq_no);
inline void CalcCost(Path *ptrpath, std::vector<double> *ptr_w_vector) {
double cost = DEFAULT_COST_VALUE;
int index = ptrpath->GetFeatureIndex();
if (FEATURE_NO_EXIST != index) {
//for the pair like (START, y)
double weight = (*ptr_w_vector)[index];
cost = weight;
} else{
// std::cout << "index error"<<std::endl;
}
ptrpath->SetCost(cost);
}
inline void CalcCost(Node *ptrnode, std::vector<double> *ptr_w_vector) {
double cost = DEFAULT_COST_VALUE;
int index = ptrnode->GetFeatureIndex();
if(FEATURE_NO_EXIST != index){
double weight = (*ptr_w_vector)[index];
// cost = exp(weight);
cost = weight;
} else{
// std::cout << "index error"<<std::endl;
}
ptrnode->SetCost(cost);
}
private:
std::vector<Node> *ptr_start_node_;
std::vector<Node> *ptr_stop_node_;
std::vector<std::vector<std::vector<Node *>>> node_matrix_;
//data related
std::vector<double> *ptr_Z_;
std::vector<double> *ptr_e_;
std::mutex mutex_lock_;
};
#endif //CRF_CRFTHREAD_H