Logo ROOT  
Reference Guide
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
12
13#include "Math/BasicMinimizer.h"
14
15#include "TMatrixD.h"
16
17namespace 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 */
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
const char Option_t
Definition: RtypesCore.h:64
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
virtual unsigned int NDim() const
number of dimensions
RMinimizer class.
Definition: RMinimizer.h:31
double HessMatrix(unsigned int i, unsigned int j) const
Returns the ith jth component of the Hessian matrix.
virtual const double * Errors() const
return errors at the minimum
Definition: RMinimizer.h:61
virtual unsigned int NCalls() const
Returns the number of function calls.
Definition: RMinimizer.cxx:44
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:66
virtual ~RMinimizer()
Destructor.
Definition: RMinimizer.h:51
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:77
TMatrixD fCovMatrix
covariant matrix
Definition: RMinimizer.h:37
std::vector< double > fErrors
vector of parameter errors
Definition: RMinimizer.h:36
std::string fMethod
minimizer method to be used, must be of a type listed in R optim or optimx descriptions
Definition: RMinimizer.h:33
RMinimizer(Option_t *method)
Default constructor.
Definition: RMinimizer.cxx:38
virtual bool ProvidesError() const
minimizer provides error and error matrix
Definition: RMinimizer.h:59
TMatrixD fHessMatrix
Hessian matrix.
Definition: RMinimizer.h:38
virtual bool Minimize()
Function to find the minimum.
Definition: RMinimizer.cxx:47
Int_t GetNrows() const
Definition: TMatrixTBase.h:124
Int_t GetNcols() const
Definition: TMatrixTBase.h:127
virtual const Element * GetMatrixArray() const
Definition: TMatrixT.h:222
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21