18 #ifndef itkLBFGS2Optimizerv4_h
19 #define itkLBFGS2Optimizerv4_h
22 #include "ITKOptimizersv4Export.h"
88 extern ITKOptimizersv4_EXPORT std::ostream &
164 template <
typename TInternalComputationValueType>
174 #if !defined(ITK_LEGACY_REMOVE)
176 static constexpr
LineSearchMethodEnum LINESEARCH_DEFAULT = LineSearchMethodEnum::LINESEARCH_DEFAULT;
177 static constexpr
LineSearchMethodEnum LINESEARCH_MORETHUENTE = LineSearchMethodEnum::LINESEARCH_MORETHUENTE;
179 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_ARMIJO;
180 static constexpr
LineSearchMethodEnum LINESEARCH_BACKTRACKING = LineSearchMethodEnum::LINESEARCH_BACKTRACKING;
182 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_WOLFE;
184 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_STRONG_WOLFE;
193 static_assert(std::is_same<TInternalComputationValueType, double>::value,
194 "LBFGS2Optimizerv4Template only supports double precision");
207 using typename Superclass::StopConditionReturnStringType;
217 StartOptimization(
bool doOnlyInitialization =
false)
override;
223 ResumeOptimization()
override;
226 GetStopConditionDescription()
const override;
237 SetHessianApproximationAccuracy(
int m);
239 GetHessianApproximationAccuracy()
const;
253 GetSolutionAccuracy()
const;
264 SetDeltaConvergenceDistance(
int nPast);
266 GetDeltaConvergenceDistance()
const;
282 GetDeltaConvergenceTolerance()
const;
294 SetMaximumIterations(
int maxIterations);
296 GetMaximumIterations()
const;
304 return GetMaximumIterations();
309 SetMaximumIterations(static_cast<int>(_arg));
320 SetLineSearch(
const LineSearchMethodEnum & linesearch);
322 GetLineSearch()
const;
331 SetMaximumLineSearchEvaluations(
int n);
333 GetMaximumLineSearchEvaluations()
const;
344 SetMinimumLineSearchStep(PrecisionType step);
346 GetMinimumLineSearchStep()
const;
357 SetMaximumLineSearchStep(PrecisionType step);
359 GetMaximumLineSearchStep()
const;
368 SetLineSearchAccuracy(PrecisionType ftol);
370 GetLineSearchAccuracy()
const;
383 SetWolfeCoefficient(PrecisionType wc);
385 GetWolfeCoefficient()
const;
400 SetLineSearchGradientAccuracy(PrecisionType gtol);
402 GetLineSearchGradientAccuracy()
const;
413 SetMachinePrecisionTolerance(PrecisionType xtol);
415 GetMachinePrecisionTolerance()
const;
432 SetOrthantwiseCoefficient(PrecisionType orthant_c);
434 GetOrthantwiseCoefficient()
const;
452 SetOrthantwiseStart(
int start);
454 GetOrthantwiseStart()
const;
465 SetOrthantwiseEnd(
int end);
467 GetOrthantwiseEnd()
const;
471 itkGetConstMacro(CurrentParameterNorm, PrecisionType);
474 itkGetConstMacro(CurrentGradientNorm, PrecisionType);
477 itkGetConstMacro(CurrentStepSize, PrecisionType);
480 itkGetConstMacro(CurrentNumberOfEvaluations, PrecisionType);
486 itkSetMacro(EstimateScalesAtEachIteration,
bool);
487 itkGetConstReferenceMacro(EstimateScalesAtEachIteration,
bool);
488 itkBooleanMacro(EstimateScalesAtEachIteration);
495 PrintSelf(std::ostream & os,
Indent indent)
const override;
500 UpdateProgressCallback(
void * instance,
501 const PrecisionType * x,
502 const PrecisionType * g,
503 const PrecisionType fx,
504 const PrecisionType xnorm,
505 const PrecisionType gnorm,
506 const PrecisionType step,
513 UpdateProgress(
const PrecisionType * x,
514 const PrecisionType * g,
515 const PrecisionType fx,
516 const PrecisionType xnorm,
517 const PrecisionType gnorm,
518 const PrecisionType step,
525 EvaluateCostCallback(
void * instance,
526 const PrecisionType * x,
529 const PrecisionType step);
532 EvaluateCost(
const PrecisionType * x, PrecisionType * g,
const int n,
const PrecisionType step);
536 class PrivateImplementationHolder;
537 lbfgs_parameter_t m_Parameters{};
539 bool m_EstimateScalesAtEachIteration{};
540 double m_CurrentStepSize{};
541 double m_CurrentParameterNorm{};
542 double m_CurrentGradientNorm{};
543 int m_CurrentNumberOfEvaluations{};
552 itkWarningMacro(
"Not supported. Please use LBFGS specific convergence methods.");
557 itkWarningMacro(
"Not supported. Please use LBFGS specific convergence methods.");
559 const PrecisionType &
562 itkWarningMacro(
"Not supported. Please use LBFGS specific convergence methods.");
571 itkWarningMacro(
"LBFGS2Optimizerv4Template does not implement single step advance");
581 #ifndef ITK_MANUAL_INSTANTIATION
582 # include "itkLBFGS2Optimizerv4.hxx"