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