IT++ Logo Newcom Logo

newton_search.h

Go to the documentation of this file.
00001 
00033 #ifndef NEWTON_SEARCH_H
00034 #define NEWTON_SEARCH_H
00035 
00036 #include <itpp/itconfig.h>
00037 #include <itpp/base/vec.h>
00038 #include <itpp/base/array.h>
00039 #include <limits>
00040 
00041 
00042 namespace itpp {
00043 
00049 
00050   enum Newton_Search_Method {BFGS};
00051 
00073   class Newton_Search {
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 
00181   enum Line_Search_Method {Soft, Exact};
00182 
00222   class Line_Search {
00223   public:
00225     Line_Search();
00227     ~Line_Search() {};
00228 
00230     void set_function(double(*function)(const vec&));
00232     void set_gradient(vec(*gradient)(const vec&));
00234     void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
00235 
00237     void set_start_point(const vec &x, double F, const vec &g, const vec &h);
00238 
00240     void get_solution(vec &xn, double &Fn, vec &gn);
00241 
00243     bool search();
00245     bool search(vec &xn, double &Fn, vec &gn);
00247     bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn, 
00248                 double &Fn, vec &gn);
00249 
00250 
00252     double get_alpha();
00254     double get_slope_ratio();
00256     int get_no_function_evaluations();
00257 
00258 
00260     void set_stop_values(double rho, double beta);
00262     double get_rho() { return stop_rho; }
00264     double get_beta() { return stop_beta; }
00265 
00267     void set_max_iterations(int value);
00269     int get_max_iterations() { return max_iterations; }
00270 
00272     void set_max_stepsize(double value);
00274     double get_max_stepsize() { return max_stepsize; }
00275 
00277     void set_method(const Line_Search_Method &method);
00278 
00280     void enable_trace() { trace = true; }
00282     void disable_trace() { trace = false; }
00283 
00289     void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
00290 
00291   private:
00292     int n; // dimension of problem, size(x)
00293     double (*f)(const vec&); // function to minimize
00294     vec (*df_dx)(const vec&); // df/dx, gradient of f
00295 
00296     // start variables
00297     vec x_start, g_start, h_start;
00298     double F_start;
00299 
00300     // solution variables
00301     vec x_end, g_end;
00302     double F_end;
00303 
00304     // trace variables
00305     vec alpha_values, F_values, dF_values;
00306 
00307     bool init; // true if functions and starting points are set
00308     bool finished; // true if functions and starting points are set
00309     bool trace; // true if trace is enabled
00310 
00311     // Parameters
00312     Line_Search_Method method;
00313     double stop_rho; // opts(2)
00314     double stop_beta; // opts(3)
00315     int max_iterations; // opts(4)
00316     double max_stepsize; // opts(5)
00317 
00318     // output parameters
00319     double alpha; // end value of alpha, info(1)
00320     double slope_ratio; // slope ratio at xn, info(2)
00321     int no_feval; // info(3)
00322   };
00323 
00334   vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
00335 
00337   
00338 } // namespace itpp
00339 
00340 #endif // #ifndef NEWTON_SEARCH_H
SourceForge Logo

Generated on Thu Apr 19 14:18:29 2007 for IT++ by Doxygen 1.5.1