ITK  6.0.0
Insight Toolkit
itkLBFGSOptimizer.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 itkLBFGSOptimizer_h
19 #define itkLBFGSOptimizer_h
20 
22 #include "vnl/algo/vnl_lbfgs.h"
23 #include "ITKOptimizersExport.h"
24 #include <memory> // For unique_ptr.
25 
26 namespace itk
27 {
86 class ITKOptimizers_EXPORT LBFGSOptimizer : public SingleValuedNonLinearVnlOptimizer
87 {
88 public:
89  ITK_DISALLOW_COPY_AND_MOVE(LBFGSOptimizer);
90 
96 
98  itkNewMacro(Self);
99 
101  itkOverrideGetNameOfClassMacro(LBFGSOptimizer);
102 
104  using InternalParametersType = vnl_vector<double>;
105 
107  using InternalOptimizerType = vnl_lbfgs;
108 
110  vnl_lbfgs *
111  GetOptimizer();
112 
114  void
115  StartOptimization() override;
116 
118  void
119  SetCostFunction(SingleValuedCostFunction * costFunction) override;
120 
124  virtual void
125  SetTrace(bool flag);
126 
127  itkGetMacro(Trace, bool);
128  itkBooleanMacro(Trace);
129 
131  virtual void
132  SetMaximumNumberOfFunctionEvaluations(unsigned int n);
133 
134  itkGetMacro(MaximumNumberOfFunctionEvaluations, unsigned int);
135 
141  virtual void
142  SetGradientConvergenceTolerance(double f);
143 
144  itkGetMacro(GradientConvergenceTolerance, double);
145 
152  virtual void
153  SetLineSearchAccuracy(double f);
154 
155  itkGetMacro(LineSearchAccuracy, double);
156 
161  virtual void
162  SetDefaultStepLength(double f);
163 
164  itkGetMacro(DefaultStepLength, double);
165 
168  GetValue() const;
169 
171  std::string
172  GetStopConditionDescription() const override;
173 
174 protected:
175  LBFGSOptimizer();
176  ~LBFGSOptimizer() override;
177  void
178  PrintSelf(std::ostream & os, Indent indent) const override;
179 
180  using CostFunctionAdaptorType = Superclass::CostFunctionAdaptorType;
181 
182 private:
183  bool m_OptimizerInitialized{};
184  std::unique_ptr<InternalOptimizerType> m_VnlOptimizer;
185  mutable std::ostringstream m_StopConditionDescription{};
186 
187  bool m_Trace{};
188  unsigned int m_MaximumNumberOfFunctionEvaluations{};
189  double m_GradientConvergenceTolerance{};
190  double m_LineSearchAccuracy{};
191  double m_DefaultStepLength{};
192 };
193 } // end namespace itk
194 
195 #endif
itk::LBFGSOptimizer::m_VnlOptimizer
std::unique_ptr< InternalOptimizerType > m_VnlOptimizer
Definition: itkLBFGSOptimizer.h:184
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::SingleValuedCostFunction
This class is a base for the CostFunctions returning a single value.
Definition: itkSingleValuedCostFunction.h:34
itk::LBFGSOptimizer::CostFunctionAdaptorType
Superclass::CostFunctionAdaptorType CostFunctionAdaptorType
Definition: itkLBFGSOptimizer.h:180
itkSingleValuedNonLinearVnlOptimizer.h
itk::LBFGSOptimizer::InternalOptimizerType
vnl_lbfgs InternalOptimizerType
Definition: itkLBFGSOptimizer.h:107
itk::LBFGSOptimizer
Wrap of the vnl_lbfgs algorithm for use in ITKv4 registration framework. The vnl_lbfgs is a wrapper f...
Definition: itkLBFGSOptimizer.h:86
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::SingleValuedNonLinearOptimizer::MeasureType
CostFunctionType::MeasureType MeasureType
Definition: itkSingleValuedNonLinearOptimizer.h:62
itk::LBFGSOptimizer::InternalParametersType
vnl_vector< double > InternalParametersType
Definition: itkLBFGSOptimizer.h:104
itk::SingleValuedNonLinearVnlOptimizer
This class is a base for the Optimization methods that optimize a single valued function.
Definition: itkSingleValuedNonLinearVnlOptimizer.h:39