ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkPowellOptimizerv4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
58 template<typename TInternalComputationValueType>
59 class ITK_TEMPLATE_EXPORT PowellOptimizerv4:
60  public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
61 {
62 public:
68 
70  itkNewMacro(Self);
71 
73  itkTypeMacro(PowellOptimizerv4, Superclass);
74 
75  using ParametersType = typename Superclass::ParametersType;
77  using ScalesType = typename Superclass::ScalesType;
78 
80  itkSetMacro(MaximumIteration, unsigned int);
81  itkGetConstReferenceMacro(MaximumIteration, unsigned int);
83 
85  itkSetMacro(MaximumLineIteration, unsigned int);
86  itkGetConstMacro(MaximumLineIteration, unsigned int);
88 
91  itkSetMacro(StepLength, double);
92  itkGetConstReferenceMacro(StepLength, double);
94 
97  itkSetMacro(StepTolerance, double);
98  itkGetConstReferenceMacro(StepTolerance, double);
100 
104  itkSetMacro(ValueTolerance, double);
105  itkGetConstReferenceMacro(ValueTolerance, double);
107 
109  itkGetConstReferenceMacro(CurrentCost, MeasureType);
110  const MeasureType & GetValue() const override { return this->GetCurrentCost(); }
112 
114  itkGetConstReferenceMacro(CurrentLineIteration, unsigned int);
115 
117  void StartOptimization(bool doOnlyInitialization = false) override;
118 
123  { m_Stop = true; }
124 
125  itkGetConstReferenceMacro(CatchGetValueException, bool);
126  itkSetMacro(CatchGetValueException, bool);
127 
128  itkGetConstReferenceMacro(MetricWorstPossibleValue, double);
129  itkSetMacro(MetricWorstPossibleValue, double);
130 
131  const std::string GetStopConditionDescription() const override;
132 
133 protected:
136  ~PowellOptimizerv4() override = default;
137  void PrintSelf(std::ostream & os, Indent indent) const override;
138 
139  itkSetMacro(CurrentCost, double);
140 
143  void SetLine(const ParametersType & origin,
144  const vnl_vector< double > & direction);
145 
149  double GetLineValue(double x) const;
150 
151  double GetLineValue(double x, ParametersType & tempCoord) const;
152 
155  void SetCurrentLinePoint(double x, double fx);
156 
159  void Swap(double *a, double *b) const;
160 
163  void Shift(double *a, double *b, double *c, double d) const;
164 
174  virtual void LineBracket(double *ax, double *bx, double *cx,
175  double *fa, double *fb, double *fc);
176 
177  virtual void LineBracket(double *ax, double *bx, double *cx,
178  double *fa, double *fb, double *fc,
179  ParametersType & tempCoord);
180 
186  virtual void BracketedLineOptimize(double ax, double bx, double cx,
187  double fa, double fb, double fc,
188  double *extX, double *extVal);
189 
190  virtual void BracketedLineOptimize(double ax, double bx, double cx,
191  double fa, double fb, double fc,
192  double *extX, double *extVal,
193  ParametersType & tempCoord);
194 
195  itkGetMacro(SpaceDimension, unsigned int);
196  void SetSpaceDimension(unsigned int dim)
197  {
198  this->m_SpaceDimension = dim;
199  this->m_LineDirection.set_size(dim);
200  this->m_LineOrigin.set_size(dim);
201  this->m_CurrentPosition.set_size(dim);
202  this->Modified();
203  }
204 
205  itkSetMacro(CurrentIteration, unsigned int);
206 
207  itkGetMacro(Stop, bool);
208  itkSetMacro(Stop, bool);
209 
210 private:
211  unsigned int m_SpaceDimension{0};
212 
214  unsigned int m_CurrentLineIteration{0};
215 
217  unsigned int m_MaximumIteration{100};
218  unsigned int m_MaximumLineIteration{100};
219 
220  bool m_CatchGetValueException{false};
221  double m_MetricWorstPossibleValue{0};
222 
224  double m_StepLength{0};
225  double m_StepTolerance{0};
226 
228  vnl_vector< double > m_LineDirection;
229 
230  double m_ValueTolerance{0};
231 
234 
239  bool m_Stop{false};
240 
242 
243  std::ostringstream m_StopConditionDescription;
244 }; // end of class
245 } // end of namespace itk
246 
247 #ifndef ITK_MANUAL_INSTANTIATION
248 #include "itkPowellOptimizerv4.hxx"
249 #endif
250 
251 #endif
Light weight base class for most itk classes.
Implements Powell optimization using Brent line search.
const MeasureType & GetValue() const override
vnl_vector< double > m_LineDirection
void SetSpaceDimension(unsigned int dim)
std::ostringstream m_StopConditionDescription
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract base for object-to-object optimizers.