| 1 | #ifndef _NEWTON_H | ||
| 2 | #define _NEWTON_H | ||
| 3 | |||
| 4 | class function | ||
| 5 | { | ||
| 6 | public: | ||
| 7 | virtual double fun(double *w) = 0 ; | ||
| 8 | virtual void grad(double *w, double *g) = 0 ; | ||
| 9 | virtual void Hv(double *s, double *Hs) = 0 ; | ||
| 10 | virtual int get_nr_variable(void) = 0 ; | ||
| 11 | virtual void get_diag_preconditioner(double *M) = 0 ; | ||
| 12 | 0 | virtual ~function(void){} | |
| 13 | |||
| 14 | // base implementation in newton.cpp | ||
| 15 | virtual double linesearch_and_update(double *w, double *s, double *f, double *g, double alpha); | ||
| 16 | }; | ||
| 17 | |||
| 18 | class NEWTON | ||
| 19 | { | ||
| 20 | public: | ||
| 21 | NEWTON(const function *fun_obj, double eps = 0.1, double eps_cg = 0.5, int max_iter = 1000); | ||
| 22 | ~NEWTON(); | ||
| 23 | |||
| 24 | void newton(double *w); | ||
| 25 | void set_print_string(void (*i_print) (const char *buf)); | ||
| 26 | |||
| 27 | private: | ||
| 28 | int pcg(double *g, double *M, double *s, double *r); | ||
| 29 | |||
| 30 | double eps; | ||
| 31 | double eps_cg; | ||
| 32 | int max_iter; | ||
| 33 | function *fun_obj; | ||
| 34 | void info(const char *fmt,...); | ||
| 35 | void (*newton_print_string)(const char *buf); | ||
| 36 | }; | ||
| 37 | #endif |