55 SEARCH_EACH_ITERATION,
57 ONE_STEP_PER_ITERATION
95 template<
class M,
class F,
class VALUES>
96 static IterationResult Iterate(
98 const M& Rd,
const F& f,
const VALUES& x0,
const double f_error,
const bool verbose=
false);
138template<
class M,
class F,
class VALUES>
141 const M& Rd,
const F& f,
const VALUES& x0,
const double f_error,
const bool verbose)
151 enum { NONE, INCREASED_DELTA, DECREASED_DELTA } lastAction = NONE;
153 gttic(Dog_leg_point);
156 gttoc(Dog_leg_point);
158 if(verbose) std::cout <<
"delta = " << delta <<
", dx_d_norm = " << result.dx_d.
norm() << std::endl;
162 const VALUES x_d(x0.retract(result.dx_d));
165 gttic(decrease_in_f);
167 result.f_error = f.error(x_d);
168 gttoc(decrease_in_f);
172 const double new_M_error = Rd.error(result.dx_d);
175 if(verbose) std::cout << std::setprecision(15) <<
"f error: " << f_error <<
" -> " << result.f_error << std::endl;
176 if(verbose) std::cout << std::setprecision(15) <<
"M error: " << M_error <<
" -> " << new_M_error << std::endl;
181 const double rho = std::abs(f_error - result.f_error) < 1e-15 || std::abs(M_error - new_M_error) < 1e-15 ?
183 (f_error - result.f_error) / (M_error - new_M_error);
185 if(verbose) std::cout << std::setprecision(15) <<
"rho = " << rho << std::endl;
189 const double dx_d_norm = result.dx_d.
norm();
190 const double newDelta = std::max(delta, 3.0 * dx_d_norm);
192 if(mode == ONE_STEP_PER_ITERATION || mode == SEARCH_REDUCE_ONLY)
194 else if(mode == SEARCH_EACH_ITERATION) {
195 if(std::abs(newDelta - delta) < 1e-15 || lastAction == DECREASED_DELTA)
199 lastAction = INCREASED_DELTA;
206 }
else if(0.75 > rho && rho >= 0.25) {
210 }
else if(0.25 > rho && rho >= 0.0) {
213 bool hitMinimumDelta;
215 newDelta = 0.5 * delta;
216 hitMinimumDelta =
false;
219 hitMinimumDelta =
true;
221 if(mode == ONE_STEP_PER_ITERATION || lastAction == INCREASED_DELTA || hitMinimumDelta)
223 else if(mode == SEARCH_EACH_ITERATION || mode == SEARCH_REDUCE_ONLY) {
225 lastAction = DECREASED_DELTA;
239 lastAction = DECREASED_DELTA;
241 if(verbose) std::cout <<
"Warning: Dog leg stopping because cannot decrease error with minimum delta" << std::endl;
243 result.f_error = f_error;
251 result.delta = delta;
294 template <
class M,
class F,
class VALUES>
298 const M& Rd,
const F& f,
303template <
class M,
class F,
class VALUES>
306 const M& Rd,
const F& f,
const VALUES& x0) {
308 std::cout <<
"DoglegLineSearch | minDelta: " << params.
minDelta
310 <<
" stepSize: " << params.
stepSize << std::endl;
311 const double fInitError = f.error(x0);
312 const double gnStep = dx_n.
norm();
313 const size_t numVars = dx_n.
size();
315 double maxStep, step;
317 maxStep = std::min(params.
maxDelta * numVars, gnStep);
318 step = std::min(params.
minDelta * numVars, gnStep);
319 step = std::min(step, maxStep);
322 std::cout <<
"Search Region: [ " << step <<
" -> " << maxStep <<
"]"
328 result.f_error = f.error(x0.retract(result.dx_d));
331 std::cout <<
"Initial Step Error: " << result.f_error << std::endl;
334 if (step < 1e-12 || params.
stepSize < 1.0)
335 throw std::runtime_error(
336 "Invalid DoglegLineSearch configuration. Would cause infinite search.");
339 double eps = std::numeric_limits<double>::epsilon();
340 while (step < maxStep - eps) {
343 step = std::min(maxStep, step * params.
stepSize);
347 step, dx_u, dx_n, params.
verbose);
348 VALUES x_d(x0.retract(dx_d));
349 double fNewError = f.error(x_d);
352 std::cout <<
"Step: " << step <<
" | Error: " << fNewError << std::endl;
355 bool updateDecreasedError = fNewError < result.f_error;
356 bool updateHasSufficientDecrease =
360 std::cout <<
"Decrease Error: " << updateDecreasedError
361 <<
" | Suff. Dec.: " << updateHasSufficientDecrease
364 if (updateDecreasedError && updateHasSufficientDecrease) {
365 result.f_error = fNewError;
369 if (params.
verbose) std::cout <<
"Step Accepted" << std::endl;
Global functions in a separate testing namespace.
Definition chartTesting.h:28
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
double norm() const
Vector L2 norm.
Definition VectorValues.cpp:286
static VectorValues Zero(const VectorValues &other)
Create a VectorValues with the same structure as other, but filled with zeros.
Definition VectorValues.cpp:77
size_t size() const
Number of variables stored.
Definition VectorValues.h:129
void setZero()
Set all values to zero vectors.
Definition VectorValues.cpp:143
This class contains the implementation of the Dogleg algorithm.
Definition DoglegOptimizerImpl.h:33
TrustRegionAdaptationMode
Specifies how the trust region is adapted at each Dogleg iteration.
Definition DoglegOptimizerImpl.h:54
static IterationResult Iterate(double delta, TrustRegionAdaptationMode mode, const VectorValues &dx_u, const VectorValues &dx_n, const M &Rd, const F &f, const VALUES &x0, const double f_error, const bool verbose=false)
Compute the update point for one iteration of the Dogleg algorithm, given an initial trust region rad...
Definition DoglegOptimizerImpl.h:139
static VectorValues ComputeDoglegPoint(double delta, const VectorValues &dx_u, const VectorValues &dx_n, const bool verbose=false)
Compute the dogleg point given a trust region radius .
Definition DoglegOptimizerImpl.cpp:26
Definition DoglegOptimizerImpl.h:35
This class contains an extension of the Dogleg Algorithm where a line search is performed across the ...
Definition DoglegOptimizerImpl.h:260
static DoglegOptimizerImpl::IterationResult Iterate(const Params ¶ms, const VectorValues &dx_u, const VectorValues &dx_n, const M &Rd, const F &f, const VALUES &x0)
Compute the update point for one iteration of the Dogleg Line Search algorithm, starting with a trust...
Definition DoglegOptimizerImpl.h:304
Definition DoglegOptimizerImpl.h:261
bool verbose
Whether to print debug information.
Definition DoglegOptimizerImpl.h:266
double minDelta
Minimum allowed small delta.
Definition DoglegOptimizerImpl.h:262
double stepSize
Increase of trust region for outward steps.
Definition DoglegOptimizerImpl.h:264
double maxDelta
Maximum allowed delta.
Definition DoglegOptimizerImpl.h:263
double sufficientDecreaseCoeff
Coefficient for suff. decrease check.
Definition DoglegOptimizerImpl.h:265