Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) in ROOT.
Plug-in's exist in ROOT to be able to instantiate the derived classes without linking the library using the static function ROOT::Math::Factory::CreateMinimizer.
Here is the list of all possible minimizers and their respective methods (algorithms) that can be instantiated: The name shown below can be used to create them. More documentation can be found in the respective class
mathmore
supportmathmore
supportmathmore
supportr
supportoptimix
of the optmix R packageThe Minimizer class provides the interface to perform the minimization including
In addition to provide the API for function minimization (via ROOT::Math::Minimizer::Minimize) the Minimizer class provides:
ROOT::Math::Functor
class and the ROOT::Math::GradFunctor
class for wrapping functions providing both evaluation and gradient. Some methods, like Fumili, Fumili2 and GSLMultiFit are specialized method for least-square and also likelihood minimizations. They require then that the given function implements in addition the ROOT::Math::FitMethodFunction
interface.ROOT::Math::MinimizerOptions
. When no parameters are specified the default ones are used. Specific Minimizer options can also be passed via the MinimizerOptions
class. For the list of the available option parameter one must look at the documentation of the corresponding derived class.An example on how to use this interface is the tutorial NumericalMinimization.C in the tutorials/fit directory.
Definition at line 119 of file Minimizer.h.
Public Member Functions | |
Minimizer () | |
Default constructor. | |
Minimizer (Minimizer &&)=delete | |
Minimizer (Minimizer const &)=delete | |
virtual | ~Minimizer () |
Destructor (no operations). | |
virtual void | Clear () |
Reset for consecutive minimization - implement if needed. | |
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. | |
virtual double | Correlation (unsigned int i, unsigned int j) const |
virtual double | CovMatrix (unsigned int ivar, unsigned int jvar) const |
virtual int | CovMatrixStatus () const |
virtual double | Edm () const |
double | ErrorDef () const |
virtual const double * | Errors () const |
virtual bool | FixVariable (unsigned int ivar) |
Fix an existing variable. | |
virtual bool | GetCovMatrix (double *covMat) const |
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value is zero. | |
virtual bool | GetHessianMatrix (double *hMat) const |
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second derivatives and is the inverse of the covariance matrix If the variable is fixed or const the values for that variables are zero. | |
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 errors are returned in errLow and errUp An extra flag specifies if only the lower (option=-1) or the upper (option=+1) error calculation is run. | |
virtual bool | GetVariableSettings (unsigned int ivar, ROOT::Fit::ParameterSettings &pars) const |
Get variable settings in a variable object (like ROOT::Fit::ParamsSettings). | |
virtual double | GlobalCC (unsigned int ivar) const |
virtual bool | Hesse () |
Perform a full calculation of the Hessian matrix for error calculation. | |
virtual bool | IsFixedVariable (unsigned int ivar) const |
Query if an existing variable is fixed (i.e. | |
bool | IsValidError () const |
unsigned int | MaxFunctionCalls () const |
Max number of function calls. | |
unsigned int | MaxIterations () const |
Max iterations. | |
virtual const double * | MinGradient () const |
virtual bool | Minimize ()=0 |
Method to perform the minimization. | |
virtual int | MinosStatus () const |
Status code of Minos (to be re-implemented by the minimizers supporting Minos). | |
virtual double | MinValue () const =0 |
virtual unsigned int | NCalls () const |
Number of function calls to reach the minimum. | |
virtual unsigned int | NDim () const =0 |
this is <= Function().NDim() which is the total number of variables (free+ constrained ones) | |
virtual unsigned int | NFree () const |
Number of free variables (real dimension of the problem). | |
virtual unsigned int | NIterations () const |
Number of iterations to reach the minimum. | |
Minimizer & | operator= (Minimizer &&)=delete |
Minimizer & | operator= (Minimizer const &)=delete |
virtual MinimizerOptions | Options () const |
Retrieve the minimizer options (implement derived class if needed). | |
double | Precision () const |
Precision of minimizer in the evaluation of the objective function. | |
int | PrintLevel () const |
Set print level. | |
virtual void | PrintResults () |
Print the result according to set level (implemented for TMinuit for maintaining Minuit-style printing). | |
virtual bool | ProvidesError () const |
Minimizer provides error and error matrix. | |
virtual bool | ReleaseVariable (unsigned int ivar) |
Release an 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. | |
virtual bool | SetCovariance (std::span< const double > cov, unsigned int nrow) |
Set initial covariance matrix. | |
virtual bool | SetCovarianceDiag (std::span< const double > d2, unsigned int n) |
Set initial second derivatives. | |
void | SetDefaultOptions () |
Reset the default options (defined in MinimizerOptions). | |
void | SetErrorDef (double up) |
Set scale for calculating the errors. | |
void | SetExtraOptions (const IOptions &extraOptions) |
Set only the extra options. | |
virtual bool | SetFixedVariable (unsigned int ivar, const std::string &name, double val) |
Set a new fixed variable (override if minimizer supports them). | |
virtual void | SetFunction (const ROOT::Math::IMultiGenFunction &func)=0 |
Set the function to minimize. | |
virtual void | SetHessianFunction (std::function< bool(std::span< const double >, double *)>) |
Set the function implementing Hessian computation (re-implemented by Minimizer using it). | |
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 set an unlimited variable (i.e. | |
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), leave upper bound unlimited. | |
void | SetMaxFunctionCalls (unsigned int maxfcn) |
Set maximum of function calls. | |
void | SetMaxIterations (unsigned int maxiter) |
Set maximum iterations (one iteration can have many function calls). | |
void | SetOptions (const MinimizerOptions &opt) |
Set all options in one go. | |
void | SetPrecision (double prec) |
Set in the minimizer the objective function evaluation precision. | |
void | SetPrintLevel (int level) |
Set print level. | |
void | SetStrategy (int strategyLevel) |
Set the strategy. | |
void | SetTolerance (double tol) |
Set the tolerance. | |
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), leave lower bound unlimited. | |
void | SetValidError (bool on) |
Flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit). | |
virtual bool | SetVariable (unsigned int ivar, const std::string &name, double val, double step)=0 |
Set a new free variable. | |
virtual bool | SetVariableInitialRange (unsigned int, double, double) |
Set the initial range of an existing variable. | |
virtual bool | SetVariableLimits (unsigned int ivar, double lower, double upper) |
Set the limits of an already existing variable. | |
virtual bool | SetVariableLowerLimit (unsigned int ivar, double lower) |
Set the lower-limit of an already existing variable. | |
template<class VariableIterator > | |
int | SetVariables (const VariableIterator &begin, const VariableIterator &end) |
Add variables. | |
virtual bool | SetVariableStepSize (unsigned int ivar, double value) |
Set the step size of an already existing variable. | |
virtual bool | SetVariableUpperLimit (unsigned int ivar, double upper) |
Set the upper-limit of an already existing variable. | |
virtual bool | SetVariableValue (unsigned int ivar, double value) |
Set the value of an already existing variable. | |
virtual bool | SetVariableValues (const double *x) |
Set the values of all existing variables (array must be dimensioned to the size of the existing parameters). | |
int | Status () const |
Status code of minimizer. | |
int | Strategy () const |
Strategy. | |
double | Tolerance () const |
Absolute tolerance. | |
virtual int | VariableIndex (const std::string &name) const |
Get index of variable given a variable given a name. | |
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 =0 |
Protected Attributes | |
MinimizerOptions | fOptions |
minimizer options | |
int | fStatus = -1 |
status of minimizer | |
bool | fValidError = false |
flag to control if errors have been validated (Hesse has been run in case of Minuit) | |
#include <Math/Minimizer.h>
|
inline |
Default constructor.
Definition at line 124 of file Minimizer.h.
|
inlinevirtual |
Destructor (no operations).
Definition at line 127 of file Minimizer.h.
|
delete |
|
inlinevirtual |
Reset for consecutive minimization - implement if needed.
Reimplemented in ROOT::Math::GeneticMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 136 of file Minimizer.h.
|
virtual |
Find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum.
The contour will be find for value of the function = Min + ErrorUp();
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 220 of file Minimizer.cxx.
|
inlinevirtual |
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 276 of file Minimizer.h.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, TLinearMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, ROOT::Math::RMinimizer, ROOT::Math::GSLMinimizer, and ROOT::Math::GSLNLSMinimizer.
Definition at line 129 of file Minimizer.cxx.
Reimplemented in TFumiliMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 268 of file Minimizer.h.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 234 of file Minimizer.h.
|
inline |
Definition at line 329 of file Minimizer.h.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::RMinimizer.
Definition at line 258 of file Minimizer.h.
Fix an existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 95 of file Minimizer.cxx.
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value is zero.
The array will be filled as cov[i *ndim + j] The ordering of the variables is the same as in errors and parameter value. This is different from the direct interface of Minuit2 or TMinuit where the values were obtained only to variable parameters
Reimplemented in TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::RMinimizer.
Definition at line 144 of file Minimizer.cxx.
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second derivatives and is the inverse of the covariance matrix If the variable is fixed or const the values for that variables are zero.
The array will be filled as h[i *ndim + j]
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 157 of file Minimizer.cxx.
|
virtual |
Minos error for variable i, return false if Minos failed or not supported and the lower and upper errors are returned in errLow and errUp An extra flag specifies if only the lower (option=-1) or the upper (option=+1) error calculation is run.
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 181 of file Minimizer.cxx.
|
virtual |
Get variable settings in a variable object (like ROOT::Fit::ParamsSettings).
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 117 of file Minimizer.cxx.
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 170 of file Minimizer.cxx.
|
virtual |
Perform a full calculation of the Hessian matrix for error calculation.
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 194 of file Minimizer.cxx.
Query if an existing variable is fixed (i.e.
considered constant in the minimization).
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 110 of file Minimizer.cxx.
|
inline |
Definition at line 332 of file Minimizer.h.
|
inline |
Max number of function calls.
Definition at line 306 of file Minimizer.h.
|
inline |
Max iterations.
Definition at line 309 of file Minimizer.h.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 237 of file Minimizer.h.
Method to perform the minimization.
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, ROOT::Math::GSLSimAnMinimizer, TLinearMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::RMinimizer.
Status code of Minos (to be re-implemented by the minimizers supporting Minos).
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 325 of file Minimizer.h.
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Number of function calls to reach the minimum.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, ROOT::Math::GSLSimAnMinimizer, TLinearMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::RMinimizer.
Definition at line 240 of file Minimizer.h.
this is <= Function().NDim() which is the total number of variables (free+ constrained ones)
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Number of free variables (real dimension of the problem).
this is <= Function().NDim() which is the total (re-implement if minimizer supports bounded parameters)
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 252 of file Minimizer.h.
Number of iterations to reach the minimum.
Definition at line 243 of file Minimizer.h.
|
inlinevirtual |
Retrieve the minimizer options (implement derived class if needed).
Reimplemented in ROOT::Math::GeneticMinimizer.
Definition at line 335 of file Minimizer.h.
|
inline |
Precision of minimizer in the evaluation of the objective function.
(a value <=0 corresponds to the let the minimizer choose its default one)
Definition at line 316 of file Minimizer.h.
|
inline |
Set print level.
Definition at line 303 of file Minimizer.h.
|
inlinevirtual |
Print the result according to set level (implemented for TMinuit for maintaining Minuit-style printing).
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 294 of file Minimizer.h.
Minimizer provides error and error matrix.
Reimplemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::RMinimizer.
Definition at line 255 of file Minimizer.h.
Release an existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 102 of file Minimizer.cxx.
|
virtual |
Scan function minimum for variable i.
Variable and function must be set before using Scan.
Reimplemented in TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 204 of file Minimizer.cxx.
|
virtual |
Set initial covariance matrix.
Set initial values for covariance/error matrix.
The covariance matrix must be provided in compressed form (row-major ordered upper traingular part)
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 26 of file Minimizer.cxx.
|
virtual |
Set initial second derivatives.
set initial second derivatives
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 15 of file Minimizer.cxx.
|
inline |
Reset the default options (defined in MinimizerOptions).
Definition at line 373 of file Minimizer.h.
|
inline |
Set scale for calculating the errors.
Definition at line 359 of file Minimizer.h.
Set only the extra options.
Definition at line 370 of file Minimizer.h.
|
virtual |
Set a new fixed variable (override if minimizer supports them).
Reimplemented in ROOT::Math::GeneticMinimizer, TFumiliMinimizer, ROOT::Math::BasicMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 52 of file Minimizer.cxx.
|
pure virtual |
Set the function to minimize.
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
|
inlinevirtual |
Set the function implementing Hessian computation (re-implemented by Minimizer using it).
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 142 of file Minimizer.h.
|
virtual |
Set a new upper/lower limited variable (override if minimizer supports them) otherwise as default set an unlimited variable (i.e.
the lower and upper bounds will be ignored).
ivar | the index of this variable in the array |
name | the variable name |
val | the value |
step | the step size |
lower | the lower bound |
upper | this upper bound |
Reimplemented in TFumiliMinimizer, ROOT::Math::BasicMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::GeneticMinimizer.
Definition at line 42 of file Minimizer.cxx.
|
inlinevirtual |
Set a new lower limit variable (override if minimizer supports them), leave upper bound unlimited.
ivar | the index of this variable in the array |
name | the variable name |
val | the value |
step | the step size |
lower | the lower bound |
Reimplemented in ROOT::Math::BasicMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 181 of file Minimizer.h.
|
inline |
Set maximum of function calls.
Definition at line 343 of file Minimizer.h.
|
inline |
Set maximum iterations (one iteration can have many function calls).
Definition at line 346 of file Minimizer.h.
|
inline |
Set all options in one go.
Definition at line 365 of file Minimizer.h.
|
inline |
Set in the minimizer the objective function evaluation precision.
(a value <=0 means the minimizer will choose its optimal value automatically, i.e. default case)
Definition at line 353 of file Minimizer.h.
|
inline |
Set print level.
Definition at line 340 of file Minimizer.h.
|
inline |
Set the strategy.
Definition at line 356 of file Minimizer.h.
|
inline |
Set the tolerance.
Definition at line 349 of file Minimizer.h.
|
inlinevirtual |
Set a new upper limit variable (override if minimizer supports them), leave lower bound unlimited.
ivar | the index of this variable in the array |
name | the variable name |
val | the value |
step | the step size |
upper | the upper bound |
Reimplemented in ROOT::Math::BasicMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 191 of file Minimizer.h.
|
inline |
Flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit).
Definition at line 362 of file Minimizer.h.
|
pure virtual |
Set a new free variable.
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, TMinuitMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TLinearMinimizer.
|
inlinevirtual |
Set the initial range of an existing variable.
Definition at line 220 of file Minimizer.h.
|
inlinevirtual |
Set the limits of an already existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 211 of file Minimizer.h.
Set the lower-limit of an already existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 78 of file Minimizer.cxx.
|
inline |
Add variables.
Definition at line 146 of file Minimizer.h.
Set the step size of an already existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 70 of file Minimizer.cxx.
Set the upper-limit of an already existing variable.
Reimplemented in ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 86 of file Minimizer.cxx.
Set the value of an already existing variable.
Reimplemented in TFumiliMinimizer, ROOT::Math::BasicMinimizer, ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 61 of file Minimizer.cxx.
Set the values of all existing variables (array must be dimensioned to the size of the existing parameters).
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and ROOT::Math::BasicMinimizer.
Definition at line 199 of file Minimizer.h.
|
inline |
Status code of minimizer.
Definition at line 322 of file Minimizer.h.
|
inline |
Strategy.
Definition at line 319 of file Minimizer.h.
|
inline |
Absolute tolerance.
Definition at line 312 of file Minimizer.h.
Get index of variable given a variable given a name.
Reimplemented in ROOT::Math::BasicMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 241 of file Minimizer.cxx.
|
virtual |
Get name of variables (override if minimizer support storing of variable names).
Reimplemented in ROOT::Math::BasicMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 233 of file Minimizer.cxx.
Implemented in TFumiliMinimizer, ROOT::Math::GeneticMinimizer, ROOT::Math::BasicMinimizer, TLinearMinimizer, TMinuitMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
|
protected |
minimizer options
Definition at line 382 of file Minimizer.h.
|
protected |
status of minimizer
Definition at line 383 of file Minimizer.h.
flag to control if errors have been validated (Hesse has been run in case of Minuit)
Definition at line 381 of file Minimizer.h.