📄 node.h
字号:
/* CRF++ -- Yet Another CRF toolkit $Id: node.h 1528 2006-08-07 02:39:50Z taku $; Copyright(C) 2005 Taku Kudo <taku@chasen.org> This is free software with ABSOLUTELY NO WARRANTY. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or(at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#ifndef _CRFPP_NODE_H#define _CRFPP_NODE_H#include <vector>#include <cmath>#include "path.h"#include "common.h"#define LOG2 0.69314718055#define MINUS_LOG_EPSILON 50namespace CRFPP{ // return log(exp(x) + exp(y)); /* this can be used recursivly e.g., log( exp(log(exp(x) + exp(y))) + exp(z)) = log(exp (x) + exp(y) + exp(z)) */ inline double logsumexp(double x, double y, bool flg) { if (flg) return y; // init mode double vmin = _min(x, y); double vmax = _max(x, y); if (vmax > vmin + MINUS_LOG_EPSILON) { return vmax; } else { return vmax + std::log(std::exp(vmin - vmax) + 1.0); } } struct Path; struct Node { unsigned int x; unsigned short int y; double alpha; double beta; double cost; double bestCost; Node *prev; int *fvector; std::vector<Path *> lpath; // $B$3$N(B node $B$K:8$+$i$D$J$,$k(B path std::vector<Path *> rpath; // $B$3$N(B node $B$K1&$+$i$D$J$,$k(B path void calcAlpha(); void calcBeta(); void calcExpectation(double *expected, double, size_t); void clear() { x = y = 0; alpha = beta = cost = 0.0; prev = 0; fvector = 0; lpath.clear(); rpath.clear(); } void shirnk() { std::vector<Path *>(lpath).swap(lpath); std::vector<Path *>(rpath).swap(rpath); } Node(): x(0), y(0), alpha(0.0), beta(0.0), cost(0.0), bestCost(0.0), prev(0), fvector(0) {}; };}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -