27 const double * yy =
y.GetMatrixArray();
62 std::vector<double> values(
X(),
X()+
NDim());
65 r[
"stepsizes"] = stepSizes;
66 r[
"initialparams"] = values;
69 bool optimxloaded =
FALSE;
70 r[
"optimxloaded"] = optimxloaded;
71 r.Execute(
"optimxloaded<-library(optimx,logical.return=TRUE)");
73 int ibool =
r.Eval(
"optimxloaded");
74 if (ibool==1) optimxloaded=
kTRUE;
80 if (optimxloaded==
kTRUE) {
83 cmd =
TString::Format(
"result <- optimx( initialparams, minfunction,method='%s',control = list(ndeps=stepsizes,maxit=%d,trace=%d,abstol=%e),hessian=TRUE)",
fMethod.c_str(),
MaxIterations(),
PrintLevel(),
Tolerance());
87 cmd =
TString::Format(
"result <- optimx( initialparams, minfunction,mingradfunction, method='%s', control = list(ndeps=stepsizes,maxit=%d,trace=%d,abstol=%e),hessian=TRUE)",
fMethod.c_str(),
MaxIterations(),
PrintLevel(),
Tolerance());
96 cmd =
TString::Format(
"result <- optim( initialparams, minfunction,method='%s',control = list(ndeps=stepsizes,maxit=%d,trace=%d,abstol=%e),hessian=TRUE)",
fMethod.c_str(),
MaxIterations(),
PrintLevel(),
Tolerance());
100 cmd =
TString::Format(
"result <- optim( initialparams, minfunction,mingradfunction, method='%s', control = list(ndeps=stepsizes,maxit=%d,trace=%d,abstol=%e),hessian=TRUE)",
fMethod.c_str(),
MaxIterations(),
PrintLevel(),
Tolerance());
104 std::cout <<
"Calling R with command " << cmd << std::endl;
105 r.Execute(cmd.
Data());
110 r.Execute(
"par<-coef(result)");
112 r.Execute(
"hess<-attr(result,\"details\")[,\"nhatend\"]");
114 r.Execute(
"hess<-sapply(hess,function(x) x)");
116 r.Execute(
"hess<-matrix(hess,c(ndim,ndim))");
118 r.Execute(
"cov<-solve(hess)");
120 r.Execute(
"errors<-sqrt(abs(diag(cov)))");
125 r.Execute(
"par<-result$par");
126 r.Execute(
"hess<-result$hessian");
127 r.Execute(
"cov<-solve(hess)");
128 r.Execute(
"errors<-sqrt(abs(diag(cov)))");
133 std::vector<double> vectorPar =
r[
"par"];
141 std::vector<double> err =
r[
"errors"];
155 const double *min=vectorPar.data();
158 std::cout<<
"Value at minimum ="<<
MinValue()<<std::endl;
165 unsigned int ndim =
NDim();
167 if (i > ndim || j > ndim)
return 0;
176 unsigned int ndim =
NDim();
178 if (i > ndim || j > ndim)
return 0;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
unsigned int NDim() const override
number of dimensions
void SetMinValue(double val)
void SetFinalValues(const double *x, const MinimTransformFunction *func=nullptr)
double MinValue() const override
return minimum function value
virtual const double * StepSizes() const
accessor methods
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
const double * X() const override
return pointer to X values at the minimum
Documentation for the abstract class IBaseFunctionMultiDim.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
virtual void Gradient(const T *x, T *grad) const
Evaluate all the vector of function derivatives (gradient) at a point x.
double Tolerance() const
absolute tolerance
unsigned int MaxIterations() const
max iterations
int PrintLevel() const
minimizer configuration parameters
double HessMatrix(unsigned int i, unsigned int j) const
Returns the ith jth component of the Hessian matrix.
TMatrixD fCovMatrix
covariant matrix
std::vector< double > fErrors
vector of parameter errors
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
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 ...
RMinimizer(Option_t *method)
Default constructor.
TMatrixD fHessMatrix
Hessian matrix.
This is a class to pass functions from ROOT to R.
ROOT R was implemented using the R Project library and the modules Rcpp and RInside
static TRInterface & Instance()
static method to get an TRInterface instance reference
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Int_t GetNoElements() const
Namespace for new Math classes and functions.
const ROOT::Math::IMultiGenFunction * gFunction
function wrapper for the function to be minimized
double minfunction(const std::vector< double > &x)
function to return the function values at point x
TVectorD mingradfunction(TVectorD y)
function to return the gradient values at point y
const ROOT::Math::IMultiGradFunction * gGradFunction
function wrapper for the gradient of the function to be minimized
int gNCalls
integer for the number of function calls
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.