25 namespace BrentMethods {
27 double MinimStep(
const IGenFunction*
function,
int type,
double &xmin,
double &xmax,
double fy,
int npx,
bool logStep)
44 if (npx < 2)
return 0.5*(xmax-xmin);
45 double dx = (xmax-xmin)/(npx-1);
46 double xxmin = (logStep) ?
std::exp(xmin) : xmin;
49 yymin = (*function)(xxmin);
51 yymin = -(*function)(xxmin);
55 for (
int i=1; i<=npx-1; i++) {
56 double x = xmin + i*dx;
77 xmin = std::max(xmin,xxmin-dx);
78 xmax = std::min(xmax,xxmin+dx);
80 return std::min(xxmin, xmax);
83 double MinimBrent(
const IGenFunction*
function,
int type,
double &xmin,
double &xmax,
double xmiddle,
double fy,
bool &ok,
int &niter,
double epsabs,
double epsrel,
int itermax)
99 const double c = 3.81966011250105097e-01;
100 double u,
v, w,
x, fv, fu, fw, fx,
e, p, q, r, t2, d=0,
m, tol;
107 fv = fw = fx = (*function)(
x);
109 fv = fw = fx = -(*function)(
x);
111 fv = fw = fx =
std::fabs((*
function)(x)-fy);
113 for (
int i=0; i<itermax; i++){
134 p = (x-
v)*q - (x-w)*r;
146 e=(x>=
m ? a-
x : b-
x);
152 if (u-a < t2 || b-u < t2)
157 e=(x>=
m ? a-
x : b-
x);
164 fu = -(*function)(u);
171 v=w; fv=fw; w=
x; fw=fx; x=u; fx=fu;
176 v=w; fv=fw; w=u; fw=fu;
178 else if (fu<=fv || v==x || v==w){
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Namespace for new ROOT classes and functions.
double MinimStep(const IGenFunction *f, int type, double &xmin, double &xmax, double fy, int npx=100, bool useLog=false)
Grid search implementation, used to bracket the minimum and later use Brent's method with the bracket...
double MinimBrent(const IGenFunction *f, int type, double &xmin, double &xmax, double xmiddle, double fy, bool &ok, int &niter, double epsabs=1.E-8, double epsrel=1.E-10, int maxiter=100)
Finds a minimum of a function, if the function is unimodal between xmin and xmax This method uses a c...
you should not use this method at all Int_t y
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t Int_t m
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
* x
Deprecated and error prone model selection interface.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Namespace for new Math classes and functions.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b