ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkGradientDescentOptimizerBasev4.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 __itkGradientDescentOptimizerBasev4_h
00019 #define __itkGradientDescentOptimizerBasev4_h
00020 
00021 #include "itkObjectToObjectOptimizerBase.h"
00022 #include "itkGradientDescentOptimizerBasev4ModifyGradientByScalesThreader.h"
00023 #include "itkGradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader.h"
00024 
00025 namespace itk
00026 {
00038 class ITK_EXPORT GradientDescentOptimizerBasev4
00039   : public ObjectToObjectOptimizerBase
00040 {
00041 public:
00043   typedef GradientDescentOptimizerBasev4 Self;
00044   typedef ObjectToObjectOptimizerBase    Superclass;
00045   typedef SmartPointer< Self >           Pointer;
00046   typedef SmartPointer< const Self >     ConstPointer;
00047 
00049   itkTypeMacro(GradientDescentOptimizerBasev4, ObjectToObjectOptimizerBase);
00050 
00052   typedef enum {
00053     MAXIMUM_NUMBER_OF_ITERATIONS,
00054     COSTFUNCTION_ERROR,
00055     UPDATE_PARAMETERS_ERROR,
00056     STEP_TOO_SMALL,
00057     QUASI_NEWTON_STEP_ERROR,
00058     CONVERGENCE_CHECKER_PASSED,
00059     OTHER_ERROR
00060     } StopConditionType;
00061 
00063   typedef std::string                            StopConditionReturnStringType;
00064 
00066   typedef std::ostringstream                     StopConditionDescriptionType;
00067 
00069   typedef Superclass::MetricType                    MetricType;
00070   typedef MetricType::Pointer                       MetricTypePointer;
00071 
00073   typedef MetricType::DerivativeType                DerivativeType;
00074 
00076   typedef Superclass::MeasureType                   MeasureType;
00077 
00079   typedef Superclass::InternalComputationValueType InternalComputationValueType;
00080 
00082   itkGetConstReferenceMacro( Gradient, DerivativeType );
00083 
00085   itkGetConstReferenceMacro(StopCondition, StopConditionType);
00086 
00088   itkSetMacro(NumberOfIterations, SizeValueType);
00089 
00091   itkGetConstReferenceMacro(NumberOfIterations, SizeValueType);
00092 
00094   itkGetConstMacro(CurrentIteration, SizeValueType);
00095 
00099   virtual void ResumeOptimization() = 0;
00100 
00103   virtual void StopOptimization(void);
00104 
00106   virtual const StopConditionReturnStringType GetStopConditionDescription() const;
00107 
00116   virtual void ModifyGradient();
00117 
00118 protected:
00119 
00121   GradientDescentOptimizerBasev4();
00122   virtual ~GradientDescentOptimizerBasev4();
00124 
00125   friend class GradientDescentOptimizerBasev4ModifyGradientByScalesThreader;
00126   friend class GradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader;
00127 
00128   typedef GradientDescentOptimizerBasev4ModifyGradientByScalesThreader::IndexRangeType IndexRangeType;
00129 
00130   GradientDescentOptimizerBasev4ModifyGradientByScalesThreader::Pointer       m_ModifyGradientByScalesThreader;
00131   GradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader::Pointer m_ModifyGradientByLearningRateThreader;
00132 
00136   virtual void EstimateLearningRate() = 0;
00137 
00143   virtual void ModifyGradientByScalesOverSubRange( const IndexRangeType& subrange ) = 0;
00144 
00150   virtual void ModifyGradientByLearningRateOverSubRange( const IndexRangeType& subrange ) = 0;
00151 
00152   /* Common variables for optimization control and reporting */
00153   bool                          m_Stop;
00154   StopConditionType             m_StopCondition;
00155   StopConditionDescriptionType  m_StopConditionDescription;
00156   SizeValueType                 m_NumberOfIterations;
00157   SizeValueType                 m_CurrentIteration;
00158 
00160   DerivativeType     m_Gradient;
00161   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00162 
00163 private:
00164   GradientDescentOptimizerBasev4( const Self & ); //purposely not implemented
00165   void operator=( const Self& ); //purposely not implemented
00166 
00167 };
00168 
00169 } // end namespace itk
00170 
00171 #endif
00172