20#include "gsl/gsl_errno.h"
58 virtual double DataElement(
const double *
x,
unsigned i,
double *
g =
nullptr,
double * =
nullptr,
bool =
false)
const {
61 if (
g ==
nullptr)
return fFunc.DataElement(
xExt, i );
76 virtual unsigned int NDim()
const {
80 unsigned int NTot()
const {
105 virtual double DoEval(
const double *
x)
const {
111 throw std::runtime_error(
"FitTransformFunction::DoDerivative");
169 unsigned int NDim()
const override {
return fChi2->NDim(); }
171 void Gradient(
const double *
x,
double *
g)
const override {
176 void FdF (
const double *
x,
double &
f,
double *
g)
const override {
189 double DoEval (
const double *
x)
const override {
195 throw std::runtime_error(
"LSRESidualFunc::DoDerivative");
250 MATH_ERROR_MSG(
"GSLNLSMinimizer::Minimize",
"Function has not been set");
257 if (
PrintLevel() > 0) std::cout <<
"GSLNLSMinimizer: Invalid function set - only FitMethodFunction types are supported" << std::endl;
282 unsigned int ndim =
NDim();
293 std::unique_ptr<MinimTransformFunction>
trFuncRaw;
303 std::unique_ptr<FitTransformFunction<Func>>
trFunc;
317 if (
debugLevel >=1 ) std::cout <<
"Minimize using GSLNLSMinimizer " << std::endl;
330 unsigned int iter = 0;
337 std::cout <<
"----------> Iteration " << iter <<
" / " <<
MaxIterations() <<
" status " <<
gsl_strerror(status) << std::endl;
340 int pr = std::cout.precision(18);
341 std::cout <<
" FVAL = " << (
fitFunc)(
x) << std::endl;
342 std::cout.precision(
pr);
343 std::cout <<
" X Values : ";
344 for (
unsigned int i = 0; i <
NDim(); ++i)
346 std::cout << std::endl;
370 std::cout <<
" after Gradient and Delta tests: " <<
gsl_strerror(status);
371 if (
fEdm > 0) std::cout <<
", edm is: " <<
fEdm;
372 std::cout << std::endl;
388 if (
x ==
nullptr)
return false;
412 for (
unsigned int i = 0; i < ndim; ++i)
419 std::cout <<
"GSLNLSMinimizer: Minimum Found" << std::endl;
420 int pr = std::cout.precision(18);
421 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
422 std::cout <<
"Edm = " <<
fEdm << std::endl;
423 std::cout.precision(
pr);
424 std::cout <<
"NIterations = " << iter << std::endl;
425 std::cout <<
"NFuncCalls = " <<
fitFunc.NCalls() << std::endl;
426 for (
unsigned int i = 0; i <
NDim(); ++i)
427 std::cout << std::setw(12) <<
VariableName(i) <<
" = " << std::setw(12) <<
X()[i] <<
" +/- " << std::setw(12) <<
fErrors[i] << std::endl;
434 std::cout <<
"GSLNLSMinimizer: Minimization did not converge: " << std::endl;
436 std::cout <<
"\t iteration is not making progress towards solution" << std::endl;
438 std::cout <<
"\t failed with status " << status << std::endl;
441 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
443 std::cout <<
"Niterations = " << iter << std::endl;
458 unsigned int ndim =
NDim();
460 if (i > ndim ||
j > ndim)
return 0;
#define MATH_ERROR_MSGVAL(loc, txt, x)
#define MATH_ERROR_MSG(loc, str)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
virtual unsigned int NPar() const
total number of parameter defined
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
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=nullptr)
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
const double * X() const override
return pointer to X values at the minimum
std::string VariableName(unsigned int ivar) const override
get name of variables (override if minimizer support storing of variable names)
GSLMultiFit, internal class for implementing GSL non linear least square GSL fitting.
int TestGradient(double absTol) const
test gradient (ask from solver gradient vector)
int TestDelta(double absTol, double relTol) const
test using abs and relative tolerance |dx| < absTol + relTol*|x| for every component
const double * Gradient() const
gradient value at the minimum
const double * CovarMatrix() const
return covariance matrix of the parameters
const double * X() const
parameter values at the minimum
int Set(const std::vector< Func > &funcVec, const double *x)
set the solver parameters
double CovMatrix(unsigned int, unsigned int) const override
return covariance matrices elements if the variable is fixed the matrix is zero The ordering of the v...
int CovMatrixStatus() const override
return covariance matrix status
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
std::vector< double > fErrors
std::vector< double > fCovMatrix
~GSLNLSMinimizer() override
Destructor (no operations)
bool DoMinimize(const Func &f)
Internal method to perform minimization template on the type of method function.
bool Minimize() override
method to perform the minimization
GSLNLSMinimizer(int type=0)
Default constructor.
const double * MinGradient() const override
return pointer to gradient values at the minimum
ROOT::Math::GSLMultiFit * fGSLMultiFit
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool HasGradient() const
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
LSResidualFunc class description.
double DoEval(const double *x) const override
LSResidualFunc< Func > & operator=(const LSResidualFunc< Func > &rhs)
void FdF(const double *x, double &f, double *g) const override
LSResidualFunc(const LSResidualFunc< Func > &rhs)
void Gradient(const double *x, double *g) const override
double DoDerivative(const double *, unsigned int) const override
LSResidualFunc(const Func &func, unsigned int i)
IMultiGenFunction * Clone() const override
Clone a function.
unsigned int NDim() const override
Retrieve the dimension of the function.
static int DefaultPrintLevel()
static double DefaultTolerance()
static int DefaultMaxIterations()
double Tolerance() const
absolute tolerance
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
int fStatus
status of minimizer
unsigned int MaxIterations() const
max iterations
void SetPrintLevel(int level)
set print level
int PrintLevel() const
minimizer configuration parameters
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...