ITK  6.0.0
Insight Toolkit
itkMultiStartOptimizerv4.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 itkMultiStartOptimizerv4_h
19 #define itkMultiStartOptimizerv4_h
20 
23 
24 namespace itk
25 {
26 
41 template <typename TInternalComputationValueType>
42 class ITK_TEMPLATE_EXPORT MultiStartOptimizerv4Template
43  : public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(MultiStartOptimizerv4Template);
47 
53 
55  itkOverrideGetNameOfClassMacro(MultiStartOptimizerv4Template);
56 
58  itkNewMacro(Self);
59 
60  using typename Superclass::ParametersType;
61  using ParametersListType = std::vector<ParametersType>;
62  using ParameterListSizeType = typename ParametersListType::size_type;
63 
68 
70 #if !defined(ITK_LEGACY_REMOVE)
71  // We need to expose the enum values at the class level
72  // for backwards compatibility
73  static constexpr itk::StopConditionObjectToObjectOptimizerEnum MAXIMUM_NUMBER_OF_ITERATIONS =
75  static constexpr itk::StopConditionObjectToObjectOptimizerEnum COSTFUNCTION_ERROR =
77  static constexpr itk::StopConditionObjectToObjectOptimizerEnum UPDATE_PARAMETERS_ERROR =
79  static constexpr itk::StopConditionObjectToObjectOptimizerEnum STEP_TOO_SMALL =
81  static constexpr itk::StopConditionObjectToObjectOptimizerEnum CONVERGENCE_CHECKER_PASSED =
83  static constexpr itk::StopConditionObjectToObjectOptimizerEnum OTHER_ERROR =
85 #endif
86 
88  using typename Superclass::StopConditionReturnStringType;
89 
91  using typename Superclass::StopConditionDescriptionType;
92 
96  using InternalComputationValueType = TInternalComputationValueType;
97 
99  using typename Superclass::MetricType;
101 
104 
106  using typename Superclass::MeasureType;
107  using MetricValuesListType = std::vector<MeasureType>;
108 
110  itkGetConstReferenceMacro(StopCondition, StopConditionObjectToObjectOptimizerEnum);
111 
113  void
114  InstantiateLocalOptimizer();
115 
117  void
118  StartOptimization(bool doOnlyInitialization = false) override;
119 
122  virtual void
123  StopOptimization();
124 
127  virtual void
128  ResumeOptimization();
129 
132  GetStopConditionDescription() const override;
133 
136  GetParametersList();
137 
139  void
140  SetParametersList(ParametersListType & p);
141 
143  const MetricValuesListType &
144  GetMetricValuesList() const;
145 
148  GetBestParameters();
149 
151  itkSetObjectMacro(LocalOptimizer, OptimizerType);
152  itkGetModifiableObjectMacro(LocalOptimizer, OptimizerType);
155  inline ParameterListSizeType
157  {
158  return this->m_BestParametersIndex;
159  }
160 
161 protected:
164  ~MultiStartOptimizerv4Template() override = default;
167  void
168  PrintSelf(std::ostream & os, Indent indent) const override;
169 
170  /* Common variables for optimization control and reporting */
171  bool m_Stop{ false };
173  StopConditionDescriptionType m_StopConditionDescription{};
174  ParametersListType m_ParametersList{};
175  MetricValuesListType m_MetricValuesList{};
176  MeasureType m_MinimumMetricValue{};
177  MeasureType m_MaximumMetricValue{};
178  ParameterListSizeType m_BestParametersIndex{};
179  OptimizerPointer m_LocalOptimizer{};
180 };
181 
184 
185 } // end namespace itk
186 
187 #ifndef ITK_MANUAL_INSTANTIATION
188 # include "itkMultiStartOptimizerv4.hxx"
189 #endif
190 
191 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::MAXIMUM_NUMBER_OF_ITERATIONS
itk::OptimizerParameters< TInternalComputationValueType >
itk::MultiStartOptimizerv4Template::MetricTypePointer
typename MetricType::Pointer MetricTypePointer
Definition: itkMultiStartOptimizerv4.h:100
itk::GradientDescentOptimizerv4Template
Gradient descent optimizer.
Definition: itkGradientDescentOptimizerv4.h:78
itk::MultiStartOptimizerv4Template::InternalComputationValueType
TInternalComputationValueType InternalComputationValueType
Definition: itkMultiStartOptimizerv4.h:96
itk::MultiStartOptimizerv4Template::GetBestParametersIndex
ParameterListSizeType GetBestParametersIndex()
Definition: itkMultiStartOptimizerv4.h:156
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::CONVERGENCE_CHECKER_PASSED
itk::ObjectToObjectOptimizerBaseTemplate::StopConditionReturnStringType
std::string StopConditionReturnStringType
Definition: itkObjectToObjectOptimizerBase.h:148
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::COSTFUNCTION_ERROR
itk::MultiStartOptimizerv4Template
Multi-start searches over input parameters and returns the best metric value.
Definition: itkMultiStartOptimizerv4.h:42
itk::MultiStartOptimizerv4Template::OptimizerPointer
typename OptimizerType::Pointer OptimizerPointer
Definition: itkMultiStartOptimizerv4.h:65
itk::MultiStartOptimizerv4Template::MetricValuesListType
std::vector< MeasureType > MetricValuesListType
Definition: itkMultiStartOptimizerv4.h:107
itk::MultiStartOptimizerv4Template::ParametersListType
std::vector< ParametersType > ParametersListType
Definition: itkMultiStartOptimizerv4.h:61
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MultiStartOptimizerv4Template::ParameterListSizeType
typename ParametersListType::size_type ParameterListSizeType
Definition: itkMultiStartOptimizerv4.h:62
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer
StopConditionObjectToObjectOptimizer
Definition: itkObjectToObjectOptimizerBase.h:42
itkGradientDescentOptimizerv4.h
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::UPDATE_PARAMETERS_ERROR
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::OTHER_ERROR
itkObjectToObjectOptimizerBase.h
itk::ObjectToObjectOptimizerBaseTemplate
Abstract base for object-to-object optimizers.
Definition: itkObjectToObjectOptimizerBase.h:113
itk::Array< TInternalComputationValueType >
itk::MultiStartOptimizerv4Template::DerivativeType
typename MetricType::DerivativeType DerivativeType
Definition: itkMultiStartOptimizerv4.h:103
StopCondition
itk::MultiStartOptimizerv4Template::LocalOptimizerPointer
typename LocalOptimizerType::Pointer LocalOptimizerPointer
Definition: itkMultiStartOptimizerv4.h:67
itk::ObjectToObjectOptimizerBaseTemplate::MeasureType
typename MetricType::MeasureType MeasureType
Definition: itkObjectToObjectOptimizerBase.h:145
itk::MultiStartOptimizerv4Template::LocalOptimizerType
typename itk::GradientDescentOptimizerv4Template< TInternalComputationValueType > LocalOptimizerType
Definition: itkMultiStartOptimizerv4.h:66
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::STEP_TOO_SMALL