Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::Math::RMinimizer Class Reference

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.
 
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
 
const doubleErrors () const override
 return errors at the minimum
 
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.
 
double HessMatrix (unsigned int i, unsigned int j) const
 Returns the ith jth component of the Hessian matrix.
 
bool Minimize () override
 Function to find the minimum.
 
unsigned int NCalls () const override
 Returns the number of function calls.
 
bool ProvidesError () const override
 minimizer provides error and error matrix
 
- Public Member Functions inherited from ROOT::Math::BasicMinimizer
 BasicMinimizer ()
 Default constructor.
 
 ~BasicMinimizer () override
 Destructor.
 
bool FixVariable (unsigned int ivar) override
 fix an existing variable
 
bool GetVariableSettings (unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const override
 get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
 
const ROOT::Math::IMultiGradFunctionGradObjFunction () const
 return pointer to used gradient object function (NULL if gradient is not supported)
 
bool IsFixedVariable (unsigned int ivar) const override
 query if an existing variable is fixed (i.e.
 
double MinValue () const override
 return minimum function value
 
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 NPar () const
 total number of parameter defined
 
const ROOT::Math::IMultiGenFunctionObjFunction () const
 return pointer to used objective function
 
void PrintResult () const
 print result of minimization
 
bool ReleaseVariable (unsigned int ivar) override
 release an existing variable
 
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
 
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 )
 
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 )
 
bool SetVariable (unsigned int ivar, const std::string &name, double val, double step) override
 set free 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
 
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)
 
virtual const doubleStepSizes () const
 accessor methods
 
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 doubleX () const override
 return pointer to X values at the minimum
 
- Public Member Functions inherited from ROOT::Math::Minimizer
 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 The contour will be find for value of the function = Min + ErrorUp();
 
virtual double Correlation (unsigned int i, unsigned int j) const
 return correlation coefficient between variable i and j.
 
virtual int CovMatrixStatus () const
 return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made pos def , 3 accurate} Minimizer who implements covariance matrix calculation will re-implement the method
 
virtual double Edm () const
 return expected distance reached from the minimum (re-implement if minimizer provides it
 
double ErrorDef () const
 return the statistical scale used for calculate the error is typically 1 for Chi2 and 0.5 for likelihood minimization
 
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 double GlobalCC (unsigned int ivar) const
 return global correlation coefficient for variable i This is a number between zero and one which gives the correlation between the i-th parameter and that linear combination of all other parameters which is most strongly correlated with i.
 
virtual bool Hesse ()
 perform a full calculation of the Hessian matrix for error calculation
 
bool IsValidError () const
 return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit)
 
unsigned int MaxFunctionCalls () const
 max number of function calls
 
unsigned int MaxIterations () const
 max iterations
 
virtual const doubleMinGradient () const
 return pointer to gradient values at the minimum
 
virtual int MinosStatus () const
 status code of Minos (to be re-implemented by the minimizers supporting Minos)
 
virtual unsigned int NIterations () const
 number of iterations to reach the minimum
 
Minimizeroperator= (Minimizer &&)=delete
 
Minimizeroperator= (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 ( a value <=0 corresponds to the let the minimizer choose its default one)
 
int PrintLevel () const
 minimizer configuration parameters
 
virtual void PrintResults ()
 return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const = 0;
 
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 void SetHessianFunction (std::function< bool(std::span< const double >, double *)>)
 set the function implementing Hessian computation (re-implemented by Minimizer using it)
 
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 ( a value <=0 means the minimizer will choose its optimal value automatically, i.e.
 
void SetPrintLevel (int level)
 set print level
 
void SetStrategy (int strategyLevel)
 set the strategy
 
void SetTolerance (double tol)
 set the tolerance
 
void SetValidError (bool on)
 flag to check if minimizer needs to perform accurate error analysis (e.g. run Hesse for Minuit)
 
virtual bool SetVariableInitialRange (unsigned int, double, double)
 set the initial range of an existing variable
 
template<class VariableIterator >
int SetVariables (const VariableIterator &begin, const VariableIterator &end)
 add variables . Return number of variables successfully added
 
int Status () const
 status code of minimizer
 
int Strategy () const
 strategy
 
double Tolerance () const
 absolute tolerance
 

Protected Attributes

std::string fMethod
 minimizer method to be used, must be of a type listed in R optim or optimx descriptions
 
- Protected Attributes inherited from ROOT::Math::Minimizer
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

TMatrixD fCovMatrix
 covariant matrix
 
std::vector< doublefErrors
 vector of parameter errors
 
TMatrixD fHessMatrix
 Hessian matrix.
 

Additional Inherited Members

- Protected Member Functions inherited from ROOT::Math::BasicMinimizer
bool CheckDimension () const
 
bool CheckObjFunction () const
 
MinimTransformFunctionCreateTransformation (std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=nullptr)
 
void SetFinalValues (const double *x, const MinimTransformFunction *func=nullptr)
 
void SetMinValue (double val)
 

#include <Math/RMinimizer.h>

Inheritance diagram for ROOT::Math::RMinimizer:
[legend]

Constructor & Destructor Documentation

◆ RMinimizer()

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 38 of file RMinimizer.cxx.

◆ ~RMinimizer()

ROOT::Math::RMinimizer::~RMinimizer ( )
inlineoverride

Destructor.

Definition at line 53 of file RMinimizer.h.

Member Function Documentation

◆ CovMatrix()

double ROOT::Math::RMinimizer::CovMatrix ( unsigned int  ivar,
unsigned int  jvar 
) const
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.

◆ Errors()

const double * ROOT::Math::RMinimizer::Errors ( ) const
inlineoverridevirtual

return errors at the minimum

Reimplemented from ROOT::Math::Minimizer.

Definition at line 63 of file RMinimizer.h.

◆ GetCovMatrix()

bool ROOT::Math::RMinimizer::GetCovMatrix ( double covMat) const
inlineoverridevirtual

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.

◆ HessMatrix()

double ROOT::Math::RMinimizer::HessMatrix ( unsigned int  i,
unsigned int  j 
) const

Returns the ith jth component of the Hessian matrix.

◆ Minimize()

bool ROOT::Math::RMinimizer::Minimize ( )
overridevirtual

Function to find the minimum.

function for finding the minimum

Reimplemented from ROOT::Math::BasicMinimizer.

Definition at line 47 of file RMinimizer.cxx.

◆ NCalls()

unsigned int ROOT::Math::RMinimizer::NCalls ( ) const
overridevirtual

Returns the number of function calls.

returns number of function calls

Reimplemented from ROOT::Math::Minimizer.

Definition at line 44 of file RMinimizer.cxx.

◆ ProvidesError()

bool ROOT::Math::RMinimizer::ProvidesError ( ) const
inlineoverridevirtual

minimizer provides error and error matrix

Reimplemented from ROOT::Math::Minimizer.

Definition at line 61 of file RMinimizer.h.

Member Data Documentation

◆ fCovMatrix

TMatrixD ROOT::Math::RMinimizer::fCovMatrix
private

covariant matrix

Definition at line 39 of file RMinimizer.h.

◆ fErrors

std::vector<double> ROOT::Math::RMinimizer::fErrors
private

vector of parameter errors

Definition at line 38 of file RMinimizer.h.

◆ fHessMatrix

TMatrixD ROOT::Math::RMinimizer::fHessMatrix
private

Hessian matrix.

Definition at line 40 of file RMinimizer.h.

◆ fMethod

std::string ROOT::Math::RMinimizer::fMethod
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.

Libraries for ROOT::Math::RMinimizer:

The documentation for this class was generated from the following files: