54 if (niter <=0 ) niter = 1000;
67 if (ivar >
fValues.size() )
return false;
81 std::map<unsigned int, std::pair<double, double> >::iterator iter =
fBounds.find(ivar);
92 if (!ret)
return false;
93 const double upper = std::numeric_limits<double>::infinity();
94 fBounds[ivar] = std::make_pair( lower, upper);
101 if (!ret)
return false;
102 const double lower = -std::numeric_limits<double>::infinity();
103 fBounds[ivar] = std::make_pair( lower, upper);
111 if (!ret)
return false;
112 fBounds[ivar] = std::make_pair( lower, upper);
120 if (!ret)
return false;
129 if (ivar >
fValues.size() )
return false;
136 if (x == 0)
return false;
143 if (ivar >
fValues.size() )
return false;
150 double upper = (
fBounds.count(ivar)) ?
fBounds[ivar].
second : std::numeric_limits<double>::infinity();
156 double lower = (
fBounds.count(ivar)) ?
fBounds[ivar].
first : - std::numeric_limits<double>::infinity();
162 if (ivar >
fVarTypes.size() )
return false;
164 fBounds[ivar] = std::make_pair( lower, upper);
165 if (lower > upper || (lower == - std::numeric_limits<double>::infinity() &&
166 upper == std::numeric_limits<double>::infinity() ) ) {
170 else if (lower == upper)
173 if (lower == - std::numeric_limits<double>::infinity() )
175 else if (upper == std::numeric_limits<double>::infinity() )
185 if (ivar >
fVarTypes.size() )
return false;
192 if (ivar >
fVarTypes.size() )
return false;
193 if (
fBounds.count(ivar) == 0) {
197 if (
fBounds[ivar].
first == - std::numeric_limits<double>::infinity() )
199 else if (
fBounds[ivar].
second == std::numeric_limits<double>::infinity() )
208 if (ivar >
fVarTypes.size() )
return false;
213 if (ivar >
fValues.size() )
return false;
216 std::map< unsigned int , std::pair< double, double> >::const_iterator itr =
fBounds.find(ivar);
218 double lower = (itr->second).
first;
219 double upper = (itr->second).
second;
229 if (ivar >
fNames.size() )
return "";
234 std::vector<std::string>::const_iterator itr = std::find(
fNames.begin(),
fNames.end(),
name);
235 if (itr ==
fNames.end() )
return -1;
236 return itr -
fNames.begin();
256 unsigned int npar =
fValues.size();
257 if (npar == 0 || npar <
fDim ) {
258 MATH_ERROR_MSGVAL(
"BasicMinimizer::CheckDimension",
"Wrong number of parameters",npar);
266 MATH_ERROR_MSG(
"BasicMinimizer::CheckFunction",
"Function has not been set");
275 bool doTransform = (
fBounds.size() > 0);
276 unsigned int ivar = 0;
277 while (!doTransform && ivar <
fVarTypes.size() ) {
281 startValues = std::vector<double>(
fValues.begin(),
fValues.end() );
289 doTransform &= (gradObjFunc != 0);
295 trFunc->InvTransformation(&
fValues.front(), &startValues[0]);
298 startValues.resize( trFunc->NDim() );
338 int pr = std::cout.precision(18);
339 std::cout <<
"FVAL = " <<
fMinVal << std::endl;
340 std::cout.precision(pr);
342 std::cout <<
"Niterations = " <<
NIterations() << std::endl;
343 unsigned int ncalls =
NCalls();
344 if (ncalls) std::cout <<
"NCalls = " << ncalls << std::endl;
345 for (
unsigned int i = 0; i <
fDim; ++i)
346 std::cout <<
fNames[i] <<
"\t = " <<
fValues[i] << std::endl;
359 unsigned int nfree =
fValues.size();
360 for (
unsigned int i = 0; i <
fVarTypes.size(); ++i)
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
std::vector< ROOT::Math::EMinimVariableType > fVarTypes
Namespace for new ROOT classes and functions.
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set upper limit variable (override if minimizer supports them )
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
virtual bool SetVariableValues(const double *x)
set the values of all existing variables (array must be dimensioned to the size of existing parameter...
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
Clone a function.
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=0)
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set lower limit variable (override if minimizer supports them )
const ROOT::Math::IMultiGenFunction * fObjFunc
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
#define MATH_ERROR_MSGVAL(loc, str, x)
void Fix()
fix the parameter
std::vector< double > fValues
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found ...
virtual unsigned int NDim() const
number of dimensions
#define MATH_ERROR_MSG(loc, str)
std::map< unsigned int, std::pair< double, double > > fBounds
virtual unsigned int NIterations() const
number of iterations to reach the minimum
static constexpr double second
std::vector< double > fSteps
void SetLowerLimit(double low)
set a single lower limit
virtual unsigned int NCalls() const
number of function calls to reach the minimum
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool Minimize()
method to perform the minimization
void SetFinalValues(const double *x)
static int DefaultPrintLevel()
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
const ROOT::Math::MinimTransformFunction * TransformFunction() const
return transformation function (NULL if not having a transformation)
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported) ...
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
static int DefaultMaxIterations()
virtual unsigned int NFree() const
number of free variables (real dimension of the problem)
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
Namespace for new Math classes and functions.
bool CheckObjFunction() const
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
void SetUpperLimit(double up)
set a single upper limit
void PrintResult() const
print result of minimization
std::vector< std::string > fNames
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed The c...
BasicMinimizer()
Default constructor.
void SetPrintLevel(int level)
set print level
bool CheckDimension() const
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
virtual ~BasicMinimizer()
Destructor.