forked from taku910/crfpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.cpp
27 lines (24 loc) · 631 Bytes
/
path.cpp
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
//
// CRF++ -- Yet Another CRF toolkit
//
// $Id: path.cpp 1587 2007-02-12 09:00:36Z taku $;
//
// Copyright(C) 2005-2007 Taku Kudo <[email protected]>
//
#include <cmath>
#include "path.h"
#include "common.h"
namespace CRFPP {
void Path::calcExpectation(double *expected, double Z, size_t size) const {
const double c = std::exp(lnode->alpha + cost + rnode->beta - Z);
for (const int *f = fvector; *f != -1; ++f) {
expected[*f + lnode->y * size + rnode->y] += c;
}
}
void Path::add(Node *_lnode, Node *_rnode) {
lnode = _lnode;
rnode = _rnode;
lnode->rpath.push_back(this);
rnode->lpath.push_back(this);
}
}