vtf-logo

CoordinateDescent.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__numerical_CoordinateDescent_h__)
00009 #define __numerical_CoordinateDescent_h__
00010 
00011 // If we are debugging the whole numerical package.
00012 #if defined(DEBUG_numerical) && !defined(DEBUG_CoordinateDescent)
00013 #define DEBUG_CoordinateDescent
00014 #endif
00015 
00016 #ifdef DEBUG_CoordinateDescent
00017 // Debug the base class.
00018 #ifndef DEBUG_Opt
00019 #define DEBUG_Opt
00020 #endif
00021 #endif
00022 
00023 #include "Opt.h"
00024 
00025 BEGIN_NAMESPACE_NUMERICAL
00026 
00028 
00034 template <int N, class Function, typename T = typename Function::result_type,
00035           typename Point = typename Function::argument_type>
00036 class CoordinateDescent :
00037   public Opt<N,Function,T,Point>
00038 {
00039 private:
00040 
00041   // 
00042   // Private types
00043   //
00044 
00045   typedef Opt<N,Function,T,Point> base_type;
00046 
00047 public:
00048 
00049   //
00050   // Public types.
00051   //
00052   
00054   typedef typename base_type::function_type function_type;
00055 
00057   typedef typename base_type::number_type number_type;
00058 
00060   typedef typename base_type::point_type point_type;
00061 
00062 private:
00063 
00064   //
00065   // Member data that the user can set.
00066   //
00067 
00068   // The initial step size.
00069   number_type _initial_step_size;
00070 
00071   // The stepsize at which to halt optimization.
00072   number_type _final_step_size;
00073 
00074   // The stepsize reduction factor.
00075   number_type _step_size_reduction_factor;
00076 
00077   //
00078   // Other member data.
00079   //
00080 
00081   // The number of steps taken before the step size is increased.
00082   int _step_limit;
00083 
00084   // The step size.
00085   number_type _step_size;
00086 
00087   //
00088   // Not implemented.
00089   //
00090   
00091   // Default constructor not implemented.
00092   CoordinateDescent();
00093 
00094   // Copy constructor not implemented.
00095   CoordinateDescent( const CoordinateDescent& );
00096 
00097   // Assignment operator not implemented.
00098   CoordinateDescent&
00099   operator=( const CoordinateDescent& );
00100 
00101 public:
00102 
00103   //--------------------------------------------------------------------------
00108   // @{
00109 
00111   CoordinateDescent( const function_type& function, 
00112                      const number_type initial_step_size = 
00113                      std::pow( std::numeric_limits<number_type>::epsilon(), 
00114                                0.25 ),
00115                      const number_type final_step_size = 
00116                      std::sqrt( std::numeric_limits<number_type>::epsilon() ),
00117                      const int max_function_calls = 10000 );
00118 
00120   virtual
00121   ~CoordinateDescent()
00122   {}
00123 
00124   // @}
00125   //--------------------------------------------------------------------------
00127   // @{
00128 
00130 
00137   bool 
00138   find_minimum( point_type& x, number_type& value, int& num_steps );
00139 
00141 
00146   bool 
00147   find_minimum( point_type& x, number_type& value )
00148   {
00149     int num_steps;
00150     return find_minimum( x, value, num_steps );
00151   }
00152 
00154 
00160   bool 
00161   find_minimum( point_type& x, int& num_steps )
00162   {
00163     number_type value;
00164     return find_minimum( x, value, num_steps );
00165   }
00166 
00168 
00172   bool 
00173   find_minimum( point_type& x )
00174   {
00175     int num_steps;
00176     number_type value;
00177     return find_minimum( x, value, num_steps );
00178   }
00179 
00180   // @}
00181   //--------------------------------------------------------------------------
00183   // @{
00184 
00185   //
00186   // Inherited from Opt.
00187   //
00188 
00190   static
00191   int
00192   dimension()
00193   {
00194     return base_type::dimension();
00195   }
00196 
00198   const function_type&
00199   function() const
00200   {
00201     return base_type::function();
00202   }
00203 
00205   int
00206   num_function_calls() const
00207   {
00208     return base_type::num_function_calls();
00209   }
00210 
00211   //
00212   // New.
00213   //
00214 
00215   // Return the stepsize reduction factor.
00216   number_type 
00217   step_size_reduction_factor() const
00218   {
00219     return _step_size_reduction_factor;
00220   }
00221   
00222   // @}
00223   //--------------------------------------------------------------------------
00225   // @{
00226 
00227   //
00228   // Inherited from Opt
00229   //
00230 
00232   void
00233   set_max_function_calls( const int max_function_calls )
00234   {
00235     base_type::set_max_function_calls( max_function_calls );
00236   }
00237 
00239   void
00240   reset_num_function_calls()
00241   {
00242     base_type::reset_num_function_calls();
00243   }
00244 
00245   //
00246   // New.
00247   //
00248   
00250   void
00251   set_initial_step_size( const number_type initial_step_size )
00252   {
00253     _initial_step_size = initial_step_size;
00254   }
00255 
00257   void
00258   set_final_step_size( const number_type final_step_size )
00259   {
00260     _final_step_size = final_step_size;
00261   }
00262 
00264   void
00265   set_step_size_reduction_factor( const number_type 
00266                                   step_size_reduction_factor )
00267   {
00268     _step_size_reduction_factor = step_size_reduction_factor;
00269   }
00270 
00271   // @}
00272 
00273 protected:
00274 
00275   //--------------------------------------------------------------------------
00279   // @{
00280 
00282 
00285   number_type
00286   evaluate_function( const point_type& x )
00287   {
00288     return base_type::evaluate_function( x );
00289   }
00290 
00291   // @}
00292 
00293 private:
00294 
00295   // Find a descent direction by moving in the coordinate directions.
00296   /*
00297     \param x is the starting point.  It will be set to the new position 
00298     found by the search.
00299     \param value is initially equal to _function( x ).  It will be set to 
00300     the value of the objective function at the new position.
00301     \param delta will be set to the difference between the new and old 
00302     position.
00303 
00304     \return Return true if the search takes one or more successful steps.  
00305     Otherwise return false.
00306   */
00307   bool
00308   descent_direction( point_type& x, number_type& value, point_type& delta );
00309 
00310   // Search in the specified coordinate and direction.
00311   /*
00312     \param x is the starting point.  It will be set to the new position 
00313     found by the search.
00314     \param value is initially equal to _function( x ).  It will be set to 
00315     the value of the objective function at the new position.
00316     \param delta will be set to the difference between the new and old 
00317     position.
00318     \param i is the coordinate in which to search.
00319     \param sign is the direction to search (1 or -1).
00320 
00321     \return Return true if the search takes one or more successful steps.  
00322     Otherwise return false.
00323   */
00324   bool
00325   coordinate_search( point_type& x, number_type& value, point_type& delta, 
00326                      const int i, const int sign );
00327 };
00328 
00329 END_NAMESPACE_NUMERICAL
00330 
00331 #define __CoordinateDescent_ipp__
00332 #include "CoordinateDescent.ipp"
00333 #undef __CoordinateDescent_ipp__
00334 
00335 #endif

Generated on Fri Aug 24 12:56:05 2007 for Numerical Algorithms Package by  doxygen 1.4.7