newton_search.h
Go to the documentation of this file.
#ifndef NEWTON_SEARCH_H
#define NEWTON_SEARCH_H
#include <itpp/base/vec.h>
#include <itpp/base/array.h>
#include <limits>
#include <itpp/itexports.h>
#include <itpp/base/base_exports.h>
namespace itpp
{
enum Newton_Search_Method {BFGS};
class ITPP_EXPORT Newton_Search
{
public:
Newton_Search();
~Newton_Search() {};
void set_function(double(*function)(const vec&));
void set_gradient(vec(*gradient)(const vec&));
void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
void set_start_point(const vec &x, const mat &D);
void set_start_point(const vec &x);
vec get_solution();
bool search();
bool search(vec &xn);
bool search(const vec &x0, vec &xn);
void set_stop_values(double epsilon_1, double epsilon_2);
double get_epsilon_1() { return stop_epsilon_1; }
double get_epsilon_2() { return stop_epsilon_2; }
void set_max_evaluations(int value);
int get_max_evaluations() { return max_evaluations; }
void set_initial_stepsize(double value);
double get_initial_stepsize() { return initial_stepsize; }
void set_method(const Newton_Search_Method &method);
double get_function_value();
double get_stop_1();
double get_stop_2();
int get_no_iterations();
int get_no_function_evaluations();
void enable_trace() { trace = true; }
void disable_trace() { trace = false; }
void get_trace(Array<vec> & xvalues, vec &Fvalues, vec &ngvalues, vec &dvalues);
private:
int n; // dimension of problem, size(x)
double(*f)(const vec&); // function to minimize
vec(*df_dx)(const vec&); // df/dx, gradient of f
// start variables
vec x_start;
mat D_start;
// solution variables
vec x_end;
// trace variables
Array<vec> x_values;
vec F_values, ng_values, Delta_values;
Newton_Search_Method method;
// Parameters
double initial_stepsize; // opts(1)
double stop_epsilon_1; // opts(2)
double stop_epsilon_2; // opt(3)
int max_evaluations; // opts(4)
// output parameters
int no_feval; // number of function evaluations
int no_iter; // number of iterations
double F, ng, nh; // function value, stop_1, stop_2 values at solution point
bool init, finished, trace;
};
enum Line_Search_Method {Soft, Exact};
class ITPP_EXPORT Line_Search
{
public:
Line_Search();
~Line_Search() {};
void set_function(double(*function)(const vec&));
void set_gradient(vec(*gradient)(const vec&));
void set_functions(double(*function)(const vec&), vec(*gradient)(const vec&)) { set_function(function); set_gradient(gradient); }
void set_start_point(const vec &x, double F, const vec &g, const vec &h);
void get_solution(vec &xn, double &Fn, vec &gn);
bool search();
bool search(vec &xn, double &Fn, vec &gn);
bool search(const vec &x, double F, const vec &g, const vec &h, vec &xn,
double &Fn, vec &gn);
double get_alpha();
double get_slope_ratio();
int get_no_function_evaluations();
void set_stop_values(double rho, double beta);
double get_rho() { return stop_rho; }
double get_beta() { return stop_beta; }
void set_max_iterations(int value);
int get_max_iterations() { return max_iterations; }
void set_max_stepsize(double value);
double get_max_stepsize() { return max_stepsize; }
void set_method(const Line_Search_Method &method);
void enable_trace() { trace = true; }
void disable_trace() { trace = false; }
void get_trace(vec &alphavalues, vec &Fvalues, vec &dFvalues);
private:
int n; // dimension of problem, size(x)
double(*f)(const vec&); // function to minimize
vec(*df_dx)(const vec&); // df/dx, gradient of f
// start variables
vec x_start, g_start, h_start;
double F_start;
// solution variables
vec x_end, g_end;
double F_end;
// trace variables
vec alpha_values, F_values, dF_values;
bool init; // true if functions and starting points are set
bool finished; // true if functions and starting points are set
bool trace; // true if trace is enabled
// Parameters
Line_Search_Method method;
double stop_rho; // opts(2)
double stop_beta; // opts(3)
int max_iterations; // opts(4)
double max_stepsize; // opts(5)
// output parameters
double alpha; // end value of alpha, info(1)
double slope_ratio; // slope ratio at xn, info(2)
int no_feval; // info(3)
};
ITPP_EXPORT vec fminunc(double(*function)(const vec&), vec(*gradient)(const vec&), const vec &x0);
} // namespace itpp
#endif // #ifndef NEWTON_SEARCH_H
array.h
Definition of Array class (container)
base_exports.h
Import/Export definitions for some templates defined in base folder.
itpp::Array
General array class.
Definition array.h:105
itpp::Line_Search
Line Search.
Definition newton_search.h:224
itpp::Line_Search::get_max_stepsize
double get_max_stepsize()
Return max number of iterations.
Definition newton_search.h:276
itpp::Line_Search::~Line_Search
~Line_Search()
Destructor.
Definition newton_search.h:229
itpp::Line_Search::set_functions
void set_functions(double(*function)(const vec &), vec(*gradient)(const vec &))
Set both function and gradient function pointers.
Definition newton_search.h:236
itpp::Line_Search::disable_trace
void disable_trace()
disable trace
Definition newton_search.h:284
itpp::Line_Search::get_rho
double get_rho()
Return stop value rho.
Definition newton_search.h:264
itpp::Line_Search::enable_trace
void enable_trace()
enable trace mode
Definition newton_search.h:282
itpp::Line_Search::get_max_iterations
int get_max_iterations()
Return max number of iterations.
Definition newton_search.h:271
itpp::Line_Search::get_beta
double get_beta()
Return stop value beta.
Definition newton_search.h:266
itpp::Newton_Search
Newton Search.
Definition newton_search.h:73
itpp::Newton_Search::set_stop_values
void set_stop_values(double epsilon_1, double epsilon_2)
Set stop criterion values.
itpp::Newton_Search::get_epsilon_1
double get_epsilon_1()
Return stop value rho.
Definition newton_search.h:106
itpp::Newton_Search::~Newton_Search
~Newton_Search()
Destructor.
Definition newton_search.h:78
itpp::Newton_Search::get_initial_stepsize
double get_initial_stepsize()
Return max number of iterations.
Definition newton_search.h:118
itpp::Newton_Search::set_initial_stepsize
void set_initial_stepsize(double value)
Set max stepsize.
itpp::Newton_Search::disable_trace
void disable_trace()
disable trace
Definition newton_search.h:137
itpp::Newton_Search::set_functions
void set_functions(double(*function)(const vec &), vec(*gradient)(const vec &))
Set both function and gradient function pointers.
Definition newton_search.h:85
itpp::Newton_Search::set_max_evaluations
void set_max_evaluations(int value)
Set max number of function evaluations.
itpp::Newton_Search::enable_trace
void enable_trace()
enable trace mode
Definition newton_search.h:135
itpp::Newton_Search::get_max_evaluations
int get_max_evaluations()
Return max number of function evaluations.
Definition newton_search.h:113
itpp::Newton_Search::set_method
void set_method(const Newton_Search_Method &method)
Set Line search method.
itpp::Newton_Search::get_epsilon_2
double get_epsilon_2()
Return stop value beta.
Definition newton_search.h:108
itpp::trace
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
itpp namespace
Definition itmex.h:37
itpp::Newton_Search_Method
Newton_Search_Method
Newton Search method.
Definition newton_search.h:49
itpp::Line_Search_Method
Line_Search_Method
Line Search method.
Definition newton_search.h:182
itpp::fminunc
vec fminunc(double(*function)(const vec &), vec(*gradient)(const vec &), const vec &x0)
Unconstrained minimization.
Definition newton_search.cpp:692
vec.h
Templated Vector Class Definitions.

Generated on Mon Apr 22 2024 09:45:27 for IT++ by Doxygen 1.9.8