Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
InitialGradientCalculator.cxx
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
11#include "Minuit2/MnFcn.h"
16#include "Minuit2/MnStrategy.h"
17#include "Minuit2/MnPrint.h"
18
19#include <cmath>
20
21namespace ROOT {
22
23namespace Minuit2 {
24
26{
27 // initial rough estimate of the gradient using the parameter step size
28
29 assert(par.IsValid());
30
31 unsigned int n = Trafo().VariableParameters();
32 assert(n == par.Vec().size());
33
34 MnPrint print("InitialGradientCalculator");
35
36 print.Debug("Calculating initial gradient at point", par.Vec());
37
38 MnAlgebraicVector gr(n), gr2(n), gst(n);
39
40 for (unsigned int i = 0; i < n; i++) {
41 unsigned int exOfIn = Trafo().ExtOfInt(i);
42
43 double var = par.Vec()(i);
44 double werr = Trafo().Parameter(exOfIn).Error();
45 double save1 = Trafo().Int2ext(i, var);
46 double save2 = save1 + werr;
47 if (Trafo().Parameter(exOfIn).HasLimits()) {
48 if (Trafo().Parameter(exOfIn).HasUpperLimit() && save2 > Trafo().Parameter(exOfIn).UpperLimit())
49 save2 = Trafo().Parameter(exOfIn).UpperLimit();
50 }
51 double var2 = Trafo().Ext2int(exOfIn, save2);
52 double vplu = var2 - var;
53 save2 = save1 - werr;
54 if (Trafo().Parameter(exOfIn).HasLimits()) {
55 if (Trafo().Parameter(exOfIn).HasLowerLimit() && save2 < Trafo().Parameter(exOfIn).LowerLimit())
56 save2 = Trafo().Parameter(exOfIn).LowerLimit();
57 }
58 var2 = Trafo().Ext2int(exOfIn, save2);
59 double vmin = var2 - var;
60 double gsmin = 8. * Precision().Eps2() * (std::fabs(var) + Precision().Eps2());
61 // protect against very small step sizes which can cause dirin to zero and then nan values in grd
62 double dirin = std::max(0.5 * (std::fabs(vplu) + std::fabs(vmin)), gsmin);
63 double g2 = 2.0 * fFcn.ErrorDef() / (dirin * dirin);
64 double gstep = std::max(gsmin, 0.1 * dirin);
65 double grd = g2 * dirin;
66 if (Trafo().Parameter(exOfIn).HasLimits()) {
67 if (gstep > 0.5)
68 gstep = 0.5;
69 }
70 gr(i) = grd;
71 gr2(i) = g2;
72 gst(i) = gstep;
73
74 print.Debug("Computed initial gradient for parameter", Trafo().Name(exOfIn), "value", var, "[", vmin, ",", vplu,
75 "]", "dirin", dirin, "grd", grd, "g2", g2);
76 }
77
78 return FunctionGradient(gr, gr2, gst);
79}
80
82{
83 // Base class interface
84 return (*this)(par);
85}
86
88{
89 // return precision (is set in transformation class)
91}
92
93} // namespace Minuit2
94
95} // namespace ROOT
const MnUserTransformation & Trafo() const
FunctionGradient operator()(const MinimumParameters &) const override
unsigned int size() const
Definition LAVector.h:231
const MnAlgebraicVector & Vec() const
double ErrorDef() const
Definition MnFcn.cxx:34
Sets the relative floating point (double) arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
void Debug(const Ts &... args)
Definition MnPrint.h:147
double Ext2int(unsigned int, double) const
unsigned int ExtOfInt(unsigned int internal) const
double Int2ext(unsigned int, double) const
const MnMachinePrecision & Precision() const
forwarded interface
const MinuitParameter & Parameter(unsigned int) const
CPyCppyy::Parameter Parameter
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...