IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
newton_search.h
Go to the documentation of this file.
1 
29 #ifndef NEWTON_SEARCH_H
30 #define NEWTON_SEARCH_H
31 
32 #include <itpp/base/vec.h>
33 #include <itpp/base/array.h>
34 #include <limits>
35 
36 
37 namespace itpp
38 {
39 
45 
46 
49 
72 {
73 public:
75  Newton_Search();
78 
80  void set_function(double(*function)(const vec&));
82  void set_gradient(vec(*gradient)(const vec&));
84  void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
85 
87  void set_start_point(const vec &x, const mat &D);
88 
90  void set_start_point(const vec &x);
91 
93  vec get_solution();
94 
96  bool search();
98  bool search(vec &xn);
100  bool search(const vec &x0, vec &xn);
101 
103  void set_stop_values(double epsilon_1, double epsilon_2);
105  double get_epsilon_1() { return stop_epsilon_1; }
107  double get_epsilon_2() { return stop_epsilon_2; }
108 
110  void set_max_evaluations(int value);
112  int get_max_evaluations() { return max_evaluations; }
113 
115  void set_initial_stepsize(double value);
117  double get_initial_stepsize() { return initial_stepsize; }
118 
120  void set_method(const Newton_Search_Method &method);
121 
123  double get_function_value();
125  double get_stop_1();
127  double get_stop_2();
129  int get_no_iterations();
132 
134  void enable_trace() { trace = true; }
136  void disable_trace() { trace = false; }
137 
144  void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues);
145 
146 private:
147  int n; // dimension of problem, size(x)
148  double(*f)(const vec&); // function to minimize
149  vec(*df_dx)(const vec&); // df/dx, gradient of f
150 
151  // start variables
152  vec x_start;
153  mat D_start;
154 
155  // solution variables
156  vec x_end;
157 
158  // trace variables
159  Array<vec> x_values;
160  vec F_values, ng_values, Delta_values;
161 
162  Newton_Search_Method method;
163 
164  // Parameters
165  double initial_stepsize; // opts(1)
166  double stop_epsilon_1; // opts(2)
167  double stop_epsilon_2; // opt(3)
168  int max_evaluations; // opts(4)
169 
170  // output parameters
171  int no_feval; // number of function evaluations
172  int no_iter; // number of iterations
173  double F, ng, nh; // function value, stop_1, stop_2 values at solution point
174 
175  bool init, finished, trace;
176 };
177 
178 
179 
181 enum Line_Search_Method {Soft, Exact};
182 
223 {
224 public:
226  Line_Search();
229 
231  void set_function(double(*function)(const vec&));
233  void set_gradient(vec(*gradient)(const vec&));
235  void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
236 
238  void set_start_point(const vec &x, double F, const vec &g, const vec &h);
239 
241  void get_solution(vec &xn, double &Fn, vec &gn);
242 
244  bool search();
246  bool search(vec &xn, double &Fn, vec &gn);
248  bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn,
249  double &Fn, vec &gn);
250 
251 
253  double get_alpha();
255  double get_slope_ratio();
258 
259 
261  void set_stop_values(double rho, double beta);
263  double get_rho() { return stop_rho; }
265  double get_beta() { return stop_beta; }
266 
268  void set_max_iterations(int value);
270  int get_max_iterations() { return max_iterations; }
271 
273  void set_max_stepsize(double value);
275  double get_max_stepsize() { return max_stepsize; }
276 
278  void set_method(const Line_Search_Method &method);
279 
281  void enable_trace() { trace = true; }
283  void disable_trace() { trace = false; }
284 
290  void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
291 
292 private:
293  int n; // dimension of problem, size(x)
294  double(*f)(const vec&); // function to minimize
295  vec(*df_dx)(const vec&); // df/dx, gradient of f
296 
297  // start variables
298  vec x_start, g_start, h_start;
299  double F_start;
300 
301  // solution variables
302  vec x_end, g_end;
303  double F_end;
304 
305  // trace variables
306  vec alpha_values, F_values, dF_values;
307 
308  bool init; // true if functions and starting points are set
309  bool finished; // true if functions and starting points are set
310  bool trace; // true if trace is enabled
311 
312  // Parameters
313  Line_Search_Method method;
314  double stop_rho; // opts(2)
315  double stop_beta; // opts(3)
316  int max_iterations; // opts(4)
317  double max_stepsize; // opts(5)
318 
319  // output parameters
320  double alpha; // end value of alpha, info(1)
321  double slope_ratio; // slope ratio at xn, info(2)
322  int no_feval; // info(3)
323 };
324 
335 vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
336 
338 
339 } // namespace itpp
340 
341 #endif // #ifndef NEWTON_SEARCH_H
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:13 for IT++ by Doxygen 1.8.1.2