Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
DavidonErrorUpdator.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
12#include "Minuit2/MnPrint.h"
13
14namespace ROOT {
15
16namespace Minuit2 {
17
18MinimumError
20{
21
22 // update of the covarianze matrix (Davidon formula, see Tutorial, par. 4.8 pag 26)
23 // in case of delgam > gvg (PHI > 1) use rank one formula
24 // see par 4.10 pag 30
25 // ( Tutorial: https://seal.web.cern.ch/seal/documents/minuit/mntutorial.pdf )
26
27 MnPrint print("DavidonErrorUpdator");
28
29 const MnAlgebraicSymMatrix &v0 = s0.Error().InvHessian();
30 MnAlgebraicVector dx = p1.Vec() - s0.Vec();
31 MnAlgebraicVector dg = g1.Vec() - s0.Gradient().Vec();
32
33 double delgam = inner_product(dx, dg);
34 double gvg = similarity(dg, v0);
35
36 print.Debug("\ndx", dx, "\ndg", dg, "\ndelgam", delgam, "gvg", gvg);
37
38 if (delgam == 0) {
39 print.Warn("delgam = 0 : cannot update - return same matrix (details in info log)");
40 print.Info("Explanation:\n"
41 " The distance from the minimum cannot be estimated, since at two\n"
42 " different points s0 and p1, the function gradient projected onto\n"
43 " the difference of s0 and p1 is zero, where:\n"
44 " * s0: ", s0.Vec(), "\n"
45 " * p1: ", p1.Vec(), "\n"
46 " * gradient at s0: ", s0.Gradient().Vec(), "\n"
47 " * gradient at p1: ", g1.Vec(), "\n"
48 " To understand whether this hints to an issue in the minimized function,\n"
49 " the minimized function can be plotted along points between s0 and p1 to\n"
50 " look for unexpected behavior.");
51 return s0.Error();
52 }
53
54 if (delgam < 0) {
55 print.Warn("delgam < 0 : first derivatives increasing along search line (details in info log)");
56 print.Info("Explanation:\n"
57 " The distance from the minimum cannot be estimated, since the minimized\n"
58 " function seems not to be strictly convex in the space probed by the fit.\n"
59 " That is expected if the starting parameters are e.g. close to a local maximum\n"
60 " of the minimized function. If this function is expected to be fully convex\n"
61 " in the probed range or Minuit is already close to the function minimum, this\n"
62 " may hint to numerical or analytical issues with the minimized function.\n"
63 " This was found by projecting the difference of gradients at two points, s0 and p1,\n"
64 " onto the direction given by the difference of s0 and p1, where:\n"
65 " * s0: ", s0.Vec(), "\n"
66 " * p1: ", p1.Vec(), "\n"
67 " * gradient at s0: ", s0.Gradient().Vec(), "\n"
68 " * gradient at p1: ", g1.Vec(), "\n"
69 " To understand whether this hints to an issue in the minimized function,\n"
70 " the minimized function can be plotted along points between s0 and p1 to\n"
71 " look for unexpected behavior.");
72 }
73
74 if (gvg <= 0) {
75 // since v0 is pos def this gvg can be only = 0 if dg = 0 - should never be here
76 print.Warn("gvg <= 0 : cannot update - return same matrix");
77 return s0.Error();
78 }
79
81
82 // use rank 2 formula (Davidon)
84
85 if (delgam > gvg) {
86 // use dual formula formula (BFGS)
88 print.Debug("delgam<gvg : use dual (BFGS) formula");
89 }
90 else {
91 print.Debug("delgam<gvg : use rank 2 Davidon formula");
92 }
93
95 vUpd += v0;
96
97 double dcov = 0.5 * (s0.Error().Dcovar() + sum_upd / sum_of_elements(vUpd));
98
99 return MinimumError(vUpd, dcov);
100}
101
102/*
103MinimumError DavidonErrorUpdator::Update(const MinimumState& s0,
104 const MinimumParameters& p1,
105 const FunctionGradient& g1) const {
106
107 const MnAlgebraicSymMatrix& v0 = s0.Error().InvHessian();
108 MnAlgebraicVector dx = p1.Vec() - s0.Vec();
109 MnAlgebraicVector dg = g1.Vec() - s0.Gradient().Vec();
110
111 double delgam = inner_product(dx, dg);
112 double gvg = similarity(dg, v0);
113
114// std::cout<<"delgam= "<<delgam<<" gvg= "<<gvg<<std::endl;
115 MnAlgebraicVector vg = v0*dg;
116// MnAlgebraicSymMatrix vUpd(v0.Nrow());
117
118// MnAlgebraicSymMatrix dd = ( 1./delgam )*outer_product(dx);
119// dd *= ( 1./delgam );
120// MnAlgebraicSymMatrix VggV = ( 1./gvg )*outer_product(vg);
121// VggV *= ( 1./gvg );
122// vUpd = dd - VggV;
123// MnAlgebraicSymMatrix vUpd = ( 1./delgam )*outer_product(dx) - ( 1./gvg )*outer_product(vg);
124 MnAlgebraicSymMatrix vUpd = Outer_product(dx)/delgam - Outer_product(vg)/gvg;
125
126 if(delgam > gvg) {
127// dx *= ( 1./delgam );
128// vg *= ( 1./gvg );
129// MnAlgebraicVector flnu = dx - vg;
130// MnAlgebraicSymMatrix tmp = Outer_product(flnu);
131// tmp *= gvg;
132// vUpd = vUpd + tmp;
133 vUpd += gvg*outer_product(dx/delgam - vg/gvg);
134 }
135
136//
137// MnAlgebraicSymMatrix dd = Outer_product(dx);
138// dd *= ( 1./delgam );
139// MnAlgebraicSymMatrix VggV = Outer_product(vg);
140// VggV *= ( 1./gvg );
141// vUpd = dd - VggV;
142//
143//
144// double phi = delgam/(delgam - gvg);
145
146// MnAlgebraicSymMatrix vUpd(v0.Nrow());
147// if(phi < 0) {
148// // rank-2 Update
149// MnAlgebraicSymMatrix dd = Outer_product(dx);
150// dd *= ( 1./delgam );
151// MnAlgebraicSymMatrix VggV = Outer_product(vg);
152// VggV *= ( 1./gvg );
153// vUpd = dd - VggV;
154// }
155// if(phi > 1) {
156// // rank-1 Update
157// MnAlgebraicVector tmp = dx - vg;
158// vUpd = Outer_product(tmp);
159// vUpd *= ( 1./(delgam - gvg) );
160// }
161//
162
163//
164// if(delgam > gvg) {
165// // rank-1 Update
166// MnAlgebraicVector tmp = dx - vg;
167// vUpd = Outer_product(tmp);
168// vUpd *= ( 1./(delgam - gvg) );
169// } else {
170// // rank-2 Update
171// MnAlgebraicSymMatrix dd = Outer_product(dx);
172// dd *= ( 1./delgam );
173// MnAlgebraicSymMatrix VggV = Outer_productn(vg);
174// VggV *= ( 1./gvg );
175// vUpd = dd - VggV;
176// }
177//
178
179 double sum_upd = sum_of_elements(vUpd);
180 vUpd += v0;
181
182// MnAlgebraicSymMatrix V1 = v0 + vUpd;
183
184 double dcov =
185 0.5*(s0.Error().Dcovar() + sum_upd/sum_of_elements(vUpd));
186
187 return MinimumError(vUpd, dcov);
188}
189*/
190
191} // namespace Minuit2
192
193} // namespace ROOT
#define s0(x)
Definition RSha256.hxx:90
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
MinimumError Update(const MinimumState &, const MinimumParameters &, const FunctionGradient &) const override
Class describing a symmetric matrix of size n.
Definition MnMatrix.h:438
MinimumError keeps the inv.
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
void Debug(const Ts &... args)
Definition MnPrint.h:133
void Info(const Ts &... args)
Definition MnPrint.h:127
void Warn(const Ts &... args)
Definition MnPrint.h:121
LAVector MnAlgebraicVector
Definition MnMatrixfwd.h:22
double sum_of_elements(const LASymMatrix &)
Definition MnMatrix.cxx:98
double similarity(const LAVector &, const LASymMatrix &)
Definition MnMatrix.cxx:540
double inner_product(const LAVector &, const LAVector &)
Definition MnMatrix.cxx:227
ABObj< sym, VectorOuterProduct< ABObj< vec, M, T >, T >, T > Outer_product(const ABObj< vec, M, T > &obj)
Definition MnMatrix.h:390
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...