ITK  5.2.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  * 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 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 
56 
58  itkNewMacro(Self);
59 
60  using ParametersType = typename Superclass::ParametersType;
61  using ParametersListType = std::vector<ParametersType>;
62  using ParameterListSizeType = typename ParametersListType::size_type;
63 
67  using LocalOptimizerPointer = typename LocalOptimizerType::Pointer;
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 StopConditionReturnStringType = typename Superclass::StopConditionReturnStringType;
89 
91  using StopConditionDescriptionType = typename Superclass::StopConditionDescriptionType;
92 
96  using InternalComputationValueType = TInternalComputationValueType;
97 
99  using MetricType = typename Superclass::MetricType;
100  using MetricTypePointer = typename MetricType::Pointer;
101 
103  using DerivativeType = typename MetricType::DerivativeType;
104 
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);
154 
155  inline ParameterListSizeType
157  {
158  return this->m_BestParametersIndex;
159  }
160 
161 protected:
164  ~MultiStartOptimizerv4Template() override = default;
166 
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 };
180 };
181 
184 
185 } // end namespace itk
186 
187 #ifndef ITK_MANUAL_INSTANTIATION
188 # include "itkMultiStartOptimizerv4.hxx"
189 #endif
190 
191 #endif
itk::MultiStartOptimizerv4Template::m_StopCondition
StopConditionObjectToObjectOptimizerEnum m_StopCondition
Definition: itkMultiStartOptimizerv4.h:172
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::MAXIMUM_NUMBER_OF_ITERATIONS
itk::MultiStartOptimizerv4Template::m_MinimumMetricValue
MeasureType m_MinimumMetricValue
Definition: itkMultiStartOptimizerv4.h:176
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::MultiStartOptimizerv4Template::StopConditionReturnStringType
typename Superclass::StopConditionReturnStringType StopConditionReturnStringType
Definition: itkMultiStartOptimizerv4.h:88
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::CONVERGENCE_CHECKER_PASSED
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::COSTFUNCTION_ERROR
itk::MultiStartOptimizerv4Template::m_MaximumMetricValue
MeasureType m_MaximumMetricValue
Definition: itkMultiStartOptimizerv4.h:177
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::MultiStartOptimizerv4Template::m_BestParametersIndex
ParameterListSizeType m_BestParametersIndex
Definition: itkMultiStartOptimizerv4.h:178
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::MultiStartOptimizerv4Template::ParameterListSizeType
typename ParametersListType::size_type ParameterListSizeType
Definition: itkMultiStartOptimizerv4.h:62
itk::MultiStartOptimizerv4Template::m_LocalOptimizer
OptimizerPointer m_LocalOptimizer
Definition: itkMultiStartOptimizerv4.h:179
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer
StopConditionObjectToObjectOptimizer
Definition: itkObjectToObjectOptimizerBase.h:42
itk::MultiStartOptimizerv4Template::m_StopConditionDescription
StopConditionDescriptionType m_StopConditionDescription
Definition: itkMultiStartOptimizerv4.h:173
itk::MultiStartOptimizerv4Template::m_ParametersList
ParametersListType m_ParametersList
Definition: itkMultiStartOptimizerv4.h:174
itkGradientDescentOptimizerv4.h
itk::MultiStartOptimizerv4Template::ParametersType
typename Superclass::ParametersType ParametersType
Definition: itkMultiStartOptimizerv4.h:60
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::UPDATE_PARAMETERS_ERROR
itk::MultiStartOptimizerv4Template::MetricType
typename Superclass::MetricType MetricType
Definition: itkMultiStartOptimizerv4.h:99
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::MultiStartOptimizerv4Template::DerivativeType
typename MetricType::DerivativeType DerivativeType
Definition: itkMultiStartOptimizerv4.h:103
itk::MultiStartOptimizerv4Template::m_MetricValuesList
MetricValuesListType m_MetricValuesList
Definition: itkMultiStartOptimizerv4.h:175
itk::MultiStartOptimizerv4Template::StopConditionDescriptionType
typename Superclass::StopConditionDescriptionType StopConditionDescriptionType
Definition: itkMultiStartOptimizerv4.h:91
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
itk::MultiStartOptimizerv4Template::MeasureType
typename Superclass::MeasureType MeasureType
Definition: itkMultiStartOptimizerv4.h:106