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 ~RMinimizer() override {}
54 ///Function to find the minimum
55 bool Minimize() override;
56 ///Returns the number of function calls
57 unsigned int NCalls() const override;
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 bool ProvidesError() const override { return !(fErrors.empty()); }
62 /// return errors at the minimum
63 const double * Errors() const override { 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 double CovMatrix(unsigned int ivar , unsigned int jvar ) const override {
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 bool GetCovMatrix(double * covMat) const override {
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 functionality of various minimizer implementations (apa...
unsigned int NDim() const override
number of dimensions
RMinimizer class.
Definition RMinimizer.h:33
const double * Errors() const override
return errors at the minimum
Definition RMinimizer.h:63
double HessMatrix(unsigned int i, unsigned int j) const
Returns the ith jth component of the Hessian matrix.
bool GetCovMatrix(double *covMat) const override
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
Definition RMinimizer.h:79
~RMinimizer() override
Destructor.
Definition RMinimizer.h:53
TMatrixD fCovMatrix
covariant matrix
Definition RMinimizer.h:39
std::vector< double > fErrors
vector of parameter errors
Definition RMinimizer.h:38
bool Minimize() override
Function to find the minimum.
std::string fMethod
minimizer method to be used, must be of a type listed in R optim or optimx descriptions
Definition RMinimizer.h:35
bool ProvidesError() const override
minimizer provides error and error matrix
Definition RMinimizer.h:61
unsigned int NCalls() const override
Returns the number of function calls.
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 ...
Definition RMinimizer.h:68
TMatrixD fHessMatrix
Hessian matrix.
Definition RMinimizer.h:40
Int_t GetNrows() const
Int_t GetNcols() const
const Element * GetMatrixArray() const override
Definition TMatrixT.h:225
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...