00001
00002
00008 #if !defined(__numerical_CoordinateDescent_h__)
00009 #define __numerical_CoordinateDescent_h__
00010
00011
00012 #if defined(DEBUG_numerical) && !defined(DEBUG_CoordinateDescent)
00013 #define DEBUG_CoordinateDescent
00014 #endif
00015
00016 #ifdef DEBUG_CoordinateDescent
00017
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
00043
00044
00045 typedef Opt<N,Function,T,Point> base_type;
00046
00047 public:
00048
00049
00050
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
00066
00067
00068
00069 number_type _initial_step_size;
00070
00071
00072 number_type _final_step_size;
00073
00074
00075 number_type _step_size_reduction_factor;
00076
00077
00078
00079
00080
00081
00082 int _step_limit;
00083
00084
00085 number_type _step_size;
00086
00087
00088
00089
00090
00091
00092 CoordinateDescent();
00093
00094
00095 CoordinateDescent( const CoordinateDescent& );
00096
00097
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
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
00213
00214
00215
00216 number_type
00217 step_size_reduction_factor() const
00218 {
00219 return _step_size_reduction_factor;
00220 }
00221
00222
00223
00225
00226
00227
00228
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
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
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 bool
00308 descent_direction( point_type& x, number_type& value, point_type& delta );
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
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