RMinimizer class.
Minimizer class that uses the ROOT/R interface to pass functions and minimize them in R.
The class implements the ROOT::Math::Minimizer interface and can be instantiated using the ROOT plugin manager (plugin name is "RMinimizer"). The various minimization algorithms (BFGS, Nelder-Mead, SANN, etc..) can be passed as an option. The default algorithm is BFGS.
The library for this and future R/ROOT classes is currently libRtools.so
Definition at line 33 of file RMinimizer.h.
Public Member Functions | |
| RMinimizer (Option_t *method) | |
| Default constructor. | |
| ~RMinimizer () override | |
| Destructor. | |
| 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 |
| double | CovMatrix (unsigned int ivar, unsigned int jvar) const override |
| return covariance matrices element for variables ivar,jvar if the variable is fixed the return value is zero The ordering of the variables is the same as in the parameter and errors vectors | |
| virtual int | CovMatrixStatus () const |
| virtual double | Edm () const |
| double | ErrorDef () const |
| const double * | Errors () const override |
| return errors at the minimum | |
| bool | FixVariable (unsigned int ivar) override |
| fix an existing variable | |
| bool | GetCovMatrix (double *covMat) const override |
| 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. | |
| bool | GetVariableSettings (unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const override |
| get variable settings in a variable object (like ROOT::Fit::ParamsSettings) | |
| virtual std::vector< double > | GlobalCC () const |
| const ROOT::Math::IMultiGradFunction * | GradObjFunction () const |
| return pointer to used gradient object function (NULL if gradient is not supported) | |
| virtual bool | Hesse () |
| Perform a full calculation of the Hessian matrix for error calculation. | |
| double | HessMatrix (unsigned int i, unsigned int j) const |
| Returns the ith jth component of the Hessian matrix. | |
| bool | IsFixedVariable (unsigned int ivar) const override |
| 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 |
| bool | Minimize () override |
| Function to find the minimum. | |
| virtual int | MinosStatus () const |
| Status code of Minos (to be re-implemented by the minimizers supporting Minos). | |
| double | MinValue () const override |
| return minimum function value | |
| unsigned int | NCalls () const override |
| Returns the number of function calls. | |
| unsigned int | NDim () const override |
| number of dimensions | |
| unsigned int | NFree () const override |
| number of free variables (real dimension of the problem) | |
| virtual unsigned int | NIterations () const |
| Number of iterations to reach the minimum. | |
| virtual unsigned int | NPar () const |
| total number of parameter defined | |
| const ROOT::Math::IMultiGenFunction * | ObjFunction () const |
| return pointer to used objective function | |
| 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. | |
| void | PrintResult () const |
| print result of minimization | |
| virtual void | PrintResults () |
| Print the result according to set level (implemented for TMinuit for maintaining Minuit-style printing). | |
| bool | ProvidesError () const override |
| minimizer provides error and error matrix | |
| bool | ReleaseVariable (unsigned int ivar) override |
| 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. | |
| bool | SetFixedVariable (unsigned int, const std::string &, double) override |
| set fixed variable (override if minimizer supports them ) | |
| void | SetFunction (const ROOT::Math::IMultiGenFunction &func) override |
| 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). | |
| bool | SetLimitedVariable (unsigned int ivar, const std::string &name, double val, double step, double, double) override |
| set upper/lower limited variable (override if minimizer supports them ) | |
| bool | SetLowerLimitedVariable (unsigned int ivar, const std::string &name, double val, double step, double lower) override |
| set lower limit variable (override if minimizer supports them ) | |
| 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. | |
| bool | SetUpperLimitedVariable (unsigned int ivar, const std::string &name, double val, double step, double upper) override |
| set upper limit variable (override if minimizer supports them ) | |
| void | SetValidError (bool on) |
| Flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit). | |
| bool | SetVariable (unsigned int ivar, const std::string &name, double val, double step) override |
| set free variable | |
| virtual bool | SetVariableInitialRange (unsigned int, double, double) |
| Set the initial range of an existing variable. | |
| bool | SetVariableLimits (unsigned int ivar, double lower, double upper) override |
| set the limits of an already existing variable | |
| bool | SetVariableLowerLimit (unsigned int ivar, double lower) override |
| set the lower-limit of an already existing variable | |
| template<class VariableIterator> | |
| int | SetVariables (const VariableIterator &begin, const VariableIterator &end) |
| Add variables. | |
| bool | SetVariableStepSize (unsigned int ivar, double step) override |
| set the step size of an already existing variable | |
| bool | SetVariableUpperLimit (unsigned int ivar, double upper) override |
| set the upper-limit of an already existing variable | |
| bool | SetVariableValue (unsigned int ivar, double val) override |
| set the value of an existing variable | |
| bool | SetVariableValues (const double *x) override |
| set the values of all existing variables (array must be dimensioned to the size of existing parameters) | |
| int | Status () const |
| Status code of minimizer. | |
| virtual const double * | StepSizes () const |
| accessor methods | |
| int | Strategy () const |
| Strategy. | |
| double | Tolerance () const |
| Absolute tolerance. | |
| int | VariableIndex (const std::string &name) const override |
| get index of variable given a variable given a name return -1 if variable is not found | |
| std::string | VariableName (unsigned int ivar) const override |
| get name of variables (override if minimizer support storing of variable names) | |
| const double * | X () const override |
| return pointer to X values at the minimum | |
Protected Member Functions | |
| bool | CheckDimension () const |
| bool | CheckObjFunction () const |
| MinimTransformFunction * | CreateTransformation (std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=nullptr) |
| void | SetFinalValues (const double *x, const MinimTransformFunction *func=nullptr) |
| void | SetMinValue (double val) |
Protected Attributes | |
| std::string | fMethod |
| minimizer method to be used, must be of a type listed in R optim or optimx descriptions | |
| 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) | |
Private Attributes | |
| std::map< unsigned int, std::pair< double, double > > | fBounds |
| map specifying the bound using as key the parameter index | |
| TMatrixD | fCovMatrix |
| covariant matrix | |
| unsigned int | fDim |
| std::vector< double > | fErrors |
| vector of parameter errors | |
| TMatrixD | fHessMatrix |
| Hessian matrix. | |
| double | fMinVal |
| std::vector< std::string > | fNames |
| const ROOT::Math::IMultiGenFunction * | fObjFunc |
| std::vector< double > | fSteps |
| std::vector< double > | fValues |
| std::vector< ROOT::Math::EMinimVariableType > | fVarTypes |
| vector specifying the type of variables | |
#include <Math/RMinimizer.h>
| ROOT::Math::RMinimizer::RMinimizer | ( | Option_t * | method | ) |
Default constructor.
Default constructor with option for the method of minimization, can be any of the following: "Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent" (Brent only for 1D minimization)
See R optim or optimx descriptions for more details and options.
Definition at line 37 of file RMinimizer.cxx.
|
inlineoverride |
Destructor.
Definition at line 53 of file RMinimizer.h.
|
protectedinherited |
Definition at line 247 of file BasicMinimizer.cxx.
|
protectedinherited |
Definition at line 256 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Reset for consecutive minimization - implement if needed.
Reimplemented in ROOT::Math::GeneticMinimizer, and ROOT::Minuit2::Minuit2Minimizer.
Definition at line 141 of file Minimizer.h.
|
virtualinherited |
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 ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 219 of file Minimizer.cxx.
|
inlinevirtualinherited |
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 281 of file Minimizer.h.
|
inlineoverridevirtual |
return covariance matrices element for variables ivar,jvar if the variable is fixed the return value is zero The ordering of the variables is the same as in the parameter and errors vectors
Reimplemented from ROOT::Math::Minimizer.
Definition at line 68 of file RMinimizer.h.
|
inlinevirtualinherited |
Reimplemented in ROOT::Math::GSLNLSMinimizer, ROOT::Minuit2::Minuit2Minimizer, TFumiliMinimizer, TLinearMinimizer, and TMinuitMinimizer.
Definition at line 273 of file Minimizer.h.
|
protectedinherited |
Definition at line 265 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Reimplemented in ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, ROOT::Minuit2::Minuit2Minimizer, TFumiliMinimizer, TLinearMinimizer, and TMinuitMinimizer.
Definition at line 239 of file Minimizer.h.
|
inlineinherited |
Definition at line 334 of file Minimizer.h.
|
inlineoverridevirtual |
return errors at the minimum
Reimplemented from ROOT::Math::Minimizer.
Definition at line 63 of file RMinimizer.h.
fix an existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 182 of file BasicMinimizer.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 from ROOT::Math::Minimizer.
Definition at line 79 of file RMinimizer.h.
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 ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 157 of file Minimizer.cxx.
|
virtualinherited |
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 ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 180 of file Minimizer.cxx.
|
overridevirtualinherited |
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
Reimplemented from ROOT::Math::Minimizer.
Definition at line 211 of file BasicMinimizer.cxx.
|
virtualinherited |
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 170 of file Minimizer.cxx.
|
inherited |
return pointer to used gradient object function (NULL if gradient is not supported)
Definition at line 325 of file BasicMinimizer.cxx.
|
virtualinherited |
Perform a full calculation of the Hessian matrix for error calculation.
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 193 of file Minimizer.cxx.
Returns the ith jth component of the Hessian matrix.
|
overridevirtualinherited |
query if an existing variable is fixed (i.e.
considered constant in the minimization) note that by default all variables are not fixed
Reimplemented from ROOT::Math::Minimizer.
Definition at line 206 of file BasicMinimizer.cxx.
|
inlineinherited |
Definition at line 337 of file Minimizer.h.
|
inlineinherited |
Max number of function calls.
Definition at line 311 of file Minimizer.h.
|
inlineinherited |
Max iterations.
Definition at line 314 of file Minimizer.h.
|
inlinevirtualinherited |
Reimplemented in ROOT::Math::GeneticMinimizer, ROOT::Math::GSLMinimizer, ROOT::Math::GSLNLSMinimizer, ROOT::Minuit2::Minuit2Minimizer, TFumiliMinimizer, TLinearMinimizer, and TMinuitMinimizer.
Definition at line 242 of file Minimizer.h.
|
overridevirtual |
Function to find the minimum.
function for finding the minimum
Reimplemented from ROOT::Math::BasicMinimizer.
Definition at line 46 of file RMinimizer.cxx.
|
inlinevirtualinherited |
Status code of Minos (to be re-implemented by the minimizers supporting Minos).
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 330 of file Minimizer.h.
|
inlineoverridevirtualinherited |
return minimum function value
Implements ROOT::Math::Minimizer.
Definition at line 115 of file BasicMinimizer.h.
|
overridevirtual |
Returns the number of function calls.
returns number of function calls
Reimplemented from ROOT::Math::Minimizer.
Definition at line 43 of file RMinimizer.cxx.
|
inlineoverridevirtualinherited |
number of dimensions
Implements ROOT::Math::Minimizer.
Definition at line 121 of file BasicMinimizer.h.
|
overridevirtualinherited |
number of free variables (real dimension of the problem)
Reimplemented from ROOT::Math::Minimizer.
Definition at line 330 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Number of iterations to reach the minimum.
Definition at line 248 of file Minimizer.h.
|
inlinevirtualinherited |
total number of parameter defined
Definition at line 127 of file BasicMinimizer.h.
|
inlineinherited |
return pointer to used objective function
Definition at line 130 of file BasicMinimizer.h.
|
inlinevirtualinherited |
Retrieve the minimizer options (implement derived class if needed).
Reimplemented in ROOT::Math::GeneticMinimizer.
Definition at line 340 of file Minimizer.h.
|
inlineinherited |
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 321 of file Minimizer.h.
|
inlineinherited |
Set print level.
Definition at line 308 of file Minimizer.h.
|
inherited |
print result of minimization
Definition at line 313 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Print the result according to set level (implemented for TMinuit for maintaining Minuit-style printing).
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 299 of file Minimizer.h.
|
inlineoverridevirtual |
minimizer provides error and error matrix
Reimplemented from ROOT::Math::Minimizer.
Definition at line 61 of file RMinimizer.h.
release an existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 189 of file BasicMinimizer.cxx.
|
virtualinherited |
Scan function minimum for variable i.
Variable and function must be set before using Scan.
Reimplemented in ROOT::Minuit2::Minuit2Minimizer, and TMinuitMinimizer.
Definition at line 203 of file Minimizer.cxx.
|
virtualinherited |
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.
|
virtualinherited |
Set initial second derivatives.
set initial second derivatives
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 15 of file Minimizer.cxx.
|
inlineinherited |
Reset the default options (defined in MinimizerOptions).
Definition at line 378 of file Minimizer.h.
|
inlineinherited |
Set scale for calculating the errors.
Definition at line 364 of file Minimizer.h.
|
inlineinherited |
Set only the extra options.
Definition at line 375 of file Minimizer.h.
|
protectedinherited |
Definition at line 300 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set fixed variable (override if minimizer supports them )
Reimplemented from ROOT::Math::Minimizer.
Definition at line 116 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set the function to minimize
Implements ROOT::Math::Minimizer.
Reimplemented in ROOT::Math::GSLMinimizer, and ROOT::Math::GSLNLSMinimizer.
Definition at line 240 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Set the function implementing Hessian computation (re-implemented by Minimizer using it).
Reimplemented in ROOT::Minuit2::Minuit2Minimizer.
Definition at line 147 of file Minimizer.h.
|
overridevirtualinherited |
set upper/lower limited variable (override if minimizer supports them )
Reimplemented from ROOT::Math::Minimizer.
Definition at line 107 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set lower limit variable (override if minimizer supports them )
Reimplemented from ROOT::Math::Minimizer.
Definition at line 88 of file BasicMinimizer.cxx.
|
inlineinherited |
Set maximum of function calls.
Definition at line 348 of file Minimizer.h.
|
inlineinherited |
Set maximum iterations (one iteration can have many function calls).
Definition at line 351 of file Minimizer.h.
|
inlineprotectedinherited |
Definition at line 152 of file BasicMinimizer.h.
|
inlineinherited |
Set all options in one go.
Definition at line 370 of file Minimizer.h.
|
inlineinherited |
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 358 of file Minimizer.h.
|
inlineinherited |
Set print level.
Definition at line 345 of file Minimizer.h.
|
inlineinherited |
Set the strategy.
Definition at line 361 of file Minimizer.h.
|
inlineinherited |
Set the tolerance.
Definition at line 354 of file Minimizer.h.
|
overridevirtualinherited |
set upper limit variable (override if minimizer supports them )
Reimplemented from ROOT::Math::Minimizer.
Definition at line 97 of file BasicMinimizer.cxx.
|
inlineinherited |
Flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit).
Definition at line 367 of file Minimizer.h.
|
overridevirtualinherited |
set free variable
Implements ROOT::Math::Minimizer.
Definition at line 63 of file BasicMinimizer.cxx.
|
inlinevirtualinherited |
Set the initial range of an existing variable.
Definition at line 225 of file Minimizer.h.
|
overridevirtualinherited |
set the limits of an already existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 159 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set the lower-limit of an already existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 147 of file BasicMinimizer.cxx.
|
inlineinherited |
Add variables.
Definition at line 151 of file Minimizer.h.
|
overridevirtualinherited |
set the step size of an already existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 140 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set the upper-limit of an already existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 153 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
set the value of an existing variable
Reimplemented from ROOT::Math::Minimizer.
Definition at line 125 of file BasicMinimizer.cxx.
set the values of all existing variables (array must be dimensioned to the size of existing parameters)
Reimplemented from ROOT::Math::Minimizer.
Definition at line 133 of file BasicMinimizer.cxx.
|
inlineinherited |
Status code of minimizer.
Definition at line 327 of file Minimizer.h.
|
inlinevirtualinherited |
accessor methods
Definition at line 140 of file BasicMinimizer.h.
|
inlineinherited |
Strategy.
Definition at line 324 of file Minimizer.h.
|
inlineinherited |
Absolute tolerance.
Definition at line 317 of file Minimizer.h.
|
overridevirtualinherited |
get index of variable given a variable given a name return -1 if variable is not found
Reimplemented from ROOT::Math::Minimizer.
Definition at line 232 of file BasicMinimizer.cxx.
|
overridevirtualinherited |
get name of variables (override if minimizer support storing of variable names)
Reimplemented from ROOT::Math::Minimizer.
Definition at line 227 of file BasicMinimizer.cxx.
|
inlineoverridevirtualinherited |
return pointer to X values at the minimum
Implements ROOT::Math::Minimizer.
Definition at line 118 of file BasicMinimizer.h.
|
privateinherited |
map specifying the bound using as key the parameter index
Definition at line 166 of file BasicMinimizer.h.
|
private |
covariant matrix
Definition at line 39 of file RMinimizer.h.
|
privateinherited |
Definition at line 157 of file BasicMinimizer.h.
|
private |
vector of parameter errors
Definition at line 38 of file RMinimizer.h.
|
private |
Hessian matrix.
Definition at line 40 of file RMinimizer.h.
|
protected |
minimizer method to be used, must be of a type listed in R optim or optimx descriptions
Definition at line 35 of file RMinimizer.h.
|
privateinherited |
Definition at line 161 of file BasicMinimizer.h.
|
privateinherited |
Definition at line 164 of file BasicMinimizer.h.
|
privateinherited |
Definition at line 159 of file BasicMinimizer.h.
|
protectedinherited |
minimizer options
Definition at line 387 of file Minimizer.h.
|
protectedinherited |
status of minimizer
Definition at line 388 of file Minimizer.h.
|
privateinherited |
Definition at line 163 of file BasicMinimizer.h.
|
protectedinherited |
flag to control if errors have been validated (Hesse has been run in case of Minuit)
Definition at line 386 of file Minimizer.h.
|
privateinherited |
Definition at line 162 of file BasicMinimizer.h.
|
privateinherited |
vector specifying the type of variables
Definition at line 165 of file BasicMinimizer.h.