ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RMinimizer.h
Go to the documentation of this file.
1 // Author: K. Hermansen and L. Moneta, Aug 2014
2 
3 // Implementation file for class RMinimizer
4 
5 #ifndef ROOT_Math_RMinimizer
6 #define ROOT_Math_RMinimizer
7 
8 
9 #ifndef ROOT_Math_Functor
10 #include "Math/Functor.h"
11 #endif
12 
13 #ifndef ROOT_Math_IParamFunctionfwd
14 #include "Math/IParamFunctionfwd.h"
15 #endif
16 
17 #ifndef ROOT_Math_BasicMinimizer
18 #include "Math/BasicMinimizer.h"
19 #endif
20 
21 #ifndef ROOT_TMatrixD
22 #include "TMatrixD.h"
23 #endif
24 
25 namespace ROOT {
26  namespace Math{
27 
28  /*! \brief RMinimizer class.
29  *
30  * Minimizer class that uses the ROOT/R interface to pass functions and minimize them in R.
31  *
32  * The class implements the ROOT::Math::Minimizer interface and can be instantiated using the
33  * ROOT plugin manager (plugin name is "RMinimizer"). The various minimization algorithms
34  * (BFGS, Nelder-Mead, SANN, etc..) can be passed as an option.
35  * The default algorithm is BFGS.
36  *
37  * The library for this and future R/ROOT classes is currently libRtools.so
38  */
40  protected:
41  std::string fMethod; /*!< minimizer method to be used, must be of a type listed in R optim or optimx descriptions */
42 
43  private:
44  std::vector<double> fErrors; /*!< vector of parameter errors */
45  TMatrixD fCovMatrix; /*!< covariant matrix */
46  TMatrixD fHessMatrix; /*!< Hessian matrix */
47 
48  public:
49  /*! \brief Default constructor
50  *
51  * Default constructor with option for the method of minimization, can be any of the following:
52  *"Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent" (Brent only for 1D minimization)
53  *
54  *See R optim or optimx descriptions for more details and options.
55  *
56  */
57  RMinimizer(Option_t *method);
58  ///Destructor
59  virtual ~RMinimizer() {}
60  ///Function to find the minimum
61  virtual bool Minimize();
62  ///Returns the number of function calls
63  virtual unsigned int NCalls() const;
64  ///Returns the ith jth component of the Hessian matrix
65  double HessMatrix(unsigned int i, unsigned int j) const;
66  /// minimizer provides error and error matrix
67  virtual bool ProvidesError() const { return !(fErrors.empty()); }
68  /// return errors at the minimum
69  virtual const double * Errors() const { return fErrors.data(); }
70  /** return covariance matrices element for variables ivar,jvar
71  if the variable is fixed the return value is zero
72  The ordering of the variables is the same as in the parameter and errors vectors
73  */
74  virtual double CovMatrix(unsigned int ivar , unsigned int jvar ) const {
75  return fCovMatrix(ivar, jvar);
76  }
77  /**
78  Fill the passed array with the covariance matrix elements
79  if the variable is fixed or const the value is zero.
80  The array will be filled as cov[i *ndim + j]
81  The ordering of the variables is the same as in errors and parameter value.
82  This is different from the direct interface of Minuit2 or TMinuit where the
83  values were obtained only to variable parameters
84  */
85  virtual bool GetCovMatrix(double * covMat) const {
86  int ndim = NDim();
87  if (fCovMatrix.GetNrows() != ndim || fCovMatrix.GetNcols() != ndim ) return false;
88  std::copy(fCovMatrix.GetMatrixArray(), fCovMatrix.GetMatrixArray() + ndim*ndim, covMat);
89  return true;
90  }
91  };
92 
93  }
94 }
95 #endif
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 ...
Definition: RMinimizer.h:74
RMinimizer(Option_t *method)
Default constructor.
Definition: RMinimizer.cxx:38
const char Option_t
Definition: RtypesCore.h:62
TMatrixD fCovMatrix
covariant matrix
Definition: RMinimizer.h:45
std::string fMethod
minimizer method to be used, must be of a type listed in R optim or optimx descriptions ...
Definition: RMinimizer.h:41
virtual unsigned int NCalls() const
Returns the number of function calls.
Definition: RMinimizer.cxx:44
std::vector< double > fErrors
vector of parameter errors
Definition: RMinimizer.h:44
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
virtual ~RMinimizer()
Destructor.
Definition: RMinimizer.h:59
virtual bool Minimize()
Function to find the minimum.
Definition: RMinimizer.cxx:47
virtual const double * Errors() const
return errors at the minimum
Definition: RMinimizer.h:69
Int_t GetNrows() const
Definition: TMatrixTBase.h:134
virtual unsigned int NDim() const
number of dimensions
virtual const Element * GetMatrixArray() const
Definition: TMatrixT.h:222
TMatrixD fHessMatrix
Hessian matrix.
Definition: RMinimizer.h:46
Int_t GetNcols() const
Definition: TMatrixTBase.h:137
double HessMatrix(unsigned int i, unsigned int j) const
Returns the ith jth component of the Hessian matrix.
virtual bool GetCovMatrix(double *covMat) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
Definition: RMinimizer.h:85
RMinimizer class.
Definition: RMinimizer.h:39
virtual bool ProvidesError() const
minimizer provides error and error matrix
Definition: RMinimizer.h:67