ITK  5.4.0
Insight Toolkit
itkPowellOptimizerv4.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 itkPowellOptimizerv4_h
19 #define itkPowellOptimizerv4_h
20 
21 #include "itkVector.h"
22 #include "itkMatrix.h"
24 
25 namespace itk
26 {
59 template <typename TInternalComputationValueType>
60 class ITK_TEMPLATE_EXPORT PowellOptimizerv4 : public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
61 {
62 public:
63 
69 
71  itkNewMacro(Self);
72 
75 
76  using typename Superclass::ParametersType;
77  using typename Superclass::MeasureType;
78  using typename Superclass::ScalesType;
79 
81  itkSetMacro(MaximumIteration, unsigned int);
82  itkGetConstReferenceMacro(MaximumIteration, unsigned int);
86  itkSetMacro(MaximumLineIteration, unsigned int);
87  itkGetConstMacro(MaximumLineIteration, unsigned int);
92  itkSetMacro(StepLength, double);
93  itkGetConstReferenceMacro(StepLength, double);
98  itkSetMacro(StepTolerance, double);
99  itkGetConstReferenceMacro(StepTolerance, double);
105  itkSetMacro(ValueTolerance, double);
106  itkGetConstReferenceMacro(ValueTolerance, double);
110  itkGetConstReferenceMacro(CurrentCost, MeasureType);
111  const MeasureType &
112  GetValue() const override
113  {
114  return this->GetCurrentCost();
115  }
119  itkGetConstReferenceMacro(CurrentLineIteration, unsigned int);
120 
122  void
123  StartOptimization(bool doOnlyInitialization = false) override;
124 
128  void
130  {
131  m_Stop = true;
132  }
133 
134  itkGetConstReferenceMacro(CatchGetValueException, bool);
135  itkSetMacro(CatchGetValueException, bool);
136  itkBooleanMacro(CatchGetValueException);
137 
138  itkGetConstReferenceMacro(MetricWorstPossibleValue, double);
139  itkSetMacro(MetricWorstPossibleValue, double);
140 
141  const std::string
142  GetStopConditionDescription() const override;
143 
144 protected:
147  ~PowellOptimizerv4() override = default;
148  void
149  PrintSelf(std::ostream & os, Indent indent) const override;
150 
151  itkSetMacro(CurrentCost, double);
152 
155  void
156  SetLine(const ParametersType & origin, const vnl_vector<double> & direction);
157 
161  double
162  GetLineValue(double x) const;
163 
164  double
165  GetLineValue(double x, ParametersType & tempCoord) const;
166 
169  void
170  SetCurrentLinePoint(double x, double fx);
171 
174  void
175  Swap(double * a, double * b) const;
176 
179  void
180  Shift(double * a, double * b, double * c, double d) const;
181 
191  virtual void
192  LineBracket(double * x1, double * x2, double * x3, double * f1, double * f2, double * f3);
193 
194  virtual void
195  LineBracket(double * x1, double * x2, double * x3, double * f1, double * f2, double * f3, ParametersType & tempCoord);
196 
202  virtual void
203  BracketedLineOptimize(double ax,
204  double bx,
205  double cx,
206  double fa,
207  double functionValueOfb,
208  double fc,
209  double * extX,
210  double * extVal);
211 
212  virtual void
213  BracketedLineOptimize(double ax,
214  double bx,
215  double cx,
216  double fa,
217  double functionValueOfb,
218  double fc,
219  double * extX,
220  double * extVal,
221  ParametersType & tempCoord);
222 
223  itkGetMacro(SpaceDimension, unsigned int);
224  void
225  SetSpaceDimension(unsigned int dim)
226  {
227  this->m_SpaceDimension = dim;
228  this->m_LineDirection.set_size(dim);
229  this->m_LineOrigin.set_size(dim);
230  this->m_CurrentPosition.set_size(dim);
231  this->Modified();
232  }
233 
234  itkSetMacro(CurrentIteration, unsigned int);
235 
236  itkGetMacro(Stop, bool);
237  itkSetMacro(Stop, bool);
238 
239 private:
240  unsigned int m_SpaceDimension{ 0 };
241 
243  unsigned int m_CurrentLineIteration{ 0 };
244 
246  unsigned int m_MaximumIteration{ 100 };
247  unsigned int m_MaximumLineIteration{ 100 };
248 
249  bool m_CatchGetValueException{ false };
250  double m_MetricWorstPossibleValue{ 0 };
251 
253  double m_StepLength{ 0 };
254  double m_StepTolerance{ 0 };
255 
256  ParametersType m_LineOrigin{};
257  vnl_vector<double> m_LineDirection{};
258 
259  double m_ValueTolerance{ 0 };
260 
262  MeasureType m_CurrentCost{};
263 
268  bool m_Stop{ false };
269 
270  ParametersType m_CurrentPosition{};
271 
272  std::ostringstream m_StopConditionDescription{};
273 }; // end of class
274 } // end of namespace itk
275 
276 #ifndef ITK_MANUAL_INSTANTIATION
277 # include "itkPowellOptimizerv4.hxx"
278 #endif
279 
280 #endif
itk::OptimizerParameters< TInternalComputationValueType >
itk::PowellOptimizerv4
Implements Powell optimization using Brent line search.
Definition: itkPowellOptimizerv4.h:60
itkMatrix.h
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
itkOverrideGetNameOfClassMacro
itkOverrideGetNameOfClassMacro(AddImageFilter)
itk::PowellOptimizerv4::StopOptimization
void StopOptimization()
Definition: itkPowellOptimizerv4.h:129
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::PowellOptimizerv4::GetValue
const MeasureType & GetValue() const override
Definition: itkPowellOptimizerv4.h:112
itkObjectToObjectOptimizerBase.h
itkVector.h
itk::ObjectToObjectOptimizerBaseTemplate
Abstract base for object-to-object optimizers.
Definition: itkObjectToObjectOptimizerBase.h:113
itk::PowellOptimizerv4::SetSpaceDimension
void SetSpaceDimension(unsigned int dim)
Definition: itkPowellOptimizerv4.h:225
itk::ObjectToObjectOptimizerBaseTemplate::MeasureType
typename MetricType::MeasureType MeasureType
Definition: itkObjectToObjectOptimizerBase.h:145