ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLBFGSOptimizerBasev4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 */
38 // Forward reference because of circular dependencies
39 template< typename TInternalVnlOptimizerType >
40 class ITK_TEMPLATE_EXPORT LBFGSOptimizerBaseHelperv4;
41 
73 template< typename TInternalVnlOptimizerType >
74 class ITK_TEMPLATE_EXPORT LBFGSOptimizerBasev4:
76 {
77 public:
78  ITK_DISALLOW_COPY_AND_ASSIGN(LBFGSOptimizerBasev4);
79 
85 
88 
89  using MetricType = Superclass::MetricType;
90  using ParametersType = Superclass::ParametersType;
91  using ScalesType = Superclass::ScalesType;
92 
94  using StopConditionReturnStringType = Superclass::StopConditionReturnStringType;
95 
97  using StopConditionDescriptionType = Superclass::StopConditionDescriptionType;
98 
101 
103  InternalOptimizerType * GetOptimizer();
104 
106  void StartOptimization(bool doOnlyInitialization = false) override;
107 
109  void SetMetric(MetricType *metric) override;
110 
114  virtual void SetTrace(bool flag);
115 
116  itkGetConstMacro(Trace, bool);
117  itkBooleanMacro(Trace);
118 
120  virtual void SetMaximumNumberOfFunctionEvaluations(unsigned int n);
121 
122  itkGetConstMacro(MaximumNumberOfFunctionEvaluations, unsigned int);
123 
129  virtual void SetGradientConvergenceTolerance(double gtol);
130 
131  itkGetConstMacro(GradientConvergenceTolerance, double);
132 
134  const StopConditionReturnStringType GetStopConditionDescription() const override;
135 
136 protected:
138  ~LBFGSOptimizerBasev4() override = default;
139  void PrintSelf(std::ostream & os, Indent indent) const override;
140 
141  using CostFunctionAdaptorType = Superclass::CostFunctionAdaptorType;
142 
143  bool m_OptimizerInitialized{false};
144 
145  using InternalOptimizerAutoPointer = std::unique_ptr<InternalOptimizerType>;
147 
148  mutable std::ostringstream m_StopConditionDescription;
149 
150  bool m_Trace{false};
151  unsigned int m_MaximumNumberOfFunctionEvaluations{2000};
152  double m_GradientConvergenceTolerance{1e-5};
153  double m_InfinityNormOfProjectedGradient{0.0};
154  double m_CostFunctionConvergenceFactor{1e+7};
155 
156  // give the helper access to member variables, to update iteration
157  // counts, etc.
158  friend class LBFGSOptimizerBaseHelperv4<TInternalVnlOptimizerType>;
160 };
161 } // end namespace itk
162 
163 #ifndef ITK_MANUAL_INSTANTIATION
164 #include "itkLBFGSOptimizerBasev4.hxx"
165 #endif
166 
167 #endif
Light weight base class for most itk classes.
std::unique_ptr< InternalOptimizerType > InternalOptimizerAutoPointer
InternalOptimizerAutoPointer m_VnlOptimizer
Wrapper helper around vnl optimizer.
Superclass::StopConditionDescriptionType StopConditionDescriptionType
Wrapper helper around vnl_lbfgsb.
std::ostringstream m_StopConditionDescription
This class is an Adaptor that allows to pass itk::ObjectToObjectMetricBase objects to vnl_optimizers ...
This is a base for the ITKv4 Optimization methods using the vnl library.
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Superclass::StopConditionReturnStringType StopConditionReturnStringType
Abstract base for vnl lbfgs algorithm optimizers in ITKv4 registration framework. ...