61 if (niter <=0 ) niter = 1000;
69 std::string algoname(
type);
70 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (
int(*)(
int)) tolower );
87 if (niter <=0 ) niter = 1000;
116 if (fnumgrad)
return fnumgrad->
NCalls();
118 if (ffitmethod)
return ffitmethod->
NCalls();
129 MATH_ERROR_MSG(
"GSLMinimizer::Minimize",
"Function has not been set");
133 unsigned int npar =
NPar();
134 unsigned int ndim =
NDim();
135 if (npar == 0 || npar <
NDim() ) {
140 MATH_WARN_MSGVAL(
"GSLMinimizer::Minimize",
"number of parameters larger than function dimension - ignore extra parameters",npar);
145 std::vector<double> startValues;
153 steps.resize(trFunc->
NDim());
158 MATH_INFO_MSG(
"GSLMinimizer::Minimize",
"There are no free parameter - just compute the function value");
159 double fval = (*function)((
double*)0);
168 for (
unsigned int i = 0; i < steps.size(); ++i)
169 stepSize += steps[i]*steps[i];
171 if (stepSize < eps) {
183 if (debugLevel >=1 ) std::cout <<
"Minimize using GSLMinimizer " <<
fGSLMultiMin->
Name() << std::endl;
190 unsigned int iter = 0;
192 bool minFound =
false;
193 bool iterFailed =
false;
206 if (debugLevel >=2) {
207 std::cout <<
"----------> Iteration " << std::setw(4) << iter;
208 int pr = std::cout.precision(18);
210 std::cout.precision(pr);
211 if (debugLevel >=3) {
212 std::cout <<
" Parameter Values : ";
214 std::cout << std::endl;
218 for (
unsigned int i = 0; i <
NDim(); ++i) {
219 std::cout <<
" " <<
VariableName(i) <<
" = " << xtmp[i];
223 std::cout << std::endl;
237 if (
x == 0)
return false;
247 if (debugLevel >=1 ) {
248 std::cout <<
"GSLMinimizer: Minimum Found" << std::endl;
249 int pr = std::cout.precision(18);
250 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
251 std::cout.precision(pr);
253 std::cout <<
"Niterations = " << iter << std::endl;
254 unsigned int ncalls =
NCalls();
255 if (ncalls) std::cout <<
"NCalls = " << ncalls << std::endl;
256 for (
unsigned int i = 0; i <
NDim(); ++i)
257 std::cout <<
VariableName(i) <<
"\t = " <<
X()[i] << std::endl;
262 if (debugLevel >= -1 ) {
263 std::cout <<
"GSLMinimizer: Minimization did not converge" << std::endl;
265 if (status == GSL_ENOPROG)
266 std::cout <<
"\t Iteration is not making progress towards solution" << std::endl;
268 std::cout <<
"\t Iteration failed with status " << status << std::endl;
270 if (debugLevel >= 1) {
273 for (
unsigned int i = 0; i <
NDim(); ++i) dg2 +=
g[i] *
g[1];
274 std::cout <<
"Grad module is " <<
std::sqrt(dg2) << std::endl;
275 for (
unsigned int i = 0; i <
NDim(); ++i)
276 std::cout <<
VariableName(i) <<
"\t = " <<
X()[i] << std::endl;
277 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
279 std::cout <<
"Niterations = " << iter << std::endl;
#define MATH_INFO_MSG(loc, str)
Pre-processor macro to report messages which can be configured to use ROOT error or simply an std::io...
#define MATH_ERROR_MSGVAL(loc, txt, x)
#define MATH_ERROR_MSG(loc, str)
#define MATH_WARN_MSGVAL(loc, txt, x)
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
virtual unsigned int NCalls() const
return the total number of function calls (overrided if needed)
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
virtual double MinValue() const
return minimum function value
virtual unsigned int NPar() const
total number of parameter defined
virtual unsigned int NFree() const
number of free variables (real dimension of the problem)
void SetMinValue(double val)
virtual const double * StepSizes() const
accessor methods
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
virtual unsigned int NDim() const
number of dimensions
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
virtual const double * X() const
return pointer to X values at the minimum
void SetFinalValues(const double *x)
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=0)
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
virtual unsigned int NCalls() const
number of function calls to reach the minimum
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
ROOT::Math::GSLMultiMinimizer * fGSLMultiMin
GSLMinimizer(ROOT::Math::EGSLMinimizerType type=ROOT::Math::kConjugateFR)
Default constructor.
virtual bool Minimize()
method to perform the minimization
virtual ~GSLMinimizer()
Destructor.
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
GSLMultiMinimizer class , for minimizing multi-dimensional function using derivatives.
int Set(const ROOT::Math::IMultiGradFunction &func, const double *x, double stepSize, double tol)
set the function to be minimize the initial minimizer parameters, step size and tolerance in the line...
double Minimum() const
function value at the minimum
double * Gradient() const
gradient value at the minimum
double * X() const
x values at the minimum
int TestGradient(double absTol) const
test gradient (ask from minimizer gradient vector)
Documentation for the abstract class IBaseFunctionMultiDim.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
static int DefaultPrintLevel()
static int DefaultMaxIterations()
double Tolerance() const
absolute tolerance
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
unsigned int MaxIterations() const
max iterations
void SetPrintLevel(int level)
set print level
int PrintLevel() const
minimizer configuration parameters
MultiNumGradFunction class to wrap a normal function in a gradient function using numerical gradient ...
unsigned int NCalls() const
EGSLMinimizerType
enumeration specifying the types of GSL minimizers
Namespace for new Math classes and functions.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)