32 const std::vector<double> &err,
unsigned int maxcalls)
const
39 const std::vector<double> &cov,
unsigned int maxcalls)
const
59 unsigned int maxcalls)
const
73 for (
unsigned int i = 0; i <
n; i++)
75 double amin = mfcn(
x);
89 state.
Trafo(), maxcalls);
104 unsigned int maxcalls)
const
110 if (gradFCN && gradFCN->HasHessian()) {
126 std::unique_ptr<AnalyticalGradientCalculator> hc;
130 hc = std::make_unique<AnalyticalGradientCalculator>(fcn,trafo);
133 bool ret = hc->Hessian(st.
Parameters(), vhmat);
135 print.
Error(
"Error computing analytical Hessian. MnHesse fails and will return a null matrix");
140 for (
unsigned int i = 0; i <
n; i++)
147 print.
Debug(
"Original error matrix", vhmat);
152 print.
Debug(
"PosDef error matrix", vhmat);
154 int ifail =
Invert(vhmat);
157 print.
Warn(
"Matrix inversion fails; will return diagonal matrix");
160 for (
unsigned int j = 0; j <
n; j++) {
161 tmpsym(j,j) = 1. / g2(j);
181 print.
Debug(
"Hessian is ACCURATE. New state:",
"\n First derivative:", st.
Gradient().
Grad(),
182 "\n Covariance matrix:", vhmat,
"\n Edm:", edm);
189 unsigned int maxcalls)
const
197 double amin = mfcn(st.
Vec());
198 double aimsag = std::sqrt(prec.
Eps2()) * (std::fabs(amin) + mfcn.
Up());
204 maxcalls = 200 + 100 *
n + 5 *
n *
n;
216 print.
Info(
"Using analytical gradient but a numerical Hessian calculator - it could be not optimal");
223 print.
Warn(
"Analytical calculator ",grd,
" numerical ",tmp.Grad(),
" g2 ",g2);
229 "\n fcn :", amin,
"\n grad :", grd,
"\n step :", gst,
"\n g2 :", g2);
231 for (
unsigned int i = 0; i <
n; i++) {
234 double dmin = 8. * prec.
Eps2() * (std::fabs(xtf) + prec.
Eps2());
235 double d = std::fabs(gst(i));
239 print.
Debug(
"Derivative parameter", i,
"d =",
d,
"dmin =", dmin);
241 for (
unsigned int icyc = 0; icyc <
Ncycles(); icyc++) {
245 for (
unsigned int multpy = 0; multpy < 5; multpy++) {
251 sag = 0.5 * (fs1 + fs2 - 2. * amin);
253 print.
Debug(
"cycle", icyc,
"mul", multpy,
"\tsag =", sag,
"d =",
d);
272 print.
Warn(
"2nd derivative zero for parameter", trafo.
Name(trafo.
ExtOfInt(i)),
273 "; MnHesse fails and will return diagonal matrix");
275 for (
unsigned int j = 0; j <
n; j++) {
276 double tmp = g2(j) < prec.
Eps2() ? 1. : 1. / g2(j);
277 vhmat(j, j) = tmp < prec.
Eps2() ? 1. : tmp;
284 double g2bfor = g2(i);
285 g2(i) = 2. * sag / (
d *
d);
286 grd(i) = (fs1 - fs2) / (2. *
d);
291 d = std::sqrt(2. * aimsag / std::fabs(g2(i)));
293 d = std::min(0.5,
d);
297 print.
Debug(
"g1 =", grd(i),
"g2 =", g2(i),
"step =", gst(i),
"d =",
d,
"diffd =", std::fabs(
d - dlast) /
d,
298 "diffg2 =", std::fabs(g2(i) - g2bfor) / g2(i));
303 if (std::fabs((g2(i) - g2bfor) / g2(i)) <
TolerG2())
305 d = std::min(
d, 10. * dlast);
306 d = std::max(
d, 0.1 * dlast);
312 print.
Warn(
"Maximum number of allowed function calls exhausted; will return diagonal matrix");
314 for (
unsigned int j = 0; j <
n; j++) {
315 double tmp = g2(j) < prec.
Eps2() ? 1. : 1. / g2(j);
316 vhmat(j, j) = tmp < prec.
Eps2() ? 1. : tmp;
324 print.
Debug(
"Second derivatives", g2);
341 unsigned int endParIndexOffDiagonal = mpiprocOffDiagonal.
EndElementIndex();
343 unsigned int offsetVect = 0;
344 for (
unsigned int in = 0; in < startParIndexOffDiagonal; in++)
345 if ((in + offsetVect) % (
n - 1) == 0)
346 offsetVect += (in + offsetVect) / (
n - 1);
348 for (
unsigned int in = startParIndexOffDiagonal; in < endParIndexOffDiagonal; in++) {
350 int i = (in + offsetVect) / (
n - 1);
351 if ((in + offsetVect) % (
n - 1) == 0)
353 int j = (in + offsetVect) % (
n - 1) + 1;
355 if ((i + 1) == j || in == startParIndexOffDiagonal)
360 double fs1 = mfcn(
x);
362 double elem = (fs1 + amin - yy(i) - yy(j)) / (dirin(i) * dirin(j));
367 x(i) -= dirin(i);
x(i) -= dirin(i);
double fs3 = mfcn(
x);
368 x(j) -= dirin(j);
x(j) -= dirin(j);
double fs4 = mfcn(
x);
369 x(i) += dirin(i);
x(i) += dirin(i);
double fs2 = mfcn(
x);
371 double elem = (fs1 - fs2 - fs3 + fs4)/(4.*dirin(i)*dirin(j));
375 if (j % (
n - 1) == 0 || in == endParIndexOffDiagonal - 1)
387 print.
Debug(
"Original error matrix", vhmat);
395 print.
Debug(
"PosDef error matrix", vhmat);
397 int ifail =
Invert(vhmat);
400 print.
Warn(
"Matrix inversion fails; will return diagonal matrix");
403 for (
unsigned int j = 0; j <
n; j++) {
404 double tmp = g2(j) < prec.
Eps2() ? 1. : 1. / g2(j);
405 tmpsym(j, j) = tmp < prec.
Eps2() ? 1. : tmp;
426 print.
Debug(
"Hessian is ACCURATE. New state:",
"\n First derivative:", grd,
"\n Second derivative:", g2,
427 "\n Gradient step:", gst,
"\n Covariance matrix:", vhmat,
"\n Edm:", edm);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Similar to the AnalyticalGradientCalculator, the ExternalInternalGradientCalculator supplies Minuit w...
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
virtual double Up() const =0
Error definition of the function.
virtual GradientParameterSpace gradParameterSpace() const
bool IsAnalytical() const
const MnAlgebraicVector & Gstep() const
const MnAlgebraicVector & Grad() const
const MnAlgebraicVector & G2() const
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
void Add(const MinimumState &state, Status status=MnValid)
add latest minimization state (for example add Hesse result after Migrad)
const MnUserParameterState & UserState() const
const MinimumState & State() const
HessianGradientCalculator: class to calculate Gradient for Hessian.
Class describing a symmetric matrix of size n.
unsigned int Nrow() const
unsigned int size() const
unsigned int StartElementIndex() const
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
unsigned int EndElementIndex() const
MinimumError keeps the inv.
const MnAlgebraicSymMatrix & InvHessian() const
bool IsMadePosDef() const
const MnAlgebraicVector & Vec() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MnAlgebraicVector & Vec() const
const MinimumParameters & Parameters() const
const FunctionGradient & Gradient() const
Wrapper class to FCNBase interface used internally by Minuit.
const FCNBase & Fcn() const
unsigned int NumOfCalls() const
unsigned int Ncycles() const
forward interface of MnStrategy
MnUserParameterState operator()(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int maxcalls=0) const
low-level API
MinimumState ComputeNumerical(const MnFcn &, const MinimumState &, const MnUserTransformation &, unsigned int maxcalls) const
internal function to compute the Hessian using numerical derivative computation
MinimumState ComputeAnalytical(const FCNGradientBase &, const MinimumState &, const MnUserTransformation &) const
internal function to compute the Hessian using an analytical computation or externally provided in th...
Sets the relative floating point (double) arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
void Debug(const Ts &... args)
void Error(const Ts &... args)
void Info(const Ts &... args)
void Warn(const Ts &... args)
unsigned int Strategy() const
unsigned int HessianCentralFDMixedDerivatives() const
unsigned int HessianForcePosDef() const
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
class which holds the external user and/or internal Minuit representation of the parameters and error...
unsigned int NFcn() const
unsigned int VariableParameters() const
const std::vector< double > & IntParameters() const
const MnUserTransformation & Trafo() const
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
class performing the numerical gradient calculation
double Estimate(const FunctionGradient &, const MinimumError &) const
int Invert(LASymMatrix &)
LASymMatrix MnAlgebraicSymMatrix
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...