Logo ROOT  
Reference Guide
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 
21 namespace ROOT {
22 
23 namespace 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 sav = Trafo().Int2ext(i, var);
46  double sav2 = sav + werr;
47  if (Trafo().Parameter(exOfIn).HasLimits()) {
48  if (Trafo().Parameter(exOfIn).HasUpperLimit() && sav2 > Trafo().Parameter(exOfIn).UpperLimit())
49  sav2 = Trafo().Parameter(exOfIn).UpperLimit();
50  }
51  double var2 = Trafo().Ext2int(exOfIn, sav2);
52  double vplu = var2 - var;
53  sav2 = sav - werr;
54  if (Trafo().Parameter(exOfIn).HasLimits()) {
55  if (Trafo().Parameter(exOfIn).HasLowerLimit() && sav2 < Trafo().Parameter(exOfIn).LowerLimit())
56  sav2 = Trafo().Parameter(exOfIn).LowerLimit();
57  }
58  var2 = Trafo().Ext2int(exOfIn, sav2);
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 trasformation class)
90  return fTransformation.Precision();
91 }
92 
94 {
95  // return ncyles (from Strategy)
96  return Strategy().GradientNCycles();
97 }
98 
100 {
101  // return Gradient step tolerance (from Strategy)
102  return Strategy().GradientStepTolerance();
103 }
104 
106 {
107  // return Gradient tolerance
108  return Strategy().GradientTolerance();
109 }
110 
111 } // namespace Minuit2
112 
113 } // namespace ROOT
ROOT::Minuit2::InitialGradientCalculator::Trafo
const MnUserTransformation & Trafo() const
Definition: InitialGradientCalculator.h:40
ROOT::Minuit2::MnMachinePrecision::Eps2
double Eps2() const
eps2 returns 2*sqrt(eps)
Definition: MnMachinePrecision.h:41
n
const Int_t n
Definition: legend1.C:16
ROOT::Minuit2::MnUserTransformation::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnUserTransformation.cxx:99
MnMachinePrecision.h
ROOT::Minuit2::LAVector
Definition: LAVector.h:32
ROOT::Minuit2::MnPrint::Debug
void Debug(const Ts &... args)
Definition: MnPrint.h:138
ROOT::Minuit2::MinuitParameter::UpperLimit
double UpperLimit() const
Definition: MinuitParameter.h:158
MnStrategy.h
ROOT::Minuit2::MnStrategy::GradientNCycles
unsigned int GradientNCycles() const
Definition: MnStrategy.h:40
ROOT::Minuit2::MnUserTransformation::Precision
const MnMachinePrecision & Precision() const
forwarded interface
Definition: MnUserTransformation.h:117
MnUserTransformation.h
ROOT::Minuit2::MinimumParameters::Vec
const MnAlgebraicVector & Vec() const
Definition: MinimumParameters.h:38
ROOT::Minuit2::MnStrategy::GradientTolerance
double GradientTolerance() const
Definition: MnStrategy.h:42
ROOT::Minuit2::FunctionGradient
Definition: FunctionGradient.h:21
ROOT::Minuit2::MnStrategy::GradientStepTolerance
double GradientStepTolerance() const
Definition: MnStrategy.h:41
ROOT::Minuit2::InitialGradientCalculator::fFcn
const MnFcn & fFcn
Definition: InitialGradientCalculator.h:49
MnFcn.h
ROOT::Math::fabs
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:131
ROOT::Minuit2::InitialGradientCalculator::StepTolerance
double StepTolerance() const
Definition: InitialGradientCalculator.cxx:99
ROOT::Minuit2::MinimumParameters
Definition: MinimumParameters.h:21
FunctionGradient.h
gr
TGraphErrors * gr
Definition: legend1.C:25
ROOT::Minuit2::MnUserTransformation::VariableParameters
unsigned int VariableParameters() const
Definition: MnUserTransformation.h:110
ROOT::Minuit2::InitialGradientCalculator::operator()
virtual FunctionGradient operator()(const MinimumParameters &) const
Definition: InitialGradientCalculator.cxx:25
Parameter
CPyCppyy::Parameter Parameter
Definition: clingwrapper.cxx:48
ROOT::Minuit2::MnMachinePrecision
Sets the relative floating point (double) arithmetic precision.
Definition: MnMachinePrecision.h:32
ROOT::Minuit2::InitialGradientCalculator::GradTolerance
double GradTolerance() const
Definition: InitialGradientCalculator.cxx:105
ROOT::Minuit2::InitialGradientCalculator::Precision
const MnMachinePrecision & Precision() const
Definition: InitialGradientCalculator.cxx:87
ROOT::Minuit2::MnUserTransformation::Parameter
const MinuitParameter & Parameter(unsigned int) const
Definition: MnUserTransformation.cxx:263
ROOT::Minuit2::MinimumParameters::IsValid
bool IsValid() const
Definition: MinimumParameters.h:41
ROOT::Minuit2::MnUserTransformation::Ext2int
double Ext2int(unsigned int, double) const
Definition: MnUserTransformation.cxx:174
xmlio::Name
const char * Name
Definition: TXMLSetup.cxx:67
ROOT::Minuit2::LAVector::size
unsigned int size() const
Definition: LAVector.h:227
ROOT::Minuit2::MinuitParameter::Error
double Error() const
Definition: MinuitParameter.h:103
ROOT::Minuit2::InitialGradientCalculator::fTransformation
const MnUserTransformation & fTransformation
Definition: InitialGradientCalculator.h:50
ROOT::Minuit2::InitialGradientCalculator::Ncycle
unsigned int Ncycle() const
Definition: InitialGradientCalculator.cxx:93
InitialGradientCalculator.h
ROOT::Minuit2::InitialGradientCalculator::Strategy
const MnStrategy & Strategy() const
Definition: InitialGradientCalculator.h:42
MinimumParameters.h
ROOT::Minuit2::MinuitParameter::LowerLimit
double LowerLimit() const
Definition: MinuitParameter.h:157
MnPrint.h
ROOT::Minuit2::MnUserTransformation::ExtOfInt
unsigned int ExtOfInt(unsigned int internal) const
Definition: MnUserTransformation.h:102
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MnFcn::ErrorDef
double ErrorDef() const
Definition: MnFcn.cxx:34
ROOT::Minuit2::MnPrint
Definition: MnPrint.h:73