ITK  4.6.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>
60  public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
61 {
62 public:
68 
70  itkNewMacro(Self);
71 
73  itkTypeMacro(PowellOptimizerv4, Superclass);
74 
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  virtual const MeasureType & GetValue() const { return this->GetCurrentCost(); }
112 
114  itkGetConstReferenceMacro(CurrentLineIteration, unsigned int);
115 
117  virtual void StartOptimization(bool doOnlyInitialization = false) ITK_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  virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
132 
133 protected:
135  PowellOptimizerv4(const PowellOptimizerv4 &);
136  virtual ~PowellOptimizerv4();
137  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_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;
212 
215 
217  unsigned int m_MaximumIteration;
219 
222 
224  double m_StepLength;
226 
228  vnl_vector< double > m_LineDirection;
229 
231 
234 
239  bool m_Stop;
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
OptimizerParameters< TInternalComputationValueType > ScalesType
double GetLineValue(double x) const
Light weight base class for most itk classes.
virtual const MeasureType & GetCurrentCost() const
OptimizerParameters< TInternalComputationValueType > ParametersType
Implements Powell optimization using Brent line search.
SmartPointer< Self > Pointer
virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE
SmartPointer< const Self > ConstPointer
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual const MeasureType & GetValue() const
Superclass::MeasureType MeasureType
void SetLine(const ParametersType &origin, const vnl_vector< double > &direction)
virtual void LineBracket(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc)
vnl_vector< double > m_LineDirection
ObjectToObjectOptimizerBaseTemplate< TInternalComputationValueType > Superclass
void SetSpaceDimension(unsigned int dim)
Superclass::ScalesType ScalesType
virtual void StartOptimization(bool doOnlyInitialization=false) ITK_OVERRIDE
std::ostringstream m_StopConditionDescription
void Shift(double *a, double *b, double *c, double d) const
void SetCurrentLinePoint(double x, double fx)
virtual void Modified() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void Swap(double *a, double *b) const
virtual void BracketedLineOptimize(double ax, double bx, double cx, double fa, double fb, double fc, double *extX, double *extVal)
Abstract base for object-to-object optimizers.
Superclass::ParametersType ParametersType