ITK  5.2.0
Insight Toolkit
itkLBFGSOptimizerBasev4.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  * http://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 itkLBFGSOptimizerBasev4_h
19 #define itkLBFGSOptimizerBasev4_h
20 
22 #include "vnl/algo/vnl_lbfgs.h"
23 #include "vnl/algo/vnl_lbfgsb.h"
24 #include <memory>
25 #include "ITKOptimizersv4Export.h"
26 
27 namespace itk
28 {
29 /* Necessary forward declaration see below for definition */
39 // Forward reference because of circular dependencies
40 template <typename TInternalVnlOptimizerType>
41 class ITK_TEMPLATE_EXPORT LBFGSOptimizerBaseHelperv4;
42 
75 template <typename TInternalVnlOptimizerType>
77 {
78 public:
79  ITK_DISALLOW_COPY_AND_MOVE(LBFGSOptimizerBasev4);
80 
86 
89 
90  using MetricType = Superclass::MetricType;
91  using ParametersType = Superclass::ParametersType;
92  using ScalesType = Superclass::ScalesType;
93 
95  using StopConditionReturnStringType = Superclass::StopConditionReturnStringType;
96 
98  using StopConditionDescriptionType = Superclass::StopConditionDescriptionType;
99 
102 
105  GetOptimizer();
106 
108  void
109  StartOptimization(bool doOnlyInitialization = false) override;
110 
112  void
113  SetMetric(MetricType * metric) override;
114 
118  virtual void
119  SetTrace(bool flag);
120 
121  itkGetConstMacro(Trace, bool);
122  itkBooleanMacro(Trace);
123 
125  virtual void
126  SetMaximumNumberOfFunctionEvaluations(unsigned int n);
127 
128  itkGetConstMacro(MaximumNumberOfFunctionEvaluations, unsigned int);
129 
135  virtual void
136  SetGradientConvergenceTolerance(double f);
137 
138  itkGetConstMacro(GradientConvergenceTolerance, double);
139 
142  GetStopConditionDescription() const override;
143 
144 protected:
146  ~LBFGSOptimizerBasev4() override = default;
147  void
148  PrintSelf(std::ostream & os, Indent indent) const override;
149 
150  using CostFunctionAdaptorType = Superclass::CostFunctionAdaptorType;
151 
152  bool m_OptimizerInitialized{ false };
153 
154  using InternalOptimizerAutoPointer = std::unique_ptr<InternalOptimizerType>;
156 
157  mutable std::ostringstream m_StopConditionDescription;
158 
159  bool m_Trace{ false };
160  unsigned int m_MaximumNumberOfFunctionEvaluations{ 2000 };
161  double m_GradientConvergenceTolerance{ 1e-5 };
162  double m_InfinityNormOfProjectedGradient{ 0.0 };
163  double m_CostFunctionConvergenceFactor{ 1e+7 };
164 
165  // give the helper access to member variables, to update iteration
166  // counts, etc.
167  friend class LBFGSOptimizerBaseHelperv4<TInternalVnlOptimizerType>;
169 };
170 } // end namespace itk
171 
172 #ifndef ITK_MANUAL_INSTANTIATION
173 # include "itkLBFGSOptimizerBasev4.hxx"
174 #endif
175 
176 #endif
itk::SingleValuedNonLinearVnlOptimizerv4::MetricType
Superclass::MetricType MetricType
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:58
itk::LBFGSOptimizerBasev4< vnl_lbfgsb >::InternalOptimizerAutoPointer
std::unique_ptr< InternalOptimizerType > InternalOptimizerAutoPointer
Definition: itkLBFGSOptimizerBasev4.h:154
itk::SingleValuedNonLinearVnlOptimizerv4::ScalesType
Superclass::ScalesType ScalesType
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:61
itk::LBFGSOptimizerBasev4::m_VnlOptimizer
InternalOptimizerAutoPointer m_VnlOptimizer
Definition: itkLBFGSOptimizerBasev4.h:155
itkSingleValuedNonLinearVnlOptimizerv4.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SingleValuedNonLinearVnlOptimizerv4
This is a base for the ITKv4 Optimization methods using the vnl library.
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:38
itk::SingleValuedNonLinearVnlOptimizerv4::StopConditionReturnStringType
Superclass::StopConditionReturnStringType StopConditionReturnStringType
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:64
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SingleValuedNonLinearVnlOptimizerv4::StopConditionDescriptionType
Superclass::StopConditionDescriptionType StopConditionDescriptionType
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:67
LBFGSBOptimizerHelperv4
Wrapper helper around vnl_lbfgsb.
itk::SingleValuedVnlCostFunctionAdaptorv4
This class is an Adaptor that allows to pass itk::ObjectToObjectMetricBase objects to vnl_optimizers ...
Definition: itkSingleValuedVnlCostFunctionAdaptorv4.h:37
LBFGSOptimizerBaseHelperv4
Wrapper helper around vnl optimizer.
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::SingleValuedNonLinearVnlOptimizerv4::ParametersType
Superclass::ParametersType ParametersType
Definition: itkSingleValuedNonLinearVnlOptimizerv4.h:60
itk::LBFGSOptimizerBasev4::m_StopConditionDescription
std::ostringstream m_StopConditionDescription
Definition: itkLBFGSOptimizerBasev4.h:157
itk::LBFGSOptimizerBasev4
Abstract base for vnl lbfgs algorithm optimizers in ITKv4 registration framework.
Definition: itkLBFGSOptimizerBasev4.h:76