61 if (niter <=0 ) niter = 1000;
69 std::string algoname(
type);
70 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (
int(*)(
int)) tolower );
87 if (niter <=0 ) niter = 1000;
117 if (fnumgrad)
return fnumgrad->
NCalls();
121 if (ffitmethod)
return ffitmethod->
NCalls();
132 MATH_ERROR_MSG(
"GSLMinimizer::Minimize",
"Function has not been set");
136 unsigned int npar =
NPar();
137 unsigned int ndim =
NDim();
138 if (npar == 0 || npar <
NDim() ) {
143 MATH_WARN_MSGVAL(
"GSLMinimizer::Minimize",
"number of parameters larger than function dimension - ignore extra parameters",npar);
146 const double eps = std::numeric_limits<double>::epsilon();
148 std::vector<double> startValues;
154 trFunc->InvStepTransformation(
X(),
StepSizes(), &steps[0]);
155 steps.resize(trFunc->NDim());
160 MATH_INFO_MSG(
"GSLMinimizer::Minimize",
"There are no free parameter - just compute the function value");
161 double fval = (*function)((
double*)
nullptr);
170 for (
unsigned int i = 0; i < steps.size(); ++i)
171 stepSize += steps[i]*steps[i];
172 stepSize = std::sqrt(stepSize);
173 if (stepSize < eps) {
184 if (debugLevel >=1 ) std::cout <<
"Minimize using GSLMinimizer " <<
fGSLMultiMin->
Name() << std::endl;
191 unsigned int iter = 0;
193 bool minFound =
false;
194 bool iterFailed =
false;
207 if (debugLevel >=2) {
208 std::cout <<
"----------> Iteration " << std::setw(4) << iter;
209 int pr = std::cout.precision(18);
211 std::cout.precision(pr);
212 if (debugLevel >=3) {
213 std::cout <<
" Parameter Values : ";
215 std::cout << std::endl;
217 xtmp = trFunc->Transformation(xtmp);
219 for (
unsigned int i = 0; i <
NDim(); ++i) {
220 std::cout <<
" " <<
VariableName(i) <<
" = " << xtmp[i];
224 std::cout << std::endl;
238 if (
x ==
nullptr)
return false;
248 if (debugLevel >=1 ) {
249 std::cout <<
"GSLMinimizer: Minimum Found" << std::endl;
250 int pr = std::cout.precision(18);
251 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
252 std::cout.precision(pr);
254 std::cout <<
"Niterations = " << iter << std::endl;
255 unsigned int ncalls =
NCalls();
256 if (ncalls) std::cout <<
"NCalls = " << ncalls << std::endl;
257 for (
unsigned int i = 0; i <
NDim(); ++i)
258 std::cout <<
VariableName(i) <<
"\t = " <<
X()[i] << std::endl;
263 if (debugLevel > 0 ) {
264 std::cout <<
"GSLMinimizer: Minimization did not converge" << std::endl;
266 if (status == GSL_ENOPROG)
267 std::cout <<
"\t Iteration is not making progress towards solution" << std::endl;
269 std::cout <<
"\t Iteration failed with status " << status << std::endl;
271 if (debugLevel >= 1) {
274 for (
unsigned int i = 0; i <
NDim(); ++i) dg2 +=
g[i] *
g[1];
275 std::cout <<
"Grad module is " << std::sqrt(dg2) << std::endl;
276 for (
unsigned int i = 0; i <
NDim(); ++i)
277 std::cout <<
VariableName(i) <<
"\t = " <<
X()[i] << std::endl;
278 std::cout <<
"FVAL = " <<
MinValue() << std::endl;
279 std::cout <<
"Niterations = " << iter << std::endl;
#define MATH_INFO_MSG(loc, str)
Pre-processor macro to report messages which can be configured to use ROOT error or simply an std::io...
#define MATH_ERROR_MSGVAL(loc, txt, x)
#define MATH_ERROR_MSG(loc, str)
#define MATH_WARN_MSGVAL(loc, txt, x)
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 NCalls() const
return the total number of function calls (override if needed)
Base Minimizer class, which defines the basic functionality of various minimizer implementations (apa...
virtual unsigned int NPar() const
total number of parameter defined
unsigned int NFree() const override
number of free variables (real dimension of the problem)
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)
virtual const double * StepSizes() const
accessor methods
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 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
std::string VariableName(unsigned int ivar) const override
get name of variables (override if minimizer support storing of variable names)
const double * MinGradient() const override
return pointer to gradient values at the minimum
ROOT::Math::GSLMultiMinimizer * fGSLMultiMin
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
~GSLMinimizer() override
Destructor.
unsigned int NCalls() const override
number of function calls to reach the minimum
GSLMinimizer(ROOT::Math::EGSLMinimizerType type=ROOT::Math::kConjugateFR)
Default constructor.
bool Minimize() override
method to perform the minimization
GSLMultiMinimizer class , for minimizing multi-dimensional function using derivatives.
int Set(const ROOT::Math::IMultiGradFunction &func, const double *x, double stepSize, double tol)
set the function to be minimize the initial minimizer parameters, step size and tolerance in the line...
double Minimum() const
function value at the minimum
double * Gradient() const
gradient value at the minimum
double * X() const
x values at the minimum
int TestGradient(double absTol) const
test gradient (ask from minimizer gradient vector)
Documentation for the abstract class IBaseFunctionMultiDim.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
static int DefaultPrintLevel()
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
MultiNumGradFunction class to wrap a normal function in a gradient function using numerical gradient ...
unsigned int NCalls() const
EGSLMinimizerType
enumeration specifying the types of GSL minimizers
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...