26 unsigned int size =
y.GetNoElements();
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;
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))");
120 r.
Execute(
"errors<-sqrt(abs(diag(cov)))");
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;
virtual double MinValue() const
return minimum function value
void SetMinValue(double val)
virtual const double * StepSizes() const
accessor methods
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
virtual unsigned int NDim() const
number of dimensions
virtual const double * X() const
return pointer to X values at the minimum
void SetFinalValues(const double *x)
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
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.
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 ...
TMatrixD fCovMatrix
covariant matrix
std::vector< double > fErrors
vector of parameter errors
std::string fMethod
minimizer method to be used, must be of a type listed in R optim or optimx descriptions
RMinimizer(Option_t *method)
Default constructor.
TMatrixD fHessMatrix
Hessian matrix.
virtual bool Minimize()
Function to find the minimum.
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
void Execute(const TString &code)
Method to eval R code.
static TRInterface & Instance()
static method to get an TRInterface instance reference
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
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.
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static constexpr double cm