Bayeux  3.4.1
Core Foundation library for SuperNEMO
multidimensional_minimization.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_MULTIDIMENSIONAL_MINIMIZATION_H
4 #define MYGSL_MULTIDIMENSIONAL_MINIMIZATION_H 1
5 
6 // Standard library:
7 #include <string>
8 
9 // Third party:
10 // - GSL:
11 #include <gsl/gsl_multimin.h>
12 #include <gsl/gsl_vector.h>
13 #include <gsl/gsl_deriv.h>
14 
15 // This project:
16 #include <datatools/logger.h>
17 #include <mygsl/error.h>
18 #include <mygsl/i_unary_function.h>
20 
21 namespace mygsl {
22 
26  {
27  public:
28 
29  static const double DEFAULT_OUT_OF_LIMIT_SLOPE;
30 
31  int init_params_values ();
32 
33  void set_numeric_eval_df (bool = true);
34 
35  bool is_numeric_eval_df () const;
36 
37  double get_out_of_limit_slope () const;
38 
39  int eval_f (const double * x_ , double & f_);
40 
41  int eval_df (const double * x_ , double * gradient_);
42 
43  int eval_fdf (const double * x_ ,
44  double & f_ ,
45  double * gradient_);
46 
47  void to_double_star (double * pars_ ,
48  size_t dimension_) const;
49 
50  void from_double_star (const double * pars_ ,
51  size_t dimension_);
52 
54  bool use_numeric_eval_ = false);
55 
57 
60  {
61  public:
62 
63  func_eval_f_param(int free_param_index_,
65  protected:
66 
67  virtual double _eval(double x_) const;
68 
69  public:
70 
73 
74  };
75 
76  static double func_eval_f_MR(double x_, void * params_);
77 
78  void plot_f(const std::string & prefix_, int mode_ = 0) const;
79 
80  protected:
81 
82  // you must provide this method:
83  virtual int _eval_f (double & f_) = 0;
84 
85  // you may provide this method;
86  // if not, the '_numerical_eval_df_MR_' method will be used in place:
87  virtual int _eval_df (double * gradient_);
88 
89  private:
90 
91  int _eval_f_MR_(double & f_);
92  int _eval_df_MR_(double * gradient_);
93  int _numerical_eval_df_MR_(double * gradient_);
94 
95  private:
96 
97  bool _numeric_eval_df_;
98  double _out_of_limit_slope_;
99 
100  };
101 
104  {
105  public:
106 
107  static const size_t DEFAULT_MAX_ITER;
108  static const size_t DEFAULT_MODULO_ITER;
109  static const double DEFAULT_EPSABS;
110 
111  static double f(const gsl_vector * v_, void * params_);
112 
113  static void df(const gsl_vector * v_, void * params_, gsl_vector * gradient_);
114 
115  static void fdf(const gsl_vector * v_, void * params_, double * f_, gsl_vector * gradient_);
116 
117  static bool name_is_valid(const std::string & name_);
118 
119  enum mode_t {
120  MODE_FDF = 0,
121  MODE_F = 1
122  };
123 
124  enum stopping_t {
127  };
128 
130  {
131 
132  public:
133 
134  virtual void action (int status_ ,
135  size_t iter_ ,
136  double * x_ ,
137  size_t dim_ ,
138  double f_) = 0;
139 
140  void operator () (int status_ ,
141  size_t iter_ ,
142  double * x_ ,
143  size_t dim_ ,
144  double f_)
145  {
146  action (status_, iter_, x_, dim_, f_);
147  }
148 
149  };
150 
152  : public at_step_action
153  {
154  virtual void action (int status_ ,
155  size_t iter_ ,
156  double * x_ ,
157  size_t dim_ ,
158  double f_);
159  };
160 
162 
163  public:
164 
166 
167  private:
168 
169  int _mode_;
170  const gsl_multimin_fdfminimizer_type * _algo_fdf_;
171  const gsl_multimin_fminimizer_type * _algo_f_;
172  gsl_multimin_fdfminimizer * _fdfmin_;
173  gsl_multimin_fminimizer * _fmin_;
174  gsl_multimin_function _f_;
175  gsl_multimin_function_fdf _fdf_;
176  gsl_vector * _x_;
177  gsl_vector * _ss_;
179 
180  double _fdf_step_size_;
181  double _fdf_tol_;
182  size_t _max_iter_;
183  size_t _n_iter_;
184  size_t _modulo_iter_;
185 
186  double _fval_;
187  int _stopping_;
188  double _epsabs_;
189 
190  // hook step function:
191  at_step_action * _at_step_action_;
192 
193  void _init_algorithm_ (const std::string & name_);
194 
195  void _set_mode_ (int mode_);
196 
197  public:
198 
199  static void print_types (std::ostream &);
200 
201  void set_max_iter (size_t max_);
202 
203  void set_modulo_iter (size_t modulo_);
204 
205  size_t get_n_iter () const;
206 
207  size_t get_modulo_iter () const;
208 
209  size_t get_max_iter () const;
210 
211  double get_epsabs () const;
212 
213  double get_fval () const;
214 
215  void unset_step_action ();
216 
217  void set_default_step_action ();
218 
219  void set_step_action (at_step_action & asd_);
220 
221  std::string get_name () const;
222 
223  void init (const std::string & name_ ,
225 
226  void reset ();
227 
229 
231 
232  protected:
233 
234  void _at_step_hook (int status_ ,
235  size_t iter_ ,
236  double * x_ ,
237  size_t dim_ ,
238  double f_);
239 
240  public:
241 
242  int minimize (double epsabs_);
243 
244  void devel_dump_x () const;
245 
246  };
247 
248 } // namespace mygsl
249 
250 #endif // MYGSL_MULTIDIMENSIONAL_MINIMIZATION_H
251 
252 // Local Variables:
253 // mode: c++
254 // coding: utf-8
255 // End:
static void df(const gsl_vector *v_, void *params_, gsl_vector *gradient_)
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
System for multidimensional minimization algorithm.
Definition: multidimensional_minimization.h:24
static bool name_is_valid(const std::string &name_)
void to_double_star(double *pars_, size_t dimension_) const
void set_step_action(at_step_action &asd_)
static void fdf(const gsl_vector *v_, void *params_, double *f_, gsl_vector *gradient_)
int eval_f(const double *x_, double &f_)
datatools::logger::priority logging
Definition: multidimensional_minimization.h:165
static default_step_action __default_step_action
Definition: multidimensional_minimization.h:161
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
static double f(const gsl_vector *v_, void *params_)
virtual void action(int status_, size_t iter_, double *x_, size_t dim_, double f_)=0
static const size_t DEFAULT_MODULO_ITER
Definition: multidimensional_minimization.h:108
Definition: multidimensional_minimization.h:121
virtual void action(int status_, size_t iter_, double *x_, size_t dim_, double f_)
virtual double _eval(double x_) const
The function evaluation abstract method.
Definition: multidimensional_minimization.h:129
void operator()(int status_, size_t iter_, double *x_, size_t dim_, double f_)
Definition: multidimensional_minimization.h:140
stopping_t
Definition: multidimensional_minimization.h:124
void plot_f(const std::string &prefix_, int mode_=0) const
int eval_df(const double *x_, double *gradient_)
multidimensional_minimization_system(double slope_=DEFAULT_OUT_OF_LIMIT_SLOPE, bool use_numeric_eval_=false)
static const size_t DEFAULT_MAX_ITER
Definition: multidimensional_minimization.h:107
multidimensional_minimization_system * sys
Definition: multidimensional_minimization.h:72
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
int eval_fdf(const double *x_, double &f_, double *gradient_)
static double func_eval_f_MR(double x_, void *params_)
func_eval_f_param(int free_param_index_, multidimensional_minimization_system &sys_)
Multidimensional minimization algorithm.
Definition: multidimensional_minimization.h:103
virtual int _eval_df(double *gradient_)
static void print_types(std::ostream &)
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
Definition: multidimensional_minimization.h:58
Definition: multidimensional_minimization.h:120
int free_param_index
Definition: multidimensional_minimization.h:71
Utilities for logging information.
void from_double_star(const double *pars_, size_t dimension_)
Definition: multidimensional_minimization.h:125
void init(const std::string &name_, multidimensional_minimization_system &ms_)
void set_modulo_iter(size_t modulo_)
mode_t
Definition: multidimensional_minimization.h:119
static const double DEFAULT_EPSABS
Definition: multidimensional_minimization.h:109
void _at_step_hook(int status_, size_t iter_, double *x_, size_t dim_, double f_)
Definition: multidimensional_minimization.h:151
static const double DEFAULT_OUT_OF_LIMIT_SLOPE
Definition: multidimensional_minimization.h:29
Definition: multidimensional_minimization.h:126
System with several parameters.
Definition: multiparameter_system.h:16