ITK  6.0.0
Insight Toolkit
itkQuasiNewtonOptimizerv4.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 itkQuasiNewtonOptimizerv4_h
19 #define itkQuasiNewtonOptimizerv4_h
20 
21 #include "itkArray2D.h"
22 #include "itkBooleanStdVector.h"
24 
25 #include "vnl/algo/vnl_matrix_inverse.h"
26 #include "vnl/algo/vnl_determinant.h"
27 
28 namespace itk
29 {
60 template <typename TInternalComputationValueType>
61 class ITK_TEMPLATE_EXPORT QuasiNewtonOptimizerv4Template
62  : public GradientDescentOptimizerv4Template<TInternalComputationValueType>
63 {
64 public:
65  ITK_DISALLOW_COPY_AND_MOVE(QuasiNewtonOptimizerv4Template);
66 
72 
74  itkNewMacro(Self);
75 
77  itkOverrideGetNameOfClassMacro(QuasiNewtonOptimizerv4Template);
78 
80  using InternalComputationValueType = TInternalComputationValueType;
81 
82  using typename Superclass::ParametersType;
83  using typename Superclass::MeasureType;
84  using typename Superclass::DerivativeType;
85  using typename Superclass::IndexRangeType;
86 
89 
91  using HessianArrayType = std::vector<HessianType>;
92 
94  void
95  StartOptimization(bool doOnlyInitialization = false) override;
96 
98  itkSetMacro(MaximumIterationsWithoutProgress, SizeValueType);
99 
114  itkSetMacro(MaximumNewtonStepSizeInPhysicalUnits, TInternalComputationValueType);
115 
117  itkGetConstReferenceMacro(NewtonStep, DerivativeType);
118 
123  virtual void
124  EstimateNewtonStepOverSubRange(const IndexRangeType & subrange);
125 
126 protected:
128  SizeValueType m_MaximumIterationsWithoutProgress{ 30 };
129 
131  ParametersType m_CurrentPosition{};
132  ParametersType m_OptimalStep{};
133 
135  MeasureType m_PreviousValue{};
136  ParametersType m_PreviousPosition{};
137 
139  MeasureType m_BestValue{};
140  ParametersType m_BestPosition{};
141  SizeValueType m_BestIteration{ 0 };
142 
144  DerivativeType m_NewtonStep{};
145 
147  std::string m_NewtonStepWarning{};
148 
150  TInternalComputationValueType m_MaximumNewtonStepSizeInPhysicalUnits{};
151 
153  HessianArrayType m_HessianArray{};
154 
157  BooleanStdVectorType m_NewtonStepValidFlags{};
158 
160  virtual void
161  EstimateNewtonStep();
162 
167  virtual bool
168  ComputeHessianAndStepWithBFGS(IndexValueType loc);
169 
171  virtual void
172  ResetNewtonStep(IndexValueType loc);
173 
178  void
179  CombineGradientNewtonStep();
180 
189  void
190  ModifyCombinedNewtonStep();
191 
196  void
197  AdvanceOneStep() override;
198 
200  ~QuasiNewtonOptimizerv4Template() override = default;
201 
202  void
203  PrintSelf(std::ostream & os, Indent indent) const override;
204 
205 private:
208 };
209 
212 
213 } // end namespace itk
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
216 # include "itkQuasiNewtonOptimizerv4.hxx"
217 #endif
218 
219 #endif
itk::OptimizerParameters< TInternalComputationValueType >
itk::QuasiNewtonOptimizerv4Template
class ITK_FORWARD_EXPORT QuasiNewtonOptimizerv4Template
Definition: itkQuasiNewtonOptimizerv4EstimateNewtonStepThreader.h:27
itkBooleanStdVector.h
itk::GradientDescentOptimizerv4Template
Gradient descent optimizer.
Definition: itkGradientDescentOptimizerv4.h:78
itk::BooleanStdVectorType
std::vector< Boolean > BooleanStdVectorType
Definition: itkBooleanStdVector.h:34
itk::QuasiNewtonOptimizerv4Template
Implement a Quasi-Newton optimizer with BFGS Hessian estimation.
Definition: itkQuasiNewtonOptimizerv4.h:61
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::GradientDescentOptimizerBasev4Template::IndexRangeType
ThreadedIndexedContainerPartitioner::IndexRangeType IndexRangeType
Definition: itkGradientDescentOptimizerBasev4.h:142
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkGradientDescentOptimizerv4.h
itk::GradientDescentOptimizerBasev4Template::InternalComputationValueType
TInternalComputationValueType InternalComputationValueType
Definition: itkGradientDescentOptimizerBasev4.h:80
itk::ObjectToObjectOptimizerBaseTemplate::DerivativeType
typename MetricType::DerivativeType DerivativeType
Definition: itkObjectToObjectOptimizerBase.h:139
itkArray2D.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Array2D
Array2D class representing a 2D array.
Definition: itkArray2D.h:42
itk::ObjectToObjectOptimizerBaseTemplate::MeasureType
typename MetricType::MeasureType MeasureType
Definition: itkObjectToObjectOptimizerBase.h:145
itk::QuasiNewtonOptimizerv4Template::HessianArrayType
std::vector< HessianType > HessianArrayType
Definition: itkQuasiNewtonOptimizerv4.h:91
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86