--- LBFGS.hpp.ori 2013-10-14 21:08:23.000000000 +0900 +++ LBFGS.hpp 2013-11-18 21:33:34.000000000 +0900 @@ -19,11 +19,6 @@ class LBFGS { public: static const unsigned int DEFAULT_NUM_VECTORS = 7; - static const RealNumber LINE_SEARCH_ALPHA = 0.1; - static const RealNumber LINE_SEARCH_BETA = 0.5; - static const RealNumber MIN_GRAD_NORM = 0.0001; - static const RealNumber MIN_FUNC_DIFF = 0.000001; - static const unsigned int MAX_LINE_SEARCH_ITERATIONS = 100; protected: @@ -55,19 +50,23 @@ backtracking_line_search(const MathVec & grad0, const RealNumber f0, MathVec & dx, MathVec & grad1) { - RealNumber t = 1.0 / this->LINE_SEARCH_BETA; + const RealNumber LINE_SEARCH_ALPHA = 0.1; + const RealNumber LINE_SEARCH_BETA = 0.5; + const RealNumber MIN_FUNC_DIFF = 0.000001; + + RealNumber t = 1.0 / LINE_SEARCH_BETA; RealNumber old_t = 0.0; - RealNumber tolerance = this->LINE_SEARCH_ALPHA * dot_product(dx, grad0); + RealNumber tolerance = LINE_SEARCH_ALPHA * dot_product(dx, grad0); RealNumber f = 0.0; unsigned int i = 0; do { - if (++i > this->MAX_LINE_SEARCH_ITERATIONS) { + if (++i > MAX_LINE_SEARCH_ITERATIONS) { cerr << "Warning: line search not terminated" << endl; is_converged = true; break; } - t *= this->LINE_SEARCH_BETA; + t *= LINE_SEARCH_BETA; //if(t==0) cerr << " looping infinitely " << endl; //cerr << "line search: " << t << endl; //x = x0 + t * dx; @@ -82,7 +81,7 @@ dx *= t; // check convergence - if (fabs(1.0 - fabs(f / f0)) < this->MIN_FUNC_DIFF) { + if (fabs(1.0 - fabs(f / f0)) < MIN_FUNC_DIFF) { is_converged = true; } @@ -145,6 +144,8 @@ } virtual void iteration() { + const RealNumber MIN_GRAD_NORM = 0.0001; + if(is_beginning) { //cerr << "beginning" << endl; f = func_grad(x.STLVec(), grad.STLVec()); @@ -153,7 +154,7 @@ //cerr << "iteration " << iter << ": obj = " << f << endl; //cerr << "|grad|=" << sqrt(dot_product(grad, grad)) << endl; grad_norm = sqrt(dot_product(grad, grad)); - if (grad_norm < this->MIN_GRAD_NORM) { + if (grad_norm < MIN_GRAD_NORM) { is_converged = true; return; }