22 return (*gFunction)(x.data());
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;
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))");
120 r.
Execute(
"errors<-sqrt(abs(diag(cov)))");
126 r.
Execute(
"hess<-result$hessian");
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;
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
const ROOT::Math::IMultiGradFunction * gGradFunction
function wrapper for the gradient of the function to be minimized
virtual const double * X() const
return pointer to X values at the minimum
void Execute(const TString &code)
Method to eval R code.
Namespace for new ROOT classes and functions.
RMinimizer(Option_t *method)
Default constructor.
TMatrixD fCovMatrix
covariant matrix
std::string fMethod
minimizer method to be used, must be of a type listed in R optim or optimx descriptions ...
std::vector< double > fErrors
vector of parameter errors
virtual void Gradient(const double *x, double *grad) const
Evaluate all the vector of function derivatives (gradient) at a point x.
virtual double MinValue() const
return minimum function value
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...
int PrintLevel() const
minimizer configuration parameters
virtual bool Minimize()
Function to find the minimum.
virtual const double * StepSizes() const
accessor methods
virtual unsigned int NCalls() const
Returns the number of function calls.
int gNCalls
integer for the number of function calls
double HessMatrix(unsigned int i, unsigned int j) const
Returns the ith jth component of the Hessian matrix.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
void SetMinValue(double val)
unsigned int MaxIterations() const
max iterations
virtual unsigned int NDim() const
number of dimensions
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
double Tolerance() const
absolute tolerance
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 ...
Element * GetMatrixArray()
Documentation for the abstract class IBaseFunctionMultiDim.
const ROOT::Math::IMultiGenFunction * gFunction
function wrapper for the function to be minimized
void SetFinalValues(const double *x)
Int_t GetNoElements() const
TMatrixD fHessMatrix
Hessian matrix.
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported) ...
static TRInterface & Instance()
static method to get an TRInterface instance reference
TVectorD mingradfunction(TVectorD y)
function to return the gradient values at point y
Namespace for new Math classes and functions.
you should not use this method at all Int_t Int_t z
double minfunction(const std::vector< double > &x)
function to return the function values at point x
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.
This is a class to pass functions from ROOT to R
const char * Data() const