23 #ifndef O2SCL_MULTI_MIN_H
24 #define O2SCL_MULTI_MIN_H
30 #include <o2scl/multi_funct.h>
31 #include <o2scl/mm_funct.h>
32 #include <o2scl/string_conv.h>
34 #ifndef DOXYGEN_NO_O2NS
39 typedef std::function<int(size_t,boost::numeric::ublas::vector<double> &,
52 template<
class func_t,
class vec_t=boost::numeric::ublas::vector<
double> >
71 virtual int operator()(
size_t nv, vec_t &x, vec_t &g)=0;
73 #ifndef DOXYGEN_INTERNAL
120 fv1=(*this->
func)(nv,x);
122 for(
size_t i=0;i<nv;i++) {
128 fv2=(*this->
func)(nv,x);
165 #ifndef DOXYGEN_INTERNAL
225 virtual int mmin(
size_t nvar, vec_t &x,
double &fmin,
232 virtual int mmin_de(
size_t nvar, vec_t &x,
double &fmin,
233 func_t &func, dfunc_t &dfunc)
235 return mmin(nvar,x,fmin,func);
247 template<
class vec2_t>
249 double value,
double limit, std::string comment)
257 (*outs) << comment <<
" Iteration: " << iter << std::endl;
259 (*outs) <<
"x: " << std::endl;
260 for(i=0;i<((int)nv);i++) (*
outs) << x[i] <<
" ";
261 (*outs) << std::endl;
263 (*outs) <<
"y: " << y <<
" Val: " << value <<
" Lim: "
264 << limit << std::endl;
266 (*outs) <<
"Press a key and type enter to continue. ";
274 const char *
type() {
return "mmin_base"; }
307 #ifndef DOXYGEN_NO_O2NS
Class for automatically computing gradients [abstract base].
double epsmin
The minimum stepsize (default )
std::istream * ins
Stream for verbose input.
int set_verbose_stream(std::ostream &out, std::istream &in)
Set streams for verbose I/O.
std::ostream * outs
Stream for verbose output.
const char * type()
Return string denoting type ("mmin_base")
virtual int mmin(size_t nvar, vec_t &x, double &fmin, func_t &func)=0
Calculate the minimum min of func w.r.t. the array x of size nvar.
int verbose
Output control.
virtual int mmin_de(size_t nvar, vec_t &x, double &fmin, func_t &func, dfunc_t &dfunc)
Calculate the minimum min of func w.r.t. the array x of size nvar with gradient dfunc.
virtual int set_function(func_t &f)
Set the function to compute the gradient of.
bool err_nonconv
If true, call the error handler if the routine does not "converge".
Multidimensional minimization [abstract base].
int print_iter(size_t nv, vec2_t &x, double y, int iter, double value, double limit, std::string comment)
Print out iteration information.
double epsrel
The relative stepsize for finite-differencing (default )
Simple automatic computation of gradient by finite differencing.
int last_ntrial
The number of iterations for in the most recent minimization.
virtual int operator()(size_t nv, vec_t &x, vec_t &g)
Compute the gradient g at the point x.
func_t * func
A pointer to the user-specified function.
std::function< int(size_t, boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> grad_funct11
Array of multi-dimensional functions typedef.
double tol_abs
The independent variable tolerance.
double tol_rel
Function value tolerance.
virtual int operator()(size_t nv, vec_t &x, vec_t &g)=0
Compute the gradient g at the point x.
std::function< double(size_t, const boost::numeric::ublas::vector< double > &)> multi_funct11
Multi-dimensional function typedef.
int ntrial
Maximum number of iterations.