LBFGS++
Loading...
Searching...
No Matches
Param.h
1// Copyright (C) 2016-2023 Yixuan Qiu <yixuan.qiu@cos.name>
2// Under MIT license
3
4#ifndef LBFGSPP_PARAM_H
5#define LBFGSPP_PARAM_H
6
7#include <Eigen/Core>
8#include <stdexcept> // std::invalid_argument
9
10namespace LBFGSpp {
11
17
24{
36
42
52
62};
63
67template <typename Scalar = double>
69{
70public:
79 int m;
88 Scalar epsilon;
106 int past;
115 Scalar delta;
141 Scalar min_step;
147 Scalar max_step;
153 Scalar ftol;
161 Scalar wolfe;
162
163public:
169 {
170 // clang-format off
171 m = 6;
172 epsilon = Scalar(1e-5);
173 epsilon_rel = Scalar(1e-5);
174 past = 0;
175 delta = Scalar(0);
176 max_iterations = 0;
178 max_linesearch = 20;
179 min_step = Scalar(1e-20);
180 max_step = Scalar(1e+20);
181 ftol = Scalar(1e-4);
182 wolfe = Scalar(0.9);
183 // clang-format on
184 }
185
191 inline void check_param() const
192 {
193 if (m <= 0)
194 throw std::invalid_argument("'m' must be positive");
195 if (epsilon < 0)
196 throw std::invalid_argument("'epsilon' must be non-negative");
197 if (epsilon_rel < 0)
198 throw std::invalid_argument("'epsilon_rel' must be non-negative");
199 if (past < 0)
200 throw std::invalid_argument("'past' must be non-negative");
201 if (delta < 0)
202 throw std::invalid_argument("'delta' must be non-negative");
203 if (max_iterations < 0)
204 throw std::invalid_argument("'max_iterations' must be non-negative");
207 throw std::invalid_argument("unsupported line search termination condition");
208 if (max_linesearch <= 0)
209 throw std::invalid_argument("'max_linesearch' must be positive");
210 if (min_step < 0)
211 throw std::invalid_argument("'min_step' must be positive");
212 if (max_step < min_step)
213 throw std::invalid_argument("'max_step' must be greater than 'min_step'");
214 if (ftol <= 0 || ftol >= 0.5)
215 throw std::invalid_argument("'ftol' must satisfy 0 < ftol < 0.5");
216 if (wolfe <= ftol || wolfe >= 1)
217 throw std::invalid_argument("'wolfe' must satisfy ftol < wolfe < 1");
218 }
219};
220
224template <typename Scalar = double>
226{
227public:
236 int m;
246 Scalar epsilon;
265 int past;
274 Scalar delta;
300 Scalar min_step;
306 Scalar max_step;
312 Scalar ftol;
320 Scalar wolfe;
321
322public:
328 {
329 // clang-format off
330 m = 6;
331 epsilon = Scalar(1e-5);
332 epsilon_rel = Scalar(1e-5);
333 past = 1;
334 delta = Scalar(1e-10);
335 max_iterations = 0;
336 max_submin = 10;
337 max_linesearch = 20;
338 min_step = Scalar(1e-20);
339 max_step = Scalar(1e+20);
340 ftol = Scalar(1e-4);
341 wolfe = Scalar(0.9);
342 // clang-format on
343 }
344
350 inline void check_param() const
351 {
352 if (m <= 0)
353 throw std::invalid_argument("'m' must be positive");
354 if (epsilon < 0)
355 throw std::invalid_argument("'epsilon' must be non-negative");
356 if (epsilon_rel < 0)
357 throw std::invalid_argument("'epsilon_rel' must be non-negative");
358 if (past < 0)
359 throw std::invalid_argument("'past' must be non-negative");
360 if (delta < 0)
361 throw std::invalid_argument("'delta' must be non-negative");
362 if (max_iterations < 0)
363 throw std::invalid_argument("'max_iterations' must be non-negative");
364 if (max_submin < 0)
365 throw std::invalid_argument("'max_submin' must be non-negative");
366 if (max_linesearch <= 0)
367 throw std::invalid_argument("'max_linesearch' must be positive");
368 if (min_step < 0)
369 throw std::invalid_argument("'min_step' must be positive");
370 if (max_step < min_step)
371 throw std::invalid_argument("'max_step' must be greater than 'min_step'");
372 if (ftol <= 0 || ftol >= 0.5)
373 throw std::invalid_argument("'ftol' must satisfy 0 < ftol < 0.5");
374 if (wolfe <= ftol || wolfe >= 1)
375 throw std::invalid_argument("'wolfe' must satisfy ftol < wolfe < 1");
376 }
377};
378
379} // namespace LBFGSpp
380
381#endif // LBFGSPP_PARAM_H
Scalar epsilon_rel
Definition: Param.h:256
void check_param() const
Definition: Param.h:350
void check_param() const
Definition: Param.h:191
Scalar epsilon
Definition: Param.h:88
Scalar max_step
Definition: Param.h:147
Scalar min_step
Definition: Param.h:141
Scalar epsilon_rel
Definition: Param.h:97
LINE_SEARCH_TERMINATION_CONDITION
Definition: Param.h:24
@ LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE
Definition: Param.h:61
@ LBFGS_LINESEARCH_BACKTRACKING_ARMIJO
Definition: Param.h:35
@ LBFGS_LINESEARCH_BACKTRACKING
Definition: Param.h:41
@ LBFGS_LINESEARCH_BACKTRACKING_WOLFE
Definition: Param.h:51