ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkPowellOptimizer.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkPowellOptimizer_h
00019 #define __itkPowellOptimizer_h
00020 
00021 #include "itkVector.h"
00022 #include "itkMatrix.h"
00023 #include "itkSingleValuedNonLinearOptimizer.h"
00024 
00025 namespace itk
00026 {
00061 class ITK_EXPORT PowellOptimizer:
00062   public SingleValuedNonLinearOptimizer
00063 {
00064 public:
00066   typedef PowellOptimizer                Self;
00067   typedef SingleValuedNonLinearOptimizer Superclass;
00068   typedef SmartPointer< Self >           Pointer;
00069   typedef SmartPointer< const Self >     ConstPointer;
00070 
00071   typedef SingleValuedNonLinearOptimizer::ParametersType
00072   ParametersType;
00073 
00075   itkNewMacro(Self);
00076 
00078   itkTypeMacro(PowellOptimizer, SingleValuedNonLinearOptimizer);
00079 
00081   typedef  SingleValuedCostFunction  CostFunctionType;
00082   typedef  CostFunctionType::Pointer CostFunctionPointer;
00083 
00085   itkSetMacro(Maximize, bool);
00086   itkBooleanMacro(Maximize);
00087   itkGetConstReferenceMacro(Maximize, bool);
00089 
00091   itkSetMacro(MaximumIteration, unsigned int);
00092   itkGetConstReferenceMacro(MaximumIteration, unsigned int);
00094 
00096   itkSetMacro(MaximumLineIteration, unsigned int);
00097   itkGetConstMacro(MaximumLineIteration, unsigned int);
00099 
00102   itkSetMacro(StepLength, double);
00103   itkGetConstReferenceMacro(StepLength, double);
00105 
00108   itkSetMacro(StepTolerance, double);
00109   itkGetConstReferenceMacro(StepTolerance, double);
00111 
00115   itkSetMacro(ValueTolerance, double);
00116   itkGetConstReferenceMacro(ValueTolerance, double);
00118 
00120   itkGetConstReferenceMacro(CurrentCost, MeasureType);
00121   MeasureType GetValue() const { return this->GetCurrentCost(); }
00123 
00125   itkGetConstReferenceMacro(CurrentIteration, unsigned int);
00126 
00128   itkGetConstReferenceMacro(CurrentLineIteration, unsigned int);
00129 
00131   void StartOptimization();
00132 
00136   void StopOptimization()
00137   { m_Stop = true; }
00138 
00139   itkGetConstReferenceMacro(CatchGetValueException, bool);
00140   itkSetMacro(CatchGetValueException, bool);
00141 
00142   itkGetConstReferenceMacro(MetricWorstPossibleValue, double);
00143   itkSetMacro(MetricWorstPossibleValue, double);
00144 
00145   const std::string GetStopConditionDescription() const;
00146 
00147 protected:
00148   PowellOptimizer();
00149   PowellOptimizer(const PowellOptimizer &);
00150   virtual ~PowellOptimizer();
00151   void PrintSelf(std::ostream & os, Indent indent) const;
00152 
00153   itkSetMacro(CurrentCost, double);
00154 
00157   void SetLine(const ParametersType & origin,
00158                const vnl_vector< double > & direction);
00159 
00163   double GetLineValue(double x) const;
00164 
00165   double GetLineValue(double x, ParametersType & tempCoord) const;
00166 
00169   void   SetCurrentLinePoint(double x, double fx);
00170 
00173   void   Swap(double *a, double *b) const;
00174 
00177   void   Shift(double *a, double *b, double *c, double d) const;
00178 
00188   virtual void   LineBracket(double *ax, double *bx, double *cx,
00189                              double *fa, double *fb, double *fc);
00190 
00191   virtual void   LineBracket(double *ax, double *bx, double *cx,
00192                              double *fa, double *fb, double *fc,
00193                              ParametersType & tempCoord);
00194 
00200   virtual void   BracketedLineOptimize(double ax, double bx, double cx,
00201                                        double fa, double fb, double fc,
00202                                        double *extX, double *extVal);
00203 
00204   virtual void   BracketedLineOptimize(double ax, double bx, double cx,
00205                                        double fa, double fb, double fc,
00206                                        double *extX, double *extVal,
00207                                        ParametersType & tempCoord);
00208 
00209   itkGetMacro(SpaceDimension, unsigned int);
00210   void SetSpaceDimension(unsigned int dim)
00211   {
00212     this->m_SpaceDimension = dim;
00213     this->m_LineDirection.set_size(dim);
00214     this->m_LineOrigin.set_size(dim);
00215     this->m_CurrentPosition.set_size(dim);
00216     this->Modified();
00217   }
00218 
00219   itkSetMacro(CurrentIteration, unsigned int);
00220 
00221   itkGetMacro(Stop, bool);
00222   itkSetMacro(Stop, bool);
00223 private:
00224   unsigned int m_SpaceDimension;
00225 
00227   unsigned int m_CurrentIteration;
00228   unsigned int m_CurrentLineIteration;
00229 
00231   unsigned int m_MaximumIteration;
00232   unsigned int m_MaximumLineIteration;
00233 
00234   bool   m_CatchGetValueException;
00235   double m_MetricWorstPossibleValue;
00236 
00238   bool m_Maximize;
00239 
00241   double m_StepLength;
00242   double m_StepTolerance;
00243 
00244   ParametersType       m_LineOrigin;
00245   vnl_vector< double > m_LineDirection;
00246 
00247   double m_ValueTolerance;
00248 
00250   MeasureType m_CurrentCost;
00251 
00256   bool m_Stop;
00257 
00258   std::ostringstream m_StopConditionDescription;
00259 }; // end of class
00260 } // end of namespace itk
00261 
00262 #endif
00263