00001 00030 #ifndef NEWTON_SEARCH_H 00031 #define NEWTON_SEARCH_H 00032 00033 #include <itpp/base/vec.h> 00034 #include <itpp/base/array.h> 00035 #include <limits> 00036 00037 00038 namespace itpp 00039 { 00040 00046 00047 00049 enum Newton_Search_Method {BFGS}; 00050 00072 class Newton_Search 00073 { 00074 public: 00076 Newton_Search(); 00078 ~Newton_Search() {}; 00079 00081 void set_function(double(*function)(const vec&)); 00083 void set_gradient(vec(*gradient)(const vec&)); 00085 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); } 00086 00088 void set_start_point(const vec &x, const mat &D); 00089 00091 void set_start_point(const vec &x); 00092 00094 vec get_solution(); 00095 00097 bool search(); 00099 bool search(vec &xn); 00101 bool search(const vec &x0, vec &xn); 00102 00104 void set_stop_values(double epsilon_1, double epsilon_2); 00106 double get_epsilon_1() { return stop_epsilon_1; } 00108 double get_epsilon_2() { return stop_epsilon_2; } 00109 00111 void set_max_evaluations(int value); 00113 int get_max_evaluations() { return max_evaluations; } 00114 00116 void set_initial_stepsize(double value); 00118 double get_initial_stepsize() { return initial_stepsize; } 00119 00121 void set_method(const Newton_Search_Method &method); 00122 00124 double get_function_value(); 00126 double get_stop_1(); 00128 double get_stop_2(); 00130 int get_no_iterations(); 00132 int get_no_function_evaluations(); 00133 00135 void enable_trace() { trace = true; } 00137 void disable_trace() { trace = false; } 00138 00145 void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues); 00146 00147 private: 00148 int n; // dimension of problem, size(x) 00149 double(*f)(const vec&); // function to minimize 00150 vec(*df_dx)(const vec&); // df/dx, gradient of f 00151 00152 // start variables 00153 vec x_start; 00154 mat D_start; 00155 00156 // solution variables 00157 vec x_end; 00158 00159 // trace variables 00160 Array<vec> x_values; 00161 vec F_values, ng_values, Delta_values; 00162 00163 Newton_Search_Method method; 00164 00165 // Parameters 00166 double initial_stepsize; // opts(1) 00167 double stop_epsilon_1; // opts(2) 00168 double stop_epsilon_2; // opt(3) 00169 int max_evaluations; // opts(4) 00170 00171 // output parameters 00172 int no_feval; // number of function evaluations 00173 int no_iter; // number of iterations 00174 double F, ng, nh; // function value, stop_1, stop_2 values at solution point 00175 00176 bool init, finished, trace; 00177 }; 00178 00179 00180 00182 enum Line_Search_Method {Soft, Exact}; 00183 00223 class Line_Search 00224 { 00225 public: 00227 Line_Search(); 00229 ~Line_Search() {}; 00230 00232 void set_function(double(*function)(const vec&)); 00234 void set_gradient(vec(*gradient)(const vec&)); 00236 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); } 00237 00239 void set_start_point(const vec &x, double F, const vec &g, const vec &h); 00240 00242 void get_solution(vec &xn, double &Fn, vec &gn); 00243 00245 bool search(); 00247 bool search(vec &xn, double &Fn, vec &gn); 00249 bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn, 00250 double &Fn, vec &gn); 00251 00252 00254 double get_alpha(); 00256 double get_slope_ratio(); 00258 int get_no_function_evaluations(); 00259 00260 00262 void set_stop_values(double rho, double beta); 00264 double get_rho() { return stop_rho; } 00266 double get_beta() { return stop_beta; } 00267 00269 void set_max_iterations(int value); 00271 int get_max_iterations() { return max_iterations; } 00272 00274 void set_max_stepsize(double value); 00276 double get_max_stepsize() { return max_stepsize; } 00277 00279 void set_method(const Line_Search_Method &method); 00280 00282 void enable_trace() { trace = true; } 00284 void disable_trace() { trace = false; } 00285 00291 void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues); 00292 00293 private: 00294 int n; // dimension of problem, size(x) 00295 double(*f)(const vec&); // function to minimize 00296 vec(*df_dx)(const vec&); // df/dx, gradient of f 00297 00298 // start variables 00299 vec x_start, g_start, h_start; 00300 double F_start; 00301 00302 // solution variables 00303 vec x_end, g_end; 00304 double F_end; 00305 00306 // trace variables 00307 vec alpha_values, F_values, dF_values; 00308 00309 bool init; // true if functions and starting points are set 00310 bool finished; // true if functions and starting points are set 00311 bool trace; // true if trace is enabled 00312 00313 // Parameters 00314 Line_Search_Method method; 00315 double stop_rho; // opts(2) 00316 double stop_beta; // opts(3) 00317 int max_iterations; // opts(4) 00318 double max_stepsize; // opts(5) 00319 00320 // output parameters 00321 double alpha; // end value of alpha, info(1) 00322 double slope_ratio; // slope ratio at xn, info(2) 00323 int no_feval; // info(3) 00324 }; 00325 00336 vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0); 00337 00339 00340 } // namespace itpp 00341 00342 #endif // #ifndef NEWTON_SEARCH_H
Generated on Tue Nov 23 08:45:11 2010 for IT++ by Doxygen 1.6.1