49 MnPrint print(
"MnSeedGenerator");
55 print.
Info(
"Computing seed using NumericalGradient calculator");
57 print.
Debug(
n,
"free parameters, FCN pointer", &fcn);
61 for (
unsigned int i = 0; i <
n; i++)
69 auto timingScope = std::make_unique<ROOT::Math::Util::TimingScope>([&print](std::string
const &s) { print.
Info(s); },
70 "Evaluated function and gradient in");
78 for (
unsigned int i = 0; i <
n; i++) {
80 : dgrad.G2()(i) > prec.
Eps() ? 1. / dgrad.G2()(i)
82 for (
unsigned int j = i + 1; j <
n; j++)
87 for (
unsigned int i = 0; i <
n; i++)
89 mat(i, i) = dgrad.G2()(i) > prec.
Eps() ? 1. / dgrad.G2()(i) : 1.0;
101 print.
Debug(
"Negative G2 Found",
"\n point:",
x,
"\n grad :", dgrad.Grad(),
"\n g2 :", dgrad.G2());
103 state = ng2ls(fcn, state, gc, prec);
105 print.
Info(
"Negative G2 found - new state:", state);
112 print.
Debug(
"calling MnHesse");
116 print.
Info(
"run Hesse - Initial seeding state:", tmp);
121 print.
Info(
"Initial state ",state);
130 MnPrint print(
"MnSeedGenerator");
138 print.
Info(
"Using analytical (external) gradient calculator but cannot compute G2 - use then numerical gradient for G2");
146 print.
Info(
"Computing seed using analytical (external) gradients and Hessian calculator");
148 print.
Info(
"Computing seed using analytical (external) gradients and G2 calculator");
166 bool computedHessian =
false;
172 print.
Error(
"Cannot compute G2 and Hessian");
177 for (
unsigned int i = 0; i <
n; i++)
181 print.
Debug(
"Computed analytical G2",g2);
187 if (computedHessian) {
189 print.
Info(
"Use full Hessian as seed");
190 print.
Debug(
"computed Hessian",hmat);
191 print.
Debug(
"computed Error matrix (H^-1)",mat);
195 if (!computedHessian) {
199 print.
Info(
"Using existing covariance matrix");
200 for (
unsigned int i = 0; i <
n; i++) {
202 : grad.
G2()(i) > prec.
Eps() ? 1. / grad.
G2()(i)
204 for (
unsigned int j = i + 1; j <
n; j++)
209 for (
unsigned int i = 0; i <
n; i++) {
211 mat(i, i) = grad.
G2()(i) > prec.
Eps() ? 1. / grad.
G2()(i) : 1.0;
216 print.
Info(
"Computing seed using full Hessian");
223 print.
Error(
"Cannot compute seed because G2 is not computed");
232 state = ng2ls(fcn, state, gc, prec);
240 print.
Info(
"Compute full Hessian: Initial seeding state is ",tmpState);
244 print.
Info(
"Initial seeding state ",state);
257 InitialGradientCalculator igc(fcn, trafo, stra);
265 std::pair<FunctionGradient, MnAlgebraicVector> hgrd = hgc.DeltaGradient(pa, dgrad);
266 for (
unsigned int i = 0; i <
n; i++) {
267 if (std::fabs(hgrd.first.Grad()(i) - grd.
Grad()(i)) > hgrd.second(i)) {
268 int externalParameterIndex = trafo.
ExtOfInt(i);
269 const char *parameter_name = trafo.
Name(externalParameterIndex);
270 print.Warn(
"Gradient discrepancy of external Parameter too large:"
272 parameter_name,
"externalParameterIndex =", externalParameterIndex,
"internal =", i);
277 print.Error(
"Minuit does not accept user specified Gradient. To force acceptance, override 'virtual bool "
278 "CheckGradient() const' of FCNGradientBase.h in the derived class.");
virtual bool CanComputeG2() const
virtual bool CanComputeHessian() const
bool Hessian(const MinimumParameters &, MnAlgebraicSymMatrix &) const override
compute Hessian matrix
const MnAlgebraicVector & Gstep() const
const MnAlgebraicVector & Grad() const
const MnAlgebraicVector & G2() const
interface class for gradient calculators
HessianGradientCalculator: class to calculate Gradient for Hessian.
MinimumError keeps the inv.
static MnAlgebraicSymMatrix InvertMatrix(const MnAlgebraicSymMatrix &matrix, int &ifail)
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MinimumParameters & Parameters() const
Wrapper class to FCNBase interface used internally by Minuit.
unsigned int NumOfCalls() const
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
Sets the relative floating point (double) arithmetic precision.
double Eps() const
eps returns the smallest possible number so that 1.+eps > 1.
void Debug(const Ts &... args)
void Error(const Ts &... args)
void Info(const Ts &... args)
MinimumSeed CallWithAnalyticalGradientCalculator(const MnFcn &, const AnalyticalGradientCalculator &, const MnUserParameterState &, const MnStrategy &) const
MinimumSeed operator()(const MnFcn &, const GradientCalculator &, const MnUserParameterState &, const MnStrategy &) const override
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
bool ComputeInitialHessian() const
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MnMachinePrecision & Precision() const
unsigned int VariableParameters() const
const std::vector< double > & IntParameters() const
const MnUserTransformation & Trafo() const
const MnUserCovariance & IntCovariance() const
bool HasCovariance() const
In case that one of the components of the second derivative g2 calculated by the numerical Gradient c...
bool HasNegativeG2(const FunctionGradient &, const MnMachinePrecision &) const
class performing the numerical gradient calculation
double Estimate(const FunctionGradient &, const MinimumError &) const
LAVector MnAlgebraicVector
LASymMatrix MnAlgebraicSymMatrix