13 #ifndef ROOT_Math_Minimizer 14 #define ROOT_Math_Minimizer 16 #ifndef ROOT_Math_IFunction 20 #ifndef ROOT_Math_MinimizerOptions 24 #ifndef ROOT_Math_Util 28 #ifndef ROOT_Math_Error 44 class ParameterSettings;
118 if (
this == &rhs)
return *
this;
133 SetFunction(static_cast<const ::ROOT::Math::IMultiGenFunction &> (func));
138 template<
class VariableIterator>
139 int SetVariables(
const VariableIterator & begin,
const VariableIterator & end) {
140 unsigned int ivar = 0;
141 for ( VariableIterator vitr = begin; vitr != end; ++vitr) {
143 if (vitr->IsFixed() )
144 iret = SetFixedVariable(ivar, vitr->Name(), vitr->Value() );
145 else if (vitr->IsDoubleBound() )
146 iret = SetLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->LowerLimit(), vitr->UpperLimit() );
147 else if (vitr->HasLowerLimit() )
148 iret = SetLowerLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->LowerLimit() );
149 else if (vitr->HasUpperLimit() )
150 iret = SetUpperLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->UpperLimit() );
152 iret = SetVariable( ivar, vitr->Name(), vitr->Value(), vitr->StepSize() );
161 virtual bool SetVariable(
unsigned int ivar,
const std::string &
name,
double val,
double step) = 0;
163 virtual bool SetLowerLimitedVariable(
unsigned int ivar ,
const std::string & name ,
double val ,
double step ,
double lower ) {
164 return SetLimitedVariable(ivar, name, val, step, lower, std::numeric_limits<double>::infinity() );
167 virtual bool SetUpperLimitedVariable(
unsigned int ivar ,
const std::string & name ,
double val ,
double step ,
double upper ) {
168 return SetLimitedVariable(ivar, name, val, step, - std::numeric_limits<double>::infinity(), upper );
171 virtual bool SetLimitedVariable(
unsigned int ivar ,
const std::string & name ,
double val ,
double step ,
172 double lower ,
double upper ) {
173 MATH_WARN_MSG(
"Minimizer::SetLimitedVariable",
"Setting of limited variable not implemented - set as unlimited");
175 return SetVariable(ivar, name, val, step);
178 virtual bool SetFixedVariable(
unsigned int ivar ,
const std::string & name ,
double val ) {
179 MATH_ERROR_MSG(
"Minimizer::SetFixedVariable",
"Setting of fixed variable not implemented");
185 MATH_ERROR_MSG(
"Minimizer::SetVariableValue",
"Set of a variable value not implemented");
193 while ( i <= NDim() && ret) {
194 ret &= SetVariableValue(i,x[i] ); i++;
200 MATH_ERROR_MSG(
"Minimizer::SetVariableStepSize",
"Setting an existing variable step size not implemented");
206 MATH_ERROR_MSG(
"Minimizer::SetVariableLowerLimit",
"Setting an existing variable limit not implemented");
212 MATH_ERROR_MSG(
"Minimizer::SetVariableUpperLimit",
"Setting an existing variable limit not implemented");
218 return SetVariableLowerLimit(ivar,lower) && SetVariableUpperLimit(ivar,upper);
222 MATH_ERROR_MSG(
"Minimizer::FixVariable",
"Fixing an existing variable not implemented");
228 MATH_ERROR_MSG(
"Minimizer::ReleaseVariable",
"Releasing an existing variable not implemented");
235 MATH_ERROR_MSG(
"Minimizer::IsFixedVariable",
"Quering an existing variable not implemented");
241 MATH_ERROR_MSG(
"Minimizer::GetVariableSettings",
"Quering an existing variable not implemented");
253 virtual bool Minimize() = 0;
256 virtual double MinValue()
const = 0;
259 virtual const double *
X()
const = 0;
262 virtual double Edm()
const {
return -1; }
268 virtual unsigned int NCalls()
const {
return 0; }
275 virtual unsigned int NDim()
const = 0;
280 virtual unsigned int NFree()
const {
return NDim(); }
292 virtual double CovMatrix(
unsigned int ivar ,
unsigned int jvar )
const {
334 virtual double Correlation(
unsigned int i,
unsigned int j )
const {
335 double tmp = CovMatrix(i,i) * CovMatrix(j,j);
336 return ( tmp < 0) ? 0 : CovMatrix(i,j) /
std::sqrt( tmp );
357 virtual bool GetMinosError(
unsigned int ivar ,
double & errLow,
double & errUp,
int option = 0) {
358 MATH_ERROR_MSG(
"Minimizer::GetMinosError",
"Minos Error not implemented");
375 virtual bool Scan(
unsigned int ivar ,
unsigned int & nstep ,
double *
x ,
double *
y ,
387 virtual bool Contour(
unsigned int ivar ,
unsigned int jvar,
unsigned int & npoints,
388 double * xi ,
double * xj ) {
405 return std::string();
411 MATH_ERROR_MSG(
"Minimizer::VariableIndex",
"Getting variable index from name not implemented");
428 double Tolerance()
const {
return fOptions.Tolerance(); }
432 double Precision()
const {
return fOptions.Precision(); }
435 int Strategy()
const {
return fOptions.Strategy(); }
442 double ErrorDef()
const {
return fOptions.ErrorDef(); }
459 void SetMaxIterations(
unsigned int maxiter) {
if (maxiter > 0) fOptions.SetMaxIterations(maxiter); }
469 void SetStrategy(
int strategyLevel) { fOptions.SetStrategy(strategyLevel); }
484 fOptions.ResetToDefaultOptions();
void SetDefaultOptions()
reset the defaut options (defined in MinimizerOptions)
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0...
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
void SetErrorDef(double up)
set scale for calculating the errors
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
virtual void SetFunction(const ROOT::Math::IMultiGradFunction &func)
set a function to minimize using gradient
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found ...
int SetVariables(const VariableIterator &begin, const VariableIterator &end)
add variables . Return number of variables successfully added
void SetOptions(const MinimizerOptions &opt)
set all options in one go
virtual bool ProvidesError() const
minimizer provides error and error matrix
virtual void PrintResults()
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const ...
void SetValidError(bool on)
flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit) ...
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set a new lower limit variable (override if minimizer supports them )
Minimizer()
Default constructor.
virtual MinimizerOptions Options() const
retrieve the minimizer options (implement derived class if needed)
#define MATH_WARN_MSG(loc, str)
int Status() const
status code of minimizer
int PrintLevel() const
minimizer configuration parameters
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower, double upper)
set a new upper/lower limited variable (override if minimizer supports them ) otherwise as default se...
virtual void Clear()
reset for consecutive minimizations - implement if needed
virtual bool GetHessianMatrix(double *hMat) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
virtual const double * Errors() const
return errors at the minimum
virtual int CovMatrixStatus() const
return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made po...
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in's exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
virtual bool SetVariableValues(const double *x)
set the values of all existing variables (array must be dimensioned to the size of the existing param...
bool IsValidError() const
return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit) ...
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names) return an empty strin...
virtual bool Contour(unsigned int ivar, unsigned int jvar, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum The c...
virtual bool SetVariableInitialRange(unsigned int, double, double)
set the initial range of an existing variable
unsigned int MaxIterations() const
max iterations
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &pars) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
#define MATH_ERROR_MSG(loc, str)
virtual unsigned int NIterations() const
number of iterations to reach the minimum
virtual bool SetVariableValue(unsigned int ivar, double value)
set the value of an already existing variable
double Tolerance() const
absolute tolerance
virtual double GlobalCC(unsigned int ivar) const
return global correlation coefficient for variable i This is a number between zero and one which give...
virtual unsigned int NCalls() const
number of function calls to reach the minimum
int Strategy() const
strategy
Minimizer(const Minimizer &)
Copy constructor.
virtual bool SetFixedVariable(unsigned int ivar, const std::string &name, double val)
set a new fixed variable (override if minimizer supports them )
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
virtual double Edm() const
return expected distance reached from the minimum (re-implement if minimizer provides it ...
double Precision() const
precision of minimizer in the evaluation of the objective function ( a value <=0 corresponds to the l...
virtual ~Minimizer()
Destructor (no operations)
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
void SetMaxFunctionCalls(unsigned int maxfcn)
set maximum of function calls
virtual double Correlation(unsigned int i, unsigned int j) const
return correlation coefficient between variable i and j.
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set a new upper limit variable (override if minimizer supports them )
void SetTolerance(double tol)
set the tolerance
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
virtual unsigned int NFree() const
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...
virtual bool GetMinosError(unsigned int ivar, double &errLow, double &errUp, int option=0)
minos error for variable i, return false if Minos failed or not supported and the lower and upper err...
virtual double CovMatrix(unsigned int ivar, unsigned int jvar) const
return covariance matrices element for variables ivar,jvar if the variable is fixed the return value ...
double func(double *x, double *p)
MinimizerOptions fOptions
void SetStrategy(int strategyLevel)
set the strategy
Namespace for new Math classes and functions.
unsigned int MaxFunctionCalls() const
max number of function calls
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
virtual bool Scan(unsigned int ivar, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
scan function minimum for variable i.
void SetPrecision(double prec)
set in the minimizer the objective function evaluation precision ( a value <=0 means the minimizer wi...
void SetPrintLevel(int level)
set print level
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
virtual bool SetVariableStepSize(unsigned int ivar, double value)
set the step size of an already existing variable
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool Hesse()
perform a full calculation of the Hessian matrix for error calculation
virtual bool GetCovMatrix(double *covMat) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...