54 v3p_netlib_lbfgs_global_t lbfgs_global;
55 v3p_netlib_lbfgs_init(&lbfgs_global);
57 long iprint[2] = {1, 0};
66 std::cerr <<
"vnl_lbfgs: n = "<< n <<
", memory = "<<
m <<
", Workspace = " 67 << w.
size() <<
"[ "<< ( w.
size() / 128.0 / 1024.0) <<
" MB], ErrorScale = " 73 std::cerr <<
"vnl_lbfgs: ";
84 v3p_netlib_logical diagco =
false;
88 double local_xtol = 1e-16;
99 }
else if (f < best_f) {
104 #define print_(i,a,b,c,d) std::cerr<<std::setw(6)<<(i)<<' '<<std::setw(20)<<(a)<<' '\ 105 <<std::setw(20)<<(b)<<' '<<std::setw(20)<<(c)<<' '<<std::setw(20)<<(d)<<'\n' 109 std::cerr <<
"vnl_lbfgs: f = " <<
f_->
reported_error(f) <<
", computing FD gradient\n";
116 if (l > limit + limit_tail) {
117 std::cerr <<
" [ Showing only first " <<limit<<
" components ]\n";
120 print_(
"i",
"x",
"g",
"fdg",
"dg");
121 print_(
"-",
"-",
"-",
"---",
"--");
122 for (
int i = 0; i < l; ++i)
123 print_(i, x[i], g[i], fdg[i], g[i]-fdg[i]);
125 std::cerr <<
" ...\n";
126 for (
int i = n - limit_tail; i < n; ++i)
127 print_(i, x[i], g[i], fdg[i], g[i]-fdg[i]);
130 std::cerr <<
" ERROR = " << (fdg - g).
squared_magnitude() / std::sqrt(
double(n)) <<
"\n";
133 iprint[0] =
trace ? 1 : -1;
137 iprint, &eps, &local_xtol, w.
data_block(), &iflag, &lbfgs_global);
161 std::cerr <<
"vnl_lbfgs: Error. Netlib routine lbfgs failed.\n";
175 if (we_trace) std::cerr <<
"done\n";
An object that represents a function from R^n -> R.
Limited memory Broyden Fletcher Goldfarb Shannon minimization.
int get_number_of_unknowns() const
Return the number of unknowns.
double default_step_length
Default step length in line search.
vnl_lbfgs()
Default constructor.
size_t size() const
Return the length, number of elements, dimension of this vector.
void init_parameters()
Called by constructors.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
abs_t magnitude() const
Return magnitude (length) of vector.
int memory
Step accuracy/speed tradeoff.
vnl_bignum squared_magnitude(vnl_bignum const &x)
void fdgradf(vnl_vector< double > const &x, vnl_vector< double > &gradient, double stepsize=1e-5)
Compute finite-difference gradient.
void report_eval(double f)
Called by derived classes after each function evaluation.
double line_search_accuracy
Accuracy of line search.
virtual bool report_iter()
Called by derived classes after each iteration.
double gtol
Termination tolerance on Grad(F)' * F = 0.
Declare in a central place the list of symbols from netlib.
#define print_(i, a, b, c, d)
virtual void compute(vnl_vector< double > const &x, double *f, vnl_vector< double > *g)
Compute one or both of f and g.
int get_max_function_evals() const
virtual double reported_error(double f_value)
Called when error is printed for user.
ReturnCodes failure_code_
bool minimize(vnl_vector< double > &x)