ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkLBFGS2Optimizerv4.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkLBFGS2Optimizerv4_h
19#define itkLBFGS2Optimizerv4_h
20
22#include "ITKOptimizersv4Export.h"
23#include <memory>
24
25#include "itk_lbfgs.h"
26
27namespace itk
28{
29/*** \class LBFGS2Optimizerv4Enums
30 * \brief Scoped Enum classes for LBFGS2Optimizerv4Template class
31 * \ingroup ITKOptimizersv4
32 */
34{
35public:
36 /*** \class LineSearchMethod
37 * \ingroup ITKOptimizersv4
38 * Line search method enum
39 */
86};
87// Define how to print enumeration
88extern ITKOptimizersv4_EXPORT std::ostream &
90
143template <typename TInternalComputationValueType>
144class ITK_TEMPLATE_EXPORT LBFGS2Optimizerv4Template
145 : public GradientDescentOptimizerv4Template<TInternalComputationValueType>
146{
147public:
148 ITK_DISALLOW_COPY_AND_MOVE(LBFGS2Optimizerv4Template);
149
151#if !defined(ITK_LEGACY_REMOVE)
153 static constexpr LineSearchMethodEnum LINESEARCH_DEFAULT = LineSearchMethodEnum::LINESEARCH_DEFAULT;
154 static constexpr LineSearchMethodEnum LINESEARCH_MORETHUENTE = LineSearchMethodEnum::LINESEARCH_MORETHUENTE;
155 static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_ARMIJO =
156 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_ARMIJO;
157 static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING = LineSearchMethodEnum::LINESEARCH_BACKTRACKING;
158 static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_WOLFE =
159 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_WOLFE;
160 static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_STRONG_WOLFE =
161 LineSearchMethodEnum::LINESEARCH_BACKTRACKING_STRONG_WOLFE;
162#endif
163
169 using PrecisionType = double;
170 static_assert(std::is_same<TInternalComputationValueType, double>::value,
171 "LBFGS2Optimizerv4Template only supports double precision");
172
178
182
185
187 itkNewMacro(Self);
188
190 itkOverrideGetNameOfClassMacro(LBFGS2Optimizerv4Template);
191
193 void
194 StartOptimization(bool doOnlyInitialization = false) override;
195
199 void
201
204
214 void
216 int
228 void
241 void
243 int
257 void
271 void
272 SetMaximumIterations(int maxIterations);
273 int
280 GetNumberOfIterations() const override
281 {
282 return GetMaximumIterations();
283 }
284 void
286 {
287 SetMaximumIterations(static_cast<int>(_arg));
288 }
289
297 void
308 void
310 int
321 void
334 void
345 void
360 void
377 void
390 void
409 void
429 void
431 int
442 void
444 int
448 itkGetConstMacro(CurrentParameterNorm, PrecisionType);
449
451 itkGetConstMacro(CurrentGradientNorm, PrecisionType);
452
454 itkGetConstMacro(CurrentStepSize, PrecisionType);
455
457 itkGetConstMacro(CurrentNumberOfEvaluations, PrecisionType);
458
464 itkSetMacro(EstimateScalesAtEachIteration, bool);
465 itkGetConstReferenceMacro(EstimateScalesAtEachIteration, bool);
466 itkBooleanMacro(EstimateScalesAtEachIteration);
468protected:
471 void
472 PrintSelf(std::ostream & os, Indent indent) const override;
473
474
476 static int
477 UpdateProgressCallback(void * instance,
478 const PrecisionType * x,
479 const PrecisionType * g,
480 const PrecisionType fx,
481 const PrecisionType xnorm,
482 const PrecisionType gnorm,
483 const PrecisionType step,
484 int n,
485 int k,
486 int ls);
487
489 int
491 const PrecisionType * g,
492 const PrecisionType fx,
493 const PrecisionType xnorm,
494 const PrecisionType gnorm,
495 const PrecisionType step,
496 int n,
497 int k,
498 int ls);
499
501 static PrecisionType
502 EvaluateCostCallback(void * instance,
503 const PrecisionType * x,
504 PrecisionType * g,
505 const int n,
506 const PrecisionType step);
507
509 EvaluateCost(const PrecisionType * x, PrecisionType * g, const int n, const PrecisionType step);
510
511private:
512 // Private Implementation (Pimpl), to hide liblbfgs data structures
513 class PrivateImplementationHolder;
514 lbfgs_parameter_t m_Parameters{};
515
522
527 void
529 {
530 itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
531 }
532 void
534 {
535 itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
536 }
537 const PrecisionType &
538 GetConvergenceValue() const override
539 {
540 itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
541 static const PrecisionType value{};
542 return value;
543 }
544
545 void
546 AdvanceOneStep() override
547 {
548 itkWarningMacro("LBFGS2Optimizerv4Template does not implement single step advance");
549 }
550};
551
552
555
556} // end namespace itk
557
558#ifndef ITK_MANUAL_INSTANTIATION
559# include "itkLBFGS2Optimizerv4.hxx"
560#endif
561
562#endif
OptimizerParameters< TInternalComputationValueType > ParametersType
OptimizerParameters< TInternalComputationValueType > ScalesType
Control indentation during Print() invocation.
Definition itkIndent.h:50
Wrap of the libLBFGS algorithm for use in ITKv4 registration framework. LibLBFGS is a translation of ...
int GetHessianApproximationAccuracy() const
void SetMachinePrecisionTolerance(PrecisionType xtol)
void SetMaximumLineSearchStep(PrecisionType step)
PrecisionType GetWolfeCoefficient() const
void SetDeltaConvergenceTolerance(PrecisionType tol)
PrecisionType GetDeltaConvergenceTolerance() const
void StartOptimization(bool doOnlyInitialization=false) override
PrecisionType GetMaximumLineSearchStep() const
PrecisionType GetMachinePrecisionTolerance() const
StopConditionReturnStringType GetStopConditionDescription() const override
void SetOrthantwiseStart(int start)
LineSearchMethodEnum GetLineSearch() const
PrecisionType GetMinimumLineSearchStep() const
SizeValueType GetNumberOfIterations() const override
void SetHessianApproximationAccuracy(int m)
void SetLineSearchAccuracy(PrecisionType ftol)
void SetDeltaConvergenceDistance(int nPast)
void ResumeOptimization() override
LBFGS2Optimizerv4Enums::LineSearchMethod LineSearchMethodEnum
typename Superclass::ParametersType ParametersType
PrecisionType GetLineSearchGradientAccuracy() const
void SetMinimumConvergenceValue(PrecisionType) override
void SetConvergenceWindowSize(SizeValueType) override
typename Superclass::MetricType MetricType
int GetMaximumLineSearchEvaluations() const
PrecisionType GetLineSearchAccuracy() const
void SetLineSearchGradientAccuracy(PrecisionType gtol)
void SetNumberOfIterations(const SizeValueType _arg) override
typename Superclass::ScalesType ScalesType
const PrecisionType & GetConvergenceValue() const override
PrecisionType GetSolutionAccuracy() const
void PrintSelf(std::ostream &os, Indent indent) const override
SmartPointer< const Self > ConstPointer
PrecisionType GetOrthantwiseCoefficient() const
static int UpdateProgressCallback(void *instance, const PrecisionType *x, const PrecisionType *g, const PrecisionType fx, const PrecisionType xnorm, const PrecisionType gnorm, const PrecisionType step, int n, int k, int ls)
void SetLineSearch(const LineSearchMethodEnum &linesearch)
void SetMaximumIterations(int maxIterations)
void SetSolutionAccuracy(PrecisionType epsilon)
void SetOrthantwiseCoefficient(PrecisionType orthant_c)
GradientDescentOptimizerv4Template< TInternalComputationValueType > Superclass
void SetMinimumLineSearchStep(PrecisionType step)
void SetWolfeCoefficient(PrecisionType wc)
PrecisionType EvaluateCost(const PrecisionType *x, PrecisionType *g, const int n, const PrecisionType step)
int UpdateProgress(const PrecisionType *x, const PrecisionType *g, const PrecisionType fx, const PrecisionType xnorm, const PrecisionType gnorm, const PrecisionType step, int n, int k, int ls)
void SetMaximumLineSearchEvaluations(int n)
static PrecisionType EvaluateCostCallback(void *instance, const PrecisionType *x, PrecisionType *g, const int n, const PrecisionType step)
ObjectToObjectMetricBaseTemplate< TInternalComputationValueType > MetricType
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
LBFGS2Optimizerv4Template< double > LBFGS2Optimizerv4