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