IT++ Logo

newton_search.h

Go to the documentation of this file.
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 
00045 
00046 
00048   enum Newton_Search_Method {BFGS};
00049 
00071   class Newton_Search {
00072   public:
00074     Newton_Search();
00076     ~Newton_Search() {};
00077 
00079     void set_function(double(*function)(const vec&));
00081     void set_gradient(vec(*gradient)(const vec&));
00083     void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
00084 
00086     void set_start_point(const vec &x, const mat &D);
00087 
00089     void set_start_point(const vec &x);
00090 
00092     vec get_solution();
00093 
00095     bool search();
00097     bool search(vec &xn);
00099     bool search(const vec &x0, vec &xn);
00100 
00102     void set_stop_values(double epsilon_1, double epsilon_2);
00104     double get_epsilon_1() { return stop_epsilon_1; }
00106     double get_epsilon_2() { return stop_epsilon_2; }
00107 
00109     void set_max_evaluations(int value);
00111     int get_max_evaluations() { return max_evaluations; }
00112 
00114     void set_initial_stepsize(double value);
00116     double get_initial_stepsize() { return initial_stepsize; }
00117 
00119     void set_method(const Newton_Search_Method &method);
00120 
00122     double get_function_value();
00124     double get_stop_1();
00126     double get_stop_2();
00128     int get_no_iterations();
00130     int get_no_function_evaluations();
00131 
00133     void enable_trace() { trace = true; }
00135     void disable_trace() { trace = false; }
00136 
00143     void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues);
00144 
00145   private:
00146     int n; // dimension of problem, size(x)
00147     double (*f)(const vec&); // function to minimize
00148     vec (*df_dx)(const vec&); // df/dx, gradient of f
00149 
00150     // start variables
00151     vec x_start;
00152     mat D_start;
00153 
00154     // solution variables
00155     vec x_end;
00156 
00157     // trace variables
00158     Array<vec> x_values;
00159     vec F_values, ng_values, Delta_values;
00160 
00161     Newton_Search_Method method;
00162 
00163     // Parameters
00164     double initial_stepsize; // opts(1)
00165     double stop_epsilon_1; // opts(2)
00166     double stop_epsilon_2; // opt(3)
00167     int max_evaluations; // opts(4)
00168 
00169     // output parameters
00170     int no_feval; // number of function evaluations
00171     int no_iter; // number of iterations
00172     double F, ng, nh; // function value, stop_1, stop_2 values at solution point
00173 
00174     bool init, finished, trace;
00175   };
00176 
00177 
00178 
00180   enum Line_Search_Method {Soft, Exact};
00181 
00221   class Line_Search {
00222   public:
00224     Line_Search();
00226     ~Line_Search() {};
00227 
00229     void set_function(double(*function)(const vec&));
00231     void set_gradient(vec(*gradient)(const vec&));
00233     void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
00234 
00236     void set_start_point(const vec &x, double F, const vec &g, const vec &h);
00237 
00239     void get_solution(vec &xn, double &Fn, vec &gn);
00240 
00242     bool search();
00244     bool search(vec &xn, double &Fn, vec &gn);
00246     bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn,
00247                 double &Fn, vec &gn);
00248 
00249 
00251     double get_alpha();
00253     double get_slope_ratio();
00255     int get_no_function_evaluations();
00256 
00257 
00259     void set_stop_values(double rho, double beta);
00261     double get_rho() { return stop_rho; }
00263     double get_beta() { return stop_beta; }
00264 
00266     void set_max_iterations(int value);
00268     int get_max_iterations() { return max_iterations; }
00269 
00271     void set_max_stepsize(double value);
00273     double get_max_stepsize() { return max_stepsize; }
00274 
00276     void set_method(const Line_Search_Method &method);
00277 
00279     void enable_trace() { trace = true; }
00281     void disable_trace() { trace = false; }
00282 
00288     void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
00289 
00290   private:
00291     int n; // dimension of problem, size(x)
00292     double (*f)(const vec&); // function to minimize
00293     vec (*df_dx)(const vec&); // df/dx, gradient of f
00294 
00295     // start variables
00296     vec x_start, g_start, h_start;
00297     double F_start;
00298 
00299     // solution variables
00300     vec x_end, g_end;
00301     double F_end;
00302 
00303     // trace variables
00304     vec alpha_values, F_values, dF_values;
00305 
00306     bool init; // true if functions and starting points are set
00307     bool finished; // true if functions and starting points are set
00308     bool trace; // true if trace is enabled
00309 
00310     // Parameters
00311     Line_Search_Method method;
00312     double stop_rho; // opts(2)
00313     double stop_beta; // opts(3)
00314     int max_iterations; // opts(4)
00315     double max_stepsize; // opts(5)
00316 
00317     // output parameters
00318     double alpha; // end value of alpha, info(1)
00319     double slope_ratio; // slope ratio at xn, info(2)
00320     int no_feval; // info(3)
00321   };
00322 
00333   vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
00334 
00336 
00337 } // namespace itpp
00338 
00339 #endif // #ifndef NEWTON_SEARCH_H
SourceForge Logo

Generated on Sat Apr 19 10:57:52 2008 for IT++ by Doxygen 1.5.5