23 #ifndef O2SCL_MULTI_MIN_H 24 #define O2SCL_MULTI_MIN_H 31 #include <o2scl/multi_funct.h> 32 #include <o2scl/mm_funct.h> 33 #include <o2scl/string_conv.h> 35 #ifndef DOXYGEN_NO_O2NS 40 typedef std::function<int(size_t,boost::numeric::ublas::vector<double> &,
53 template<
class func_t,
class vec_t=boost::numeric::ublas::vector<
double> >
72 virtual int operator()(
size_t nv, vec_t &x, vec_t &g)=0;
74 #ifndef DOXYGEN_INTERNAL 121 fv1=(*this->
func)(nv,x);
123 for(
size_t i=0;i<nv;i++) {
126 if (fabs(h)<=epsmin) h=epsrel;
129 fv2=(*this->
func)(nv,x);
166 #ifndef DOXYGEN_INTERNAL 226 virtual int mmin(
size_t nvar, vec_t &x,
double &fmin,
233 virtual int mmin_de(
size_t nvar, vec_t &x,
double &fmin,
234 func_t &func, dfunc_t &dfunc)
236 return mmin(nvar,x,fmin,func);
248 template<
class vec2_t>
250 double value,
double limit, std::string comment)
253 if (verbose<=0)
return 0;
258 (*outs) << comment <<
" Iteration: " << iter << std::endl;
260 (*outs) <<
"x: " << std::endl;
261 for(i=0;i<((int)nv);i++) (*outs) << x[i] <<
" ";
262 (*outs) << std::endl;
264 (*outs) <<
"y: " << y <<
" Val: " << value <<
" Lim: " 265 << limit << std::endl;
267 (*outs) <<
"Press a key and type enter to continue. ";
275 const char *
type() {
return "mmin_base"; }
282 this->ntrial=mb.ntrial;
283 this->tol_rel=mb.tol_rel;
284 this->tol_abs=mb.tol_abs;
285 this->last_ntrial=mb.last_ntrial;
286 this->err_nonconv=mb.err_nonconv;
296 this->ntrial=mb.ntrial;
297 this->tol_rel=mb.tol_rel;
298 this->tol_abs=mb.tol_abs;
299 this->last_ntrial=mb.last_ntrial;
300 this->err_nonconv=mb.err_nonconv;
308 #ifndef DOXYGEN_NO_O2NS Class for automatically computing gradients [abstract base].
double epsmin
The minimum stepsize (default )
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
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")
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.