22#include "gsl/gsl_errno.h"
39template <
class FMFunc>
53 virtual double DataElement(
const double *
x,
unsigned i,
double *
g =
nullptr,
double * =
nullptr,
bool =
false)
const
77 virtual typename FMFunc::Type_t
Type()
const {
return fFunc.Type(); }
112 throw std::runtime_error(
"FitTransformFunction::DoDerivative");
155 unsigned int NDim()
const override {
return fChi2->NDim(); }
173 throw std::runtime_error(
"LSRESidualFunc::DoDerivative");
186 if (
tName ==
"lms_old")
188 if (
tName ==
"lm_old")
190 if (
tName ==
"trust")
192 if (
tName ==
"trust_lm")
194 if (
tName ==
"trust_lmaccel")
196 if (
tName ==
"trust_dogleg")
198 if (
tName ==
"trust_ddogleg")
200 if (
tName ==
"trust_subspace2D" ||
tName ==
"trust_2D")
272 MATH_ERROR_MSG(
"GSLNLSMinimizer::Minimize",
"Function has not been set");
281 std::cout <<
"GSLNLSMinimizer: Invalid function set - only FitMethodFunction types are supported" << std::endl;
313template <
class Func,
class FitterType>
327 unsigned int ndim =
NDim();
338 std::unique_ptr<MinimTransformFunction>
trFuncRaw;
347 std::unique_ptr<FitTransformFunction<Func>>
trFunc;
362 std::cout <<
"Minimize using GSLNLSMinimizer " << std::endl;
373 unsigned int iter = 0;
378 std::cout <<
"GSLNLSMinimizer: " <<
fGSLMultiFit->
Name() <<
" - start iterating......... " << std::endl;
382 status = fitter->Iterate();
385 std::cout <<
"----------> Iteration " << iter <<
" / " <<
MaxIterations() <<
" status "
387 const double *
x = fitter->X();
390 int pr = std::cout.precision(18);
391 std::cout <<
" FVAL = " << (
fitFunc)(
x) << std::endl;
392 std::cout.precision(
pr);
393 std::cout <<
" X Values : ";
394 for (
unsigned int i = 0; i <
NDim(); ++i)
396 std::cout << std::endl;
412 fEdm = fitter->Edm();
421 std::cout <<
" after Gradient and Delta tests: " <<
gsl_strerror(status);
423 std::cout <<
", edm is: " <<
fEdm;
424 std::cout << std::endl;
432 fEdm = fitter->Edm();
446 const double *
x = fitter->X();
461 const double *
cov = fitter->CovarMatrix();
472 for (
unsigned int i = 0; i < ndim; ++i)
479 std::cout <<
"GSLNLSMinimizer: Minimum Found" << std::endl;
480 int pr = std::cout.precision(18);
481 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
482 std::cout <<
"Edm = " <<
fEdm << std::endl;
483 std::cout.precision(
pr);
484 std::cout <<
"NIterations = " << iter << std::endl;
485 std::cout <<
"NFuncCalls = " <<
fitFunc.NCalls() << std::endl;
486 for (
unsigned int i = 0; i <
NDim(); ++i)
487 std::cout << std::setw(12) <<
VariableName(i) <<
" = " << std::setw(12) <<
X()[i] <<
" +/- "
488 << std::setw(12) <<
fErrors[i] << std::endl;
494 std::cout <<
"GSLNLSMinimizer: Minimization did not converge: " << std::endl;
496 std::cout <<
"\t iteration is not making progress towards solution" << std::endl;
498 std::cout <<
"\t failed with status " << status << std::endl;
501 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
502 std::cout <<
"Edm = " << fitter->Edm() << std::endl;
503 std::cout <<
"Niterations = " << iter << std::endl;
519 unsigned int ndim =
NDim();
522 if (i > ndim ||
j > ndim)
#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)
GSLMultiFit2, internal class for implementing GSL non linear least square GSL fitting New class imple...
void SetParameters(const ROOT::Math::MinimizerOptions &minimOptions)
ROOT::Math::GenAlgoOptions GetDefaultOptions() const
GSLMultiFit, internal class for implementing GSL non linear least square GSL fitting.
const double * Gradient() const
gradient value at the minimum
GSLNLSMinimizer class for Non Linear Least Square fitting It Uses the Levemberg-Marquardt algorithm f...
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)
GSLNLSMinimizer(int type)
Constructor from a type.
bool DoMinimize(const Func &f, FitterType *fitter)
Internal method to perform minimization template on the type of method function.
bool Minimize() override
method to perform the minimization
const double * MinGradient() const override
return pointer to gradient values at the minimum
ROOT::Math::GSLMultiFit * fGSLMultiFit
ROOT::Math::GSLMultiFit2 * fGSLMultiFit2
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()
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
const std::string & MinimizerAlgorithm() const
type of algorithm
static double DefaultTolerance()
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
static int DefaultMaxIterations()
void SetMinimizerAlgorithm(const char *type)
set minimizer algorithm
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.
MinimizerOptions fOptions
minimizer options
int PrintLevel() const
Set print level.
Namespace for new Math classes and functions.
int GetTypeFromName(const char *name)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...