LBFGS++
Param.h
1 // Copyright (C) 2016-2020 Yixuan Qiu <yixuan.qiu@cos.name>
2 // Under MIT license
3 
4 #ifndef PARAM_H
5 #define PARAM_H
6 
7 #include <Eigen/Core>
8 #include <stdexcept> // std::invalid_argument
9 
10 
11 namespace LBFGSpp {
12 
13 
19 
26 {
38 
44 
54 
64 };
65 
66 
70 template <typename Scalar = double>
72 {
73 public:
82  int m;
91  Scalar epsilon;
100  int past;
109  Scalar delta;
135  Scalar min_step;
141  Scalar max_step;
147  Scalar ftol;
155  Scalar wolfe;
156 
157 public:
163  {
164  m = 6;
165  epsilon = Scalar(1e-5);
166  past = 0;
167  delta = Scalar(0);
168  max_iterations = 0;
170  max_linesearch = 20;
171  min_step = Scalar(1e-20);
172  max_step = Scalar(1e+20);
173  ftol = Scalar(1e-4);
174  wolfe = Scalar(0.9);
175  }
176 
182  inline void check_param() const
183  {
184  if(m <= 0)
185  throw std::invalid_argument("'m' must be positive");
186  if(epsilon <= 0)
187  throw std::invalid_argument("'epsilon' must be positive");
188  if(past < 0)
189  throw std::invalid_argument("'past' must be non-negative");
190  if(delta < 0)
191  throw std::invalid_argument("'delta' must be non-negative");
192  if(max_iterations < 0)
193  throw std::invalid_argument("'max_iterations' must be non-negative");
196  throw std::invalid_argument("unsupported line search termination condition");
197  if(max_linesearch <= 0)
198  throw std::invalid_argument("'max_linesearch' must be positive");
199  if(min_step < 0)
200  throw std::invalid_argument("'min_step' must be positive");
201  if(max_step < min_step )
202  throw std::invalid_argument("'max_step' must be greater than 'min_step'");
203  if(ftol <= 0 || ftol >= 0.5)
204  throw std::invalid_argument("'ftol' must satisfy 0 < ftol < 0.5");
205  if(wolfe <= ftol || wolfe >= 1)
206  throw std::invalid_argument("'wolfe' must satisfy ftol < wolfe < 1");
207  }
208 };
209 
210 
214 template <typename Scalar = double>
216 {
217 public:
226  int m;
236  Scalar epsilon;
245  int past;
254  Scalar delta;
280  Scalar min_step;
286  Scalar max_step;
292  Scalar ftol;
300  Scalar wolfe;
301 
302 public:
308  {
309  m = 6;
310  epsilon = Scalar(1e-5);
311  past = 1;
312  delta = Scalar(1e-10);
313  max_iterations = 0;
314  max_submin = 20;
315  max_linesearch = 20;
316  min_step = Scalar(1e-20);
317  max_step = Scalar(1e+20);
318  ftol = Scalar(1e-4);
319  wolfe = Scalar(0.9);
320  }
321 
327  inline void check_param() const
328  {
329  if(m <= 0)
330  throw std::invalid_argument("'m' must be positive");
331  if(epsilon <= 0)
332  throw std::invalid_argument("'epsilon' must be positive");
333  if(past < 0)
334  throw std::invalid_argument("'past' must be non-negative");
335  if(delta < 0)
336  throw std::invalid_argument("'delta' must be non-negative");
337  if(max_iterations < 0)
338  throw std::invalid_argument("'max_iterations' must be non-negative");
339  if(max_submin < 0)
340  throw std::invalid_argument("'max_submin' must be non-negative");
341  if(max_linesearch <= 0)
342  throw std::invalid_argument("'max_linesearch' must be positive");
343  if(min_step < 0)
344  throw std::invalid_argument("'min_step' must be positive");
345  if(max_step < min_step )
346  throw std::invalid_argument("'max_step' must be greater than 'min_step'");
347  if(ftol <= 0 || ftol >= 0.5)
348  throw std::invalid_argument("'ftol' must satisfy 0 < ftol < 0.5");
349  if(wolfe <= ftol || wolfe >= 1)
350  throw std::invalid_argument("'wolfe' must satisfy ftol < wolfe < 1");
351  }
352 };
353 
354 
355 } // namespace LBFGSpp
356 
357 #endif // PARAM_H
LBFGSpp::LINE_SEARCH_TERMINATION_CONDITION
LINE_SEARCH_TERMINATION_CONDITION
Definition: Param.h:25
LBFGSpp::LBFGSBParam::min_step
Scalar min_step
Definition: Param.h:280
LBFGSpp::LBFGSBParam::ftol
Scalar ftol
Definition: Param.h:292
LBFGSpp::LBFGSBParam::wolfe
Scalar wolfe
Definition: Param.h:300
LBFGSpp::LBFGS_LINESEARCH_BACKTRACKING_WOLFE
@ LBFGS_LINESEARCH_BACKTRACKING_WOLFE
Definition: Param.h:53
LBFGSpp::LBFGSBParam::max_submin
int max_submin
Definition: Param.h:268
LBFGSpp::LBFGSParam
Definition: Param.h:71
LBFGSpp::LBFGSBParam
Definition: Param.h:215
LBFGSpp::LBFGSBParam::check_param
void check_param() const
Definition: Param.h:327
LBFGSpp::LBFGSParam::check_param
void check_param() const
Definition: Param.h:182
LBFGSpp::LBFGSParam::max_step
Scalar max_step
Definition: Param.h:141
LBFGSpp::LBFGSBParam::max_linesearch
int max_linesearch
Definition: Param.h:274
LBFGSpp::LBFGSParam::wolfe
Scalar wolfe
Definition: Param.h:155
LBFGSpp::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE
@ LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE
Definition: Param.h:63
LBFGSpp::LBFGSBParam::epsilon
Scalar epsilon
Definition: Param.h:236
LBFGSpp::LBFGS_LINESEARCH_BACKTRACKING_ARMIJO
@ LBFGS_LINESEARCH_BACKTRACKING_ARMIJO
Definition: Param.h:37
LBFGSpp::LBFGS_LINESEARCH_BACKTRACKING
@ LBFGS_LINESEARCH_BACKTRACKING
Definition: Param.h:43
LBFGSpp::LBFGSParam::max_iterations
int max_iterations
Definition: Param.h:117
LBFGSpp::LBFGSParam::ftol
Scalar ftol
Definition: Param.h:147
LBFGSpp::LBFGSBParam::past
int past
Definition: Param.h:245
LBFGSpp::LBFGSBParam::m
int m
Definition: Param.h:226
LBFGSpp::LBFGSParam::m
int m
Definition: Param.h:82
LBFGSpp::LBFGSParam::max_linesearch
int max_linesearch
Definition: Param.h:129
LBFGSpp::LBFGSBParam::delta
Scalar delta
Definition: Param.h:254
LBFGSpp::LBFGSParam::epsilon
Scalar epsilon
Definition: Param.h:91
LBFGSpp::LBFGSBParam::LBFGSBParam
LBFGSBParam()
Definition: Param.h:307
LBFGSpp::LBFGSParam::LBFGSParam
LBFGSParam()
Definition: Param.h:162
LBFGSpp::LBFGSParam::delta
Scalar delta
Definition: Param.h:109
LBFGSpp::LBFGSParam::linesearch
int linesearch
Definition: Param.h:123
LBFGSpp::LBFGSBParam::max_step
Scalar max_step
Definition: Param.h:286
LBFGSpp::LBFGSParam::min_step
Scalar min_step
Definition: Param.h:135
LBFGSpp::LBFGSParam::past
int past
Definition: Param.h:100
LBFGSpp::LBFGSBParam::max_iterations
int max_iterations
Definition: Param.h:262