📄 lbfgs.h
字号:
/* CRF++ -- Yet Another CRF toolkit $Id: lbfgs.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 MECAB_LBFGS_H#define MECAB_LBFGS_H#include <vector>#include "common.h"extern "C" { extern void lbfgs(int* n, int* m, double* x, double* f, double* g, int* diagco, double* diag, int* iprint, double* eps, double* xtol, double* w, int* iflag);}namespace CRFPP { class LBFGS { private: int n_; int m_; int iflag_; whatlog what_; std::vector <double> diag_; std::vector <double> w_; public: explicit LBFGS(): n_(0), m_(5), iflag_(0) {}; virtual ~LBFGS() {}; const char *what() { return what_.str(); } int init(int _n, int _m) { n_ = _n; m_ = _m; w_.resize(n_ *(2 * m_ + 1) + 2 * m_); diag_.resize(n_); return 0; } int optimize(double *x, double *f, double *g) { int iprint[] = {-1, 0}; double eta = 1e-7; double xtol = 1e-7; int diagco = 0; lbfgs(&n_, &m_, x, f, g, &diagco, &diag_[0], iprint, &eta, &xtol, &w_[0], &iflag_); if (iflag_ < 0) { CHECK_FALSE(false) << "routine stops with unexpected error"; return -1; } if (iflag_ == 0) return 0; // terminate return 1; // evaluate next f and g } };}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -