41 return (*
this)(par, gra);
49 int npar = params.size();
52 for (
int i = 0; i < npar; ++i) {
56 double fval =
Fcn()(par);
60 return (*
this)(minpars);
72 MnPrint print(
"Numerical2PGradientCalculator");
76 double fcnmin = par.
Fval();
84 double dfmin = 8. * eps2 * (std::fabs(fcnmin) +
Fcn().
Up());
85 double vrysml = 8. * eps * eps;
92 unsigned int ncycle =
Ncycle();
98 print.
Debug(
"Calculating gradient around function value", fcnmin,
"\n\t at point", par.
Vec());
110 for (
unsigned int i = startElementIndex; i < endElementIndex; i++) {
120 for (
int i = 0; i <
int(
n); i++) {
130 double epspri = eps2 + std::fabs(grd(i) * eps2);
132 for (
unsigned int j = 0; j < ncycle; j++) {
133 double optstp = std::sqrt(dfmin / (std::fabs(g2(i)) + epspri));
134 double step = std::max(optstp, std::fabs(0.1 * gstep(i)));
140 double stpmax = 10. * std::fabs(gstep(i));
144 double stpmin = std::max(vrysml, 8. * std::fabs(eps2 *
x(i)));
163 double fs1 =
Fcn()(
x);
165 double fs2 =
Fcn()(
x);
168 double grdb4 = grd(i);
169 grd(i) = 0.5 * (fs1 - fs2) / step;
170 g2(i) = (fs1 + fs2 - 2. * fcnmin) / step / step;
178 MnPrint printtl(
"Numerical2PGradientCalculator[OpenMP]");
180 if (i == 0 && j == 0) {
182 printtl.
Trace([&](std::ostream &os) {
184 print.
Trace([&](std::ostream &os) {
186 os << std::setw(10) <<
"parameter" << std::setw(6) <<
"cycle" << std::setw(15) <<
"x" << std::setw(15)
187 <<
"step" << std::setw(15) <<
"f1" << std::setw(15) <<
"f2" << std::setw(15) <<
"grd"
188 << std::setw(15) <<
"g2" << std::endl;
192 printtl.
Trace([&](std::ostream &os) {
194 print.
Trace([&](std::ostream &os) {
196 const int pr = os.precision(13);
198 os << std::setw(10) <<
Trafo().
Name(iext) << std::setw(5) << j <<
" " <<
x(i) <<
" " << step <<
" "
199 << fs1 <<
" " << fs2 <<
" " << grd(i) <<
" " << g2(i) << std::endl;
204 if (std::fabs(grdb4 - grd(i)) / (std::fabs(grd(i)) + dfmin / step) <
GradTolerance()) {
225 print.
Debug([&](std::ostream &os) {
226 const int pr = os.precision(13);
228 os << std::setw(14) <<
"Parameter" << std::setw(14) <<
"Gradient" << std::setw(14) <<
"g2 " << std::setw(14)
229 <<
"step" << std::endl;
230 for (
int i = 0; i <
int(
n); i++) {
232 os << std::setw(14) <<
Trafo().
Name(iext) <<
" " << grd(i) <<
" " << g2(i) <<
" " << gstep(i) << std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
const MnAlgebraicVector & Gstep() const
const MnAlgebraicVector & Grad() const
const MnAlgebraicVector & G2() const
Class to calculate an initial estimate of the gradient.
bool SyncVector(ROOT::Minuit2::MnAlgebraicVector &mnvector)
unsigned int StartElementIndex() const
unsigned int EndElementIndex() const
const MnAlgebraicVector & Vec() const
Sets the relative floating point (double) arithmetic precision.
double Eps() const
eps returns the smallest possible number so that 1.+eps > 1.
double Eps2() const
eps2 returns 2*sqrt(eps)
void Debug(const Ts &... args)
void Trace(const Ts &... args)
double GradientStepTolerance() const
double GradientTolerance() const
unsigned int GradientNCycles() const
const MnUserTransformation & Trafo() const
const MnStrategy & Strategy() const
const MnMachinePrecision & Precision() const
FunctionGradient operator()(const MinimumParameters &) const override
double GradTolerance() const
const MnUserTransformation & fTransformation
unsigned int Ncycle() const
const MnFcn & Fcn() const
const MnStrategy & fStrategy
double StepTolerance() const
CPyCppyy::Parameter Parameter
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.