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
25/// Initial rough estimate of the gradient using the parameter step size.
26FunctionGradient
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
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. * trafo.Precision().Eps2() * (std::fabs(var) + trafo.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 * 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.Trace("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
81} // namespace Minuit2
82
83} // namespace ROOT
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const MnAlgebraicVector & Vec() const
void Debug(const Ts &... args)
Definition MnPrint.h:135
void Trace(const Ts &... args)
Definition MnPrint.h:141
class dealing with the transformation between user specified parameters (external) and internal param...
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
FunctionGradient calculateInitialGradient(const MinimumParameters &, const MnUserTransformation &, double errorDef)
Initial rough estimate of the gradient using the parameter step size.
Namespace for new ROOT classes and functions.