IT++ Logo
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#include <itpp/itexports.h>
37
38namespace itpp
39{
40
46
47
50
72class ITPP_EXPORT Newton_Search
73{
74public:
79
81 void set_function(double(*function)(const vec&));
83 void set_gradient(vec(*gradient)(const vec&));
85 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
86
88 void set_start_point(const vec &x, const mat &D);
89
91 void set_start_point(const vec &x);
92
94 vec get_solution();
95
97 bool search();
99 bool search(vec &xn);
101 bool search(const vec &x0, vec &xn);
102
104 void set_stop_values(double epsilon_1, double epsilon_2);
106 double get_epsilon_1() { return stop_epsilon_1; }
108 double get_epsilon_2() { return stop_epsilon_2; }
109
111 void set_max_evaluations(int value);
113 int get_max_evaluations() { return max_evaluations; }
114
116 void set_initial_stepsize(double value);
118 double get_initial_stepsize() { return initial_stepsize; }
119
121 void set_method(const Newton_Search_Method &method);
122
124 double get_function_value();
126 double get_stop_1();
128 double get_stop_2();
130 int get_no_iterations();
132 int get_no_function_evaluations();
133
135 void enable_trace() { trace = true; }
137 void disable_trace() { trace = false; }
138
145 void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues);
146
147private:
148 int n; // dimension of problem, size(x)
149 double(*f)(const vec&); // function to minimize
150 vec(*df_dx)(const vec&); // df/dx, gradient of f
151
152 // start variables
153 vec x_start;
154 mat D_start;
155
156 // solution variables
157 vec x_end;
158
159 // trace variables
160 Array<vec> x_values;
161 vec F_values, ng_values, Delta_values;
162
164
165 // Parameters
166 double initial_stepsize; // opts(1)
167 double stop_epsilon_1; // opts(2)
168 double stop_epsilon_2; // opt(3)
169 int max_evaluations; // opts(4)
170
171 // output parameters
172 int no_feval; // number of function evaluations
173 int no_iter; // number of iterations
174 double F, ng, nh; // function value, stop_1, stop_2 values at solution point
175
176 bool init, finished, trace;
177};
178
179
180
182enum Line_Search_Method {Soft, Exact};
183
223class ITPP_EXPORT Line_Search
224{
225public:
227 Line_Search();
230
232 void set_function(double(*function)(const vec&));
234 void set_gradient(vec(*gradient)(const vec&));
236 void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
237
239 void set_start_point(const vec &x, double F, const vec &g, const vec &h);
240
242 void get_solution(vec &xn, double &Fn, vec &gn);
243
245 bool search();
247 bool search(vec &xn, double &Fn, vec &gn);
249 bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn,
250 double &Fn, vec &gn);
251
252
254 double get_alpha();
256 double get_slope_ratio();
258 int get_no_function_evaluations();
259
260
262 void set_stop_values(double rho, double beta);
264 double get_rho() { return stop_rho; }
266 double get_beta() { return stop_beta; }
267
269 void set_max_iterations(int value);
271 int get_max_iterations() { return max_iterations; }
272
274 void set_max_stepsize(double value);
276 double get_max_stepsize() { return max_stepsize; }
277
279 void set_method(const Line_Search_Method &method);
280
282 void enable_trace() { trace = true; }
284 void disable_trace() { trace = false; }
285
291 void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
292
293private:
294 int n; // dimension of problem, size(x)
295 double(*f)(const vec&); // function to minimize
296 vec(*df_dx)(const vec&); // df/dx, gradient of f
297
298 // start variables
299 vec x_start, g_start, h_start;
300 double F_start;
301
302 // solution variables
303 vec x_end, g_end;
304 double F_end;
305
306 // trace variables
307 vec alpha_values, F_values, dF_values;
308
309 bool init; // true if functions and starting points are set
310 bool finished; // true if functions and starting points are set
311 bool trace; // true if trace is enabled
312
313 // Parameters
314 Line_Search_Method method;
315 double stop_rho; // opts(2)
316 double stop_beta; // opts(3)
317 int max_iterations; // opts(4)
318 double max_stepsize; // opts(5)
319
320 // output parameters
321 double alpha; // end value of alpha, info(1)
322 double slope_ratio; // slope ratio at xn, info(2)
323 int no_feval; // info(3)
324};
325
336ITPP_EXPORT vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
337
339
340} // namespace itpp
341
342#endif // #ifndef NEWTON_SEARCH_H
Definition of Array class (container)
Import/Export definitions for some templates defined in base folder.
General array class.
Definition factory.h:40
double get_max_stepsize()
Return max number of iterations.
~Line_Search()
Destructor.
void set_functions(double(*function)(const vec &), vec(*gradient)(const vec &))
Set both function and gradient function pointers.
void disable_trace()
disable trace
double get_rho()
Return stop value rho.
void enable_trace()
enable trace mode
int get_max_iterations()
Return max number of iterations.
double get_beta()
Return stop value beta.
Newton Search.
void set_stop_values(double epsilon_1, double epsilon_2)
Set stop criterion values.
double get_epsilon_1()
Return stop value rho.
~Newton_Search()
Destructor.
double get_initial_stepsize()
Return max number of iterations.
void set_initial_stepsize(double value)
Set max stepsize.
void disable_trace()
disable trace
void set_functions(double(*function)(const vec &), vec(*gradient)(const vec &))
Set both function and gradient function pointers.
void set_max_evaluations(int value)
Set max number of function evaluations.
void enable_trace()
enable trace mode
int get_max_evaluations()
Return max number of function evaluations.
void set_method(const Newton_Search_Method &method)
Set Line search method.
double get_epsilon_2()
Return stop value beta.
T trace(const Mat< T > &m)
The trace of the matrix m, i.e. the sum of the diagonal elements.
Definition matfunc.h:762
itpp namespace
Definition itmex.h:37
Newton_Search_Method
Newton Search method.
Line_Search_Method
Line Search method.
vec fminunc(double(*function)(const vec &), vec(*gradient)(const vec &), const vec &x0)
Unconstrained minimization.
Templated Vector Class Definitions.
SourceForge Logo

Generated on Mon Apr 7 2025 07:53:18 for IT++ by Doxygen 1.11.0