Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
MnPosDef.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
10#include "Minuit2/MnPosDef.h"
13#include "Minuit2/MnPrint.h"
14
15#include <algorithm>
16#include <iostream>
17
18namespace ROOT {
19
20namespace Minuit2 {
21
23{
24 // interface from minimum state
25 MinimumError err = (*this)(st.Error(), prec);
26 return MinimumState(st.Parameters(), err, st.Gradient(), st.Edm(), st.NFcn());
27}
28
30{
31 MnPrint print("MnPosDef");
32
33 // make error matrix positive defined returning a new corrected minimum error state
34
35 MnAlgebraicSymMatrix err(e.InvHessian());
36 if (err.size() == 1 && err(0, 0) < prec.Eps()) {
37 err(0, 0) = 1.;
39 }
40 if (err.size() == 1 && err(0, 0) > prec.Eps()) {
41 return e;
42 }
43 // std::cout<<"MnPosDef init matrix= "<<err<<std::endl;
44
45 double epspdf = std::max(1.e-12, prec.Eps2()); // should this lower bound be configurable?
46 double dgmin = err(0, 0);
47
48 for (unsigned int i = 0; i < err.Nrow(); i++) {
49 if (err(i, i) <= 0 /* prec.Eps2() */)
50 print.Warn("non-positive diagonal element in covariance matrix[", i, "] =", err(i, i));
51
52 if (err(i, i) < dgmin)
53 dgmin = err(i, i);
54 }
55 double dg = 0.;
56 if (dgmin <= 0) {
57 // dg = 1. + epspdf - dgmin;
58 dg = 0.5 + epspdf - dgmin;
59 // dg = 0.5*(1. + epspdf - dgmin);
60
61 print.Warn("Added to diagonal of Error matrix a value", dg);
62
63 // std::cout << "Error matrix " << err << std::endl;
64 }
65
66 MnAlgebraicVector s(err.Nrow());
68 for (unsigned int i = 0; i < err.Nrow(); i++) {
69 err(i, i) += dg;
70 if (err(i, i) < 0.)
71 err(i, i) = 1.;
72 s(i) = 1. / std::sqrt(err(i, i));
73 for (unsigned int j = 0; j <= i; j++) {
74 p(i, j) = err(i, j) * s(i) * s(j);
75 }
76 }
77
78 // std::cout<<"MnPosDef p: "<<p<<std::endl;
80 double pmin = eval(0);
81 double pmax = eval(eval.size() - 1);
82 // std::cout<<"pmin= "<<pmin<<" pmax= "<<pmax<<std::endl;
83 pmax = std::max(std::fabs(pmax), 1.);
84 if (pmin > epspdf * pmax)
85 return MinimumError(err, e.Dcovar());
86
87 double pAdd = 0.001 * pmax - pmin;
88
89 for (unsigned int i = 0; i < err.Nrow(); i++)
90 err(i, i) *= (1. + pAdd);
91
92 print.Debug([&](std::ostream &os) {
93 os << "Eigenvalues:";
94 for (unsigned i = 0; i < err.Nrow(); ++i)
95 os << "\n " << eval(i);
96 });
97
98 // std::cout<<"MnPosDef final matrix: "<<err<<std::endl;
99
100 print.Warn("Matrix forced pos-def by adding to diagonal", pAdd);
101
103}
104
105} // namespace Minuit2
106
107} // namespace ROOT
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Class describing a symmetric matrix of size n.
Definition MnMatrix.h:438
unsigned int Nrow() const
Definition MnMatrix.h:683
unsigned int size() const
Definition MnMatrix.h:681
unsigned int size() const
Definition MnMatrix.h:1032
MinimumError keeps the inv.
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Sets the relative floating point (double) arithmetic precision.
MinimumState operator()(const MinimumState &, const MnMachinePrecision &) const
Definition MnPosDef.cxx:22
void Debug(const Ts &... args)
Definition MnPrint.h:135
void Warn(const Ts &... args)
Definition MnPrint.h:123
LAVector eigenvalues(const LASymMatrix &)
Definition MnMatrix.cxx:602
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...