1 #ifndef theplu_yat_utility_minimizer_ 2 #define theplu_yat_utility_minimizer_ 25 #include "Exception.h" 26 #include "yat_assert.h" 27 #include "univariable/f.h" 29 #include <gsl/gsl_min.h> 30 #include <gsl/gsl_errno.h> 60 unsigned int epochs(
void)
const;
68 virtual bool operator()(
const gsl_min_fminimizer*)=0;
80 Interval(
double epsabs,
double epsrel);
103 double operator()(FUNC& func,
double guess,
double min,
double max,
114 double operator()(FUNC& func,
double guess,
double min,
double max,
115 Stopper&& stopper,
unsigned int max_epochs);
123 Minimizer(
const gsl_min_fminimizer_type* t);
125 const gsl_min_fminimizer_type* type_;
130 std::unique_ptr<gsl_min_fminimizer, GslFree> solver_;
131 unsigned int epochs_;
144 return (*
this)(func, guess, min,
max, std::move(stopper), max_epochs);
151 unsigned int max_epochs)
153 gsl_function gsl_func;
154 gsl_func.function = univariable::f<FUNC>;
155 gsl_func.params = &func;
156 gsl_min_fminimizer_set(solver_.get(), &gsl_func, guess, min,
max);
158 int status = GSL_CONTINUE;
159 for (epochs_=0; epochs_<max_epochs && !stopper(solver_.get()); ++epochs_) {
160 status = gsl_min_fminimizer_iterate(solver_.get());
163 if (status == GSL_FAILURE)
165 if (status == GSL_EBADFUNC) {
166 std::ostringstream ss;
167 ss <<
"Minimizer: at x = " 168 << gsl_min_fminimizer_x_minimum(solver_.get());
174 return gsl_min_fminimizer_x_minimum(solver_.get());
Interval(double epsabs, double epsrel)
virtual bool operator()(const gsl_min_fminimizer *)=0
return true is search should stop
unsigned int epochs(void) const
Number of epochs (iterations) used in last minimisation.
Definition: Minimizer.h:73
Class for errors reported from underlying GSL calls.
Definition: Exception.h:102
The Department of Theoretical Physics namespace as we define it.
Definition: Minimizer.h:64
double operator()(FUNC &func, double guess, double min, double max, Stopper &&stopper)
Definition: Minimizer.h:140
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:699
Wrapper class around gsl_min_fminimizer in GSL.
Definition: Minimizer.h:48
bool operator()(const gsl_min_fminimizer *)
Minimizer(const Minimizer &)=delete
Copy is not allowed.
Minimizer & operator=(const Minimizer &)=delete
Assignment is not allowed.