ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLBFGSBOptimizer.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 __itkLBFGSBOptimizer_h
00019 #define __itkLBFGSBOptimizer_h
00020 
00021 #include "itkIntTypes.h"
00022 #include "itkSingleValuedNonLinearVnlOptimizer.h"
00023 
00024 namespace itk
00025 {
00033 class ITK_EXPORT LBFGSBOptimizerHelper;
00034 
00061 class ITK_EXPORT LBFGSBOptimizer:
00062   public SingleValuedNonLinearVnlOptimizer
00063 {
00064 public:
00066   typedef LBFGSBOptimizer                   Self;
00067   typedef SingleValuedNonLinearVnlOptimizer Superclass;
00068   typedef SmartPointer< Self >              Pointer;
00069   typedef SmartPointer< const Self >        ConstPointer;
00070 
00072   itkNewMacro(Self);
00073 
00075   itkTypeMacro(LBFGSBOptimizer, SingleValuedNonLinearVnlOptimizer);
00076 
00080   typedef Array< double > BoundValueType;
00081 
00085   typedef Array< long > BoundSelectionType;
00086 
00088   typedef vnl_vector< double > InternalBoundValueType;
00089 
00091   typedef vnl_vector< long > InternalBoundSelectionType;
00092 
00094   typedef LBFGSBOptimizerHelper InternalOptimizerType;
00095 
00097   void StartOptimization(void);
00098 
00100   virtual void SetCostFunction(SingleValuedCostFunction *costFunction);
00101 
00105   virtual void SetTrace(bool flag);
00106 
00107   itkGetMacro(Trace, bool);
00108   itkBooleanMacro(Trace);
00109 
00111   virtual void SetLowerBound(const BoundValueType & value);
00112 
00113   virtual const BoundValueType & GetLowerBound();
00114 
00116   virtual void SetUpperBound(const BoundValueType & value);
00117 
00118   virtual const BoundValueType & GetUpperBound();
00119 
00126   virtual void SetBoundSelection(const BoundSelectionType & select);
00127 
00128   virtual const BoundSelectionType & GetBoundSelection();
00129 
00136   virtual void SetCostFunctionConvergenceFactor(double);
00137 
00138   itkGetMacro(CostFunctionConvergenceFactor, double);
00139 
00144   virtual void SetProjectedGradientTolerance(double);
00145 
00146   itkGetMacro(ProjectedGradientTolerance, double);
00147 
00149   virtual void SetMaximumNumberOfIterations(unsigned int);
00150 
00151   itkGetMacro(MaximumNumberOfIterations, unsigned int);
00152 
00154   virtual void SetMaximumNumberOfEvaluations(unsigned int);
00155 
00156   itkGetMacro(MaximumNumberOfEvaluations, unsigned int);
00157 
00159   virtual void SetMaximumNumberOfCorrections(unsigned int);
00160 
00161   itkGetMacro(MaximumNumberOfCorrections, unsigned int);
00162 
00164   void SetScales(const ScalesType &)
00165   {
00166     itkExceptionMacro(<< "This optimizer does not support scales.");
00167   }
00168 
00170   itkGetConstReferenceMacro(CurrentIteration, unsigned int);
00171 
00173   MeasureType GetValue() const;
00174 
00177   itkGetConstReferenceMacro(InfinityNormOfProjectedGradient, double);
00178 
00180   const std::string GetStopConditionDescription() const;
00181 
00182 protected:
00183   LBFGSBOptimizer();
00184   virtual ~LBFGSBOptimizer();
00185   void PrintSelf(std::ostream & os, Indent indent) const;
00186 
00187   typedef Superclass::CostFunctionAdaptorType CostFunctionAdaptorType;
00188 private:
00189   LBFGSBOptimizer(const Self &); //purposely not implemented
00190   void operator=(const Self &);  //purposely not implemented
00191 
00192   // give the helper access to member variables, to update iteration
00193   // counts, etc.
00194   friend class LBFGSBOptimizerHelper;
00195 
00196   bool                       m_Trace;
00197   bool                       m_OptimizerInitialized;
00198   InternalOptimizerType *    m_VnlOptimizer;
00199   mutable std::ostringstream m_StopConditionDescription;
00200   BoundValueType             m_LowerBound;
00201   BoundValueType             m_UpperBound;
00202   BoundSelectionType         m_BoundSelection;
00203 
00204   double       m_CostFunctionConvergenceFactor;
00205   double       m_ProjectedGradientTolerance;
00206   unsigned int m_MaximumNumberOfIterations;
00207   unsigned int m_MaximumNumberOfEvaluations;
00208   unsigned int m_MaximumNumberOfCorrections;
00209 
00210   unsigned int m_CurrentIteration;
00211   double       m_InfinityNormOfProjectedGradient;
00212 };
00213 } // end namespace itk
00214 
00215 #endif
00216