ITK  5.2.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  * 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 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 
74  itkTypeMacro(PowellOptimizerv4, Superclass);
75 
76  using ParametersType = typename Superclass::ParametersType;
78  using ScalesType = typename Superclass::ScalesType;
79 
81  itkSetMacro(MaximumIteration, unsigned int);
82  itkGetConstReferenceMacro(MaximumIteration, unsigned int);
84 
86  itkSetMacro(MaximumLineIteration, unsigned int);
87  itkGetConstMacro(MaximumLineIteration, unsigned int);
89 
92  itkSetMacro(StepLength, double);
93  itkGetConstReferenceMacro(StepLength, double);
95 
98  itkSetMacro(StepTolerance, double);
99  itkGetConstReferenceMacro(StepTolerance, double);
101 
105  itkSetMacro(ValueTolerance, double);
106  itkGetConstReferenceMacro(ValueTolerance, double);
108 
110  itkGetConstReferenceMacro(CurrentCost, MeasureType);
111  const MeasureType &
112  GetValue() const override
113  {
114  return this->GetCurrentCost();
115  }
117 
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 
137  itkGetConstReferenceMacro(MetricWorstPossibleValue, double);
138  itkSetMacro(MetricWorstPossibleValue, double);
139 
140  const std::string
141  GetStopConditionDescription() const override;
142 
143 protected:
146  ~PowellOptimizerv4() override = default;
147  void
148  PrintSelf(std::ostream & os, Indent indent) const override;
149 
150  itkSetMacro(CurrentCost, double);
151 
154  void
155  SetLine(const ParametersType & origin, const vnl_vector<double> & direction);
156 
160  double
161  GetLineValue(double x) const;
162 
163  double
164  GetLineValue(double x, ParametersType & tempCoord) const;
165 
168  void
169  SetCurrentLinePoint(double x, double fx);
170 
173  void
174  Swap(double * a, double * b) const;
175 
178  void
179  Shift(double * a, double * b, double * c, double d) const;
180 
190  virtual void
191  LineBracket(double * x1, double * x2, double * x3, double * f1, double * f2, double * f3);
192 
193  virtual void
194  LineBracket(double * x1, double * x2, double * x3, double * f1, double * f2, double * f3, ParametersType & tempCoord);
195 
201  virtual void
202  BracketedLineOptimize(double ax,
203  double bx,
204  double cx,
205  double fa,
206  double functionValueOfb,
207  double fc,
208  double * extX,
209  double * extVal);
210 
211  virtual void
212  BracketedLineOptimize(double ax,
213  double bx,
214  double cx,
215  double fa,
216  double functionValueOfb,
217  double fc,
218  double * extX,
219  double * extVal,
220  ParametersType & tempCoord);
221 
222  itkGetMacro(SpaceDimension, unsigned int);
223  void
224  SetSpaceDimension(unsigned int dim)
225  {
226  this->m_SpaceDimension = dim;
227  this->m_LineDirection.set_size(dim);
228  this->m_LineOrigin.set_size(dim);
229  this->m_CurrentPosition.set_size(dim);
230  this->Modified();
231  }
232 
233  itkSetMacro(CurrentIteration, unsigned int);
234 
235  itkGetMacro(Stop, bool);
236  itkSetMacro(Stop, bool);
237 
238 private:
239  unsigned int m_SpaceDimension{ 0 };
240 
242  unsigned int m_CurrentLineIteration{ 0 };
243 
245  unsigned int m_MaximumIteration{ 100 };
246  unsigned int m_MaximumLineIteration{ 100 };
247 
248  bool m_CatchGetValueException{ false };
249  double m_MetricWorstPossibleValue{ 0 };
250 
252  double m_StepLength{ 0 };
253  double m_StepTolerance{ 0 };
254 
256  vnl_vector<double> m_LineDirection;
257 
258  double m_ValueTolerance{ 0 };
259 
262 
267  bool m_Stop{ false };
268 
270 
271  std::ostringstream m_StopConditionDescription;
272 }; // end of class
273 } // end of namespace itk
274 
275 #ifndef ITK_MANUAL_INSTANTIATION
276 # include "itkPowellOptimizerv4.hxx"
277 #endif
278 
279 #endif
itk::OptimizerParameters< TInternalComputationValueType >
itk::PowellOptimizerv4::m_StopConditionDescription
std::ostringstream m_StopConditionDescription
Definition: itkPowellOptimizerv4.h:271
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::PowellOptimizerv4::m_LineDirection
vnl_vector< double > m_LineDirection
Definition: itkPowellOptimizerv4.h:256
itk::PowellOptimizerv4::m_CurrentCost
MeasureType m_CurrentCost
Definition: itkPowellOptimizerv4.h:261
itk::PowellOptimizerv4::m_LineOrigin
ParametersType m_LineOrigin
Definition: itkPowellOptimizerv4.h:255
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
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::m_CurrentPosition
ParametersType m_CurrentPosition
Definition: itkPowellOptimizerv4.h:269
itk::PowellOptimizerv4::SetSpaceDimension
void SetSpaceDimension(unsigned int dim)
Definition: itkPowellOptimizerv4.h:224
itk::ObjectToObjectOptimizerBaseTemplate::MeasureType
typename MetricType::MeasureType MeasureType
Definition: itkObjectToObjectOptimizerBase.h:145