00001
00029 #ifndef NEWTON_SEARCH_H
00030 #define NEWTON_SEARCH_H
00031
00032 #include <itpp/base/vec.h>
00033 #include <itpp/base/array.h>
00034 #include <limits>
00035
00036
00037 namespace itpp
00038 {
00039
00045
00046
00048 enum Newton_Search_Method {BFGS};
00049
00071 class Newton_Search
00072 {
00073 public:
00075 Newton_Search();
00077 ~Newton_Search() {};
00078
00080 void set_function(double(*function)(const vec&));
00082 void set_gradient(vec(*gradient)(const vec&));
00084 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
00085
00087 void set_start_point(const vec &x, const mat &D);
00088
00090 void set_start_point(const vec &x);
00091
00093 vec get_solution();
00094
00096 bool search();
00098 bool search(vec &xn);
00100 bool search(const vec &x0, vec &xn);
00101
00103 void set_stop_values(double epsilon_1, double epsilon_2);
00105 double get_epsilon_1() { return stop_epsilon_1; }
00107 double get_epsilon_2() { return stop_epsilon_2; }
00108
00110 void set_max_evaluations(int value);
00112 int get_max_evaluations() { return max_evaluations; }
00113
00115 void set_initial_stepsize(double value);
00117 double get_initial_stepsize() { return initial_stepsize; }
00118
00120 void set_method(const Newton_Search_Method &method);
00121
00123 double get_function_value();
00125 double get_stop_1();
00127 double get_stop_2();
00129 int get_no_iterations();
00131 int get_no_function_evaluations();
00132
00134 void enable_trace() { trace = true; }
00136 void disable_trace() { trace = false; }
00137
00144 void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues);
00145
00146 private:
00147 int n;
00148 double(*f)(const vec&);
00149 vec(*df_dx)(const vec&);
00150
00151
00152 vec x_start;
00153 mat D_start;
00154
00155
00156 vec x_end;
00157
00158
00159 Array<vec> x_values;
00160 vec F_values, ng_values, Delta_values;
00161
00162 Newton_Search_Method method;
00163
00164
00165 double initial_stepsize;
00166 double stop_epsilon_1;
00167 double stop_epsilon_2;
00168 int max_evaluations;
00169
00170
00171 int no_feval;
00172 int no_iter;
00173 double F, ng, nh;
00174
00175 bool init, finished, trace;
00176 };
00177
00178
00179
00181 enum Line_Search_Method {Soft, Exact};
00182
00222 class Line_Search
00223 {
00224 public:
00226 Line_Search();
00228 ~Line_Search() {};
00229
00231 void set_function(double(*function)(const vec&));
00233 void set_gradient(vec(*gradient)(const vec&));
00235 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
00236
00238 void set_start_point(const vec &x, double F, const vec &g, const vec &h);
00239
00241 void get_solution(vec &xn, double &Fn, vec &gn);
00242
00244 bool search();
00246 bool search(vec &xn, double &Fn, vec &gn);
00248 bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn,
00249 double &Fn, vec &gn);
00250
00251
00253 double get_alpha();
00255 double get_slope_ratio();
00257 int get_no_function_evaluations();
00258
00259
00261 void set_stop_values(double rho, double beta);
00263 double get_rho() { return stop_rho; }
00265 double get_beta() { return stop_beta; }
00266
00268 void set_max_iterations(int value);
00270 int get_max_iterations() { return max_iterations; }
00271
00273 void set_max_stepsize(double value);
00275 double get_max_stepsize() { return max_stepsize; }
00276
00278 void set_method(const Line_Search_Method &method);
00279
00281 void enable_trace() { trace = true; }
00283 void disable_trace() { trace = false; }
00284
00290 void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
00291
00292 private:
00293 int n;
00294 double(*f)(const vec&);
00295 vec(*df_dx)(const vec&);
00296
00297
00298 vec x_start, g_start, h_start;
00299 double F_start;
00300
00301
00302 vec x_end, g_end;
00303 double F_end;
00304
00305
00306 vec alpha_values, F_values, dF_values;
00307
00308 bool init;
00309 bool finished;
00310 bool trace;
00311
00312
00313 Line_Search_Method method;
00314 double stop_rho;
00315 double stop_beta;
00316 int max_iterations;
00317 double max_stepsize;
00318
00319
00320 double alpha;
00321 double slope_ratio;
00322 int no_feval;
00323 };
00324
00335 vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
00336
00338
00339 }
00340
00341 #endif // #ifndef NEWTON_SEARCH_H