23 #ifndef O2SCL_ROOT_ROBBINS_MONRO_H 24 #define O2SCL_ROOT_ROBBINS_MONRO_H 31 #include <o2scl/funct.h> 32 #include <o2scl/root.h> 34 #ifndef DOXYGEN_NO_O2NS 40 template<
class func_t=funct,
class dfunc_t=func_t>
60 virtual const char *
type() {
return "root_robbins_monro"; }
64 virtual int solve(
double &x, func_t &func) {
70 for(
size_t i=0;i<this->
ntrial/2;i++) {
75 x2=x-fx*coeff/pow(((
double)(i+1)),gamma);
76 avg+=(x2*((double)i)+avg)/((
double)(i+1));
77 double favg=func(avg);
89 for(
size_t i=0;i<this->
ntrial;i++) {
94 x2=x-f(x)*coeff/pow(((
double)(i+1)),gamma);
116 virtual int solve_de(
double &x, func_t &func, dfunc_t &df) {
122 for(
size_t i=0;i<this->
ntrial/2;i++) {
128 x2=x-fx/df*coeff/pow(((
double)(i+1)),gamma);
129 avg+=(x2*((double)i)+avg)/((
double)(i+1));
130 double favg=func(avg);
131 if (fabs(favg)<this->
tol_rel) {
142 for(
size_t i=0;i<this->
ntrial;i++) {
148 x2=x-fx/df*coeff/pow(((
double)(i+1)),gamma);
163 #ifndef DOXYGEN_NO_O2NS int ntrial
Maximum number of iterations (default 100)
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual int solve_de(double &x, func_t &func, dfunc_t &df)
Solve func using x as an initial guess using derivatives df.
exceeded max number of iterations
virtual int solve(double &x, func_t &func)
Solve func using x as an initial guess.
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
double tol_rel
The maximum value of the functions for success (default )
bool err_nonconv
If true, call the error handler if the solver does not converge (default true)
bool pr_averaging
If true, apply Polyak-Ruppert averaging.
One-dimensional solver [abstract base].
One-dimensional root-finding for noisy functions.
virtual const char * type()
Return the type, "root_robbins_monro".
double gamma
Exponent for sequence (default 1.0)
virtual int solve_bkt(double &x1, double x2, func_t &f)
Solve func in region returning .
static const double x2[5]
static const double x1[5]
double coeff
Coefficient for sequence (default 1.0)