Bayeux  3.4.1
Core Foundation library for SuperNEMO
one_dimensional_minimization.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_ONE_DIMENSIONAL_MINIMIZATION_H
4 #define MYGSL_ONE_DIMENSIONAL_MINIMIZATION_H 1
5 
6 // Standard library:
7 #include <algorithm>
8 #include <iostream>
9 #include <sstream>
10 #include <stdexcept>
11 #include <string>
12 #include <vector>
13 #include <cmath>
14 
15 // Third party:
16 // - GSL:
17 #include <gsl/gsl_min.h>
18 
19 // This project:
20 #include <mygsl/i_unary_function.h>
21 #include <mygsl/best_value.h>
22 
23 namespace mygsl {
24 
27  {
28  public:
29  static const std::string & goldensection_method_label();
30  static const std::string & brent_method_label();
31  static double default_epsabs();
32  static const size_t DEFAULT_MAX_ITER = 1000;
33 
35  {
36  public:
37 
38  virtual void action (int status_,
39  size_t iter_,
40  double a_,
41  double b_,
42  double c_) = 0;
43 
44  void operator () (int status_,
45  size_t iter_,
46  double a_,
47  double b_,
48  double c_);
49  };
50 
52  {
53  virtual void action (int status_,
54  size_t iter_,
55  double a_,
56  double b_,
57  double c_);
58  };
59 
60  public:
61 
62  void unset_step_action ();
63 
65 
66  void set_step_action (at_step_action & action_);
67 
68  const best_value & get_minimum_value () const;
69 
70  std::string get_name () const;
71 
72  void set_debug (bool debug_ = true);
73 
74  bool is_debug () const;
75 
76  size_t get_iter () const;
77 
78  size_t get_max_iter () const;
79 
80  double get_epsabs () const;
81 
82  bool is_converged () const;
83 
84  one_dimensional_minimization (bool debug_ = false);
85 
87 
88  void init (const i_unary_function & functor_,
89  const std::string & method_ = "");
90 
91  void initialize (const i_unary_function & functor_,
92  const std::string & method_ = "");
93 
94  void reset ();
95 
96  protected:
97 
98  void _at_step_hook (int status_,
99  size_t iter_,
100  double a_,
101  double b_,
102  double c_);
103 
104  public:
105 
106  int minimize (double a_,
107  double b_,
108  double m_,
109  double epsabs_);
110 
111  static double g_function (double x_, void * params_);
112 
113  static best_value minimize (const i_unary_function & sys_,
114  double a_,
115  double b_,
116  double m_,
117  double epsabs_,
118  const std::string & method_ = "");
119 
120  private:
121 
122  static default_step_action _default_step_action_;
123 
124  private:
125 
126  bool _debug_;
127  const gsl_min_fminimizer_type * _fminimizer_type_;
128  gsl_min_fminimizer * _fminimizer_;
129  int _status_;
130  gsl_function _function_;
131  best_value _minimum_value_;
132  size_t _iter_;
133  size_t _max_iter_;
134  double _epsabs_;
135  bool _converged_;
136  const i_unary_function * _functor_;
137 
138  // hook step function:
139  at_step_action * _at_step_action_;
140 
141  };
142 
143 } // namespace mygsl
144 
145 #endif // MYGSL_ONE_DIMENSIONAL_MINIMIZATION_H
146 
147 /* Local Variables: */
148 /* mode: c++ */
149 /* coding: utf-8 */
150 /* End: */
virtual void action(int status_, size_t iter_, double a_, double b_, double c_)
void operator()(int status_, size_t iter_, double a_, double b_, double c_)
static double g_function(double x_, void *params_)
void set_step_action(at_step_action &action_)
A data structure representing a numeric value and its associated error.
Definition: best_value.h:17
static const std::string & brent_method_label()
void init(const i_unary_function &functor_, const std::string &method_="")
Definition: one_dimensional_minimization.h:34
virtual void action(int status_, size_t iter_, double a_, double b_, double c_)=0
One dimensional minimization algorithm.
Definition: one_dimensional_minimization.h:26
const best_value & get_minimum_value() const
void set_debug(bool debug_=true)
int minimize(double a_, double b_, double m_, double epsabs_)
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
Definition: one_dimensional_minimization.h:51
static const std::string & goldensection_method_label()
void initialize(const i_unary_function &functor_, const std::string &method_="")
void _at_step_hook(int status_, size_t iter_, double a_, double b_, double c_)
one_dimensional_minimization(bool debug_=false)
static const size_t DEFAULT_MAX_ITER
Definition: one_dimensional_minimization.h:32