YODA::Estimate Class Reference A point estimate (base class for the Estimate) More...
Inheritance diagram for YODA::Estimate:
Detailed DescriptionA point estimate (base class for the Estimate) This class is used internally by YODA to centralise the storage of static statistical results or estimators. Each estimate is made up of a value and an error map. The error map uses the source of uncertainty as the keys and the (possibly asymmetric) uncertainty pair as the values. The empty string is interpreted as the total uncertainty. Definition at line 29 of file Estimate.h. Constructor & Destructor Documentation◆ Estimate() [1/5]
Default constructor of a new distribution. Definition at line 36 of file Estimate.h. 36{ reset(); }
References reset(). ◆ Estimate() [2/5]
Constructor to set an Estimate with a pre-filled state. Principally designed for internal persistency use. Definition at line 42 of file Estimate.h. 43 : _value(v), _error(errors) { }
◆ Estimate() [3/5]
Alternative constructor to set an Estimate with value and uncertainty. Definition at line 47 of file Estimate.h. 48 : _value(v) { setErr(e, source); }
void setErr(const std::pair< double, double > &err, const std::string &source="") Set a signed uncertainty component. Definition Estimate.h:165 References setErr(). ◆ Estimate() [4/5]
Copy constructor Sets all the parameters using the ones provided from an existing Estimate. Definition at line 53 of file Estimate.h. 53 {
54 _value = toCopy._value;
55 _error = toCopy._error;
56 }
◆ Estimate() [5/5]
Move constructor Sets all the parameters using the ones provided from an existing Estimate. Definition at line 61 of file Estimate.h. 61 {
62 _value = std::move(toMove._value);
63 _error = std::move(toMove._error);
64 }
Member Function Documentation◆ add()
Add two Estimates. Definition at line 95 of file Estimate.h. 95 {
97 std::smatch match;
98 const std::regex re(pat_uncorr, std::regex_constants::icase);
101 else if (std::regex_search(src, match, re)) {
102 // treat as uncorrelated between AOs:
103 // add in quadrature
105 const auto [r_dn,r_up] = toAdd.errDownUp(src);
106 const double new_dn = std::sqrt(l_dn*l_dn + r_dn*r_dn);
107 const double new_up = std::sqrt(l_up*l_up + r_up*r_up);
108 setErr({-new_dn,new_up}, src);
109 }
110 else {
111 // treat as correlated between AOs: add linearly
113 const auto [r_dn,r_up] = toAdd.errDownUp(src);
114 setErr({l_dn+r_dn, l_up+r_up}, src);
115 }
116 }
117 return *this;
118 }
std::vector< std::string > sources() const noexcept The list of error source names. Definition Estimate.h:487 std::pair< double, double > errDownUp(const std::string &source="") const The signed absolute error on the central value. Definition Estimate.h:255 bool hasSource(const std::string &key) const noexcept Returns true/false if the error map contains key. Definition Estimate.h:494 References errDownUp(), hasSource(), setErr(), setVal(), sources(), and val(). Referenced by YODA::Estimate0D::add(), YODA::Estimate0D::add(), and operator+=(). ◆ deserializeSources()
Definition at line 563 of file Estimate.h. 563 {
564
566 if (data.size() != nErrs)
567 throw UserError("Expected " + std::to_string(nErrs) + " error source labels!");
568
569 for (size_t i = 0; i < data.size(); ++i) {
570 const std::string name("source" + std::to_string(i+1));
571 if (!_error.count(name))
572 throw UserError("Key names have already been updated!");
573 renameSource(name, data[i]);
574 }
575
576 }
size_t numErrs() const noexcept The number of error sources in the error map. Definition Estimate.h:499 void renameSource(const std::string &old_label, const std::string &new_label) Replace a source label in the error breakdown. Definition Estimate.h:219 References numErrs(), and renameSource(). ◆ err()
Convenience alias for errorDownUp(source) Definition at line 263 of file Estimate.h. References errDownUp(). ◆ errAvg()
The unsigned error from an average of the downwards/upwards shifts. Definition at line 293 of file Estimate.h. References errDownUp(). ◆ errDown()
The signed error due to the systematic downward variation. Definition at line 283 of file Estimate.h. References errDownUp(). Referenced by YODA::divide(). ◆ errDownUp()
The signed absolute error on the central value.
Definition at line 255 of file Estimate.h. 255 {
256 const size_t count = _error.count(source);
257 if (!count)
258 throw RangeError("Error map has no such key: "+source);
259 return _error.at(source);
260 }
Referenced by add(), err(), errAvg(), errDown(), errEnv(), errNegPos(), errUp(), relErrDownUp(), and subtract(). ◆ errEnv()
The unsigned symmetrised error from the largest component of the downwards/upwards shifts. Definition at line 299 of file Estimate.h. References errDownUp(). ◆ errNeg()
The signed negative uncertainty component. Definition at line 273 of file Estimate.h. 273 {
275 }
std::pair< double, double > errNegPos(std::string source="") const The signed negative and positive uncertainty component. Definition Estimate.h:268 References errNegPos(). Referenced by valMin(). ◆ errNegPos()
The signed negative and positive uncertainty component. Definition at line 268 of file Estimate.h. References errDownUp(). ◆ errPos()
The signed positive uncertainty component. Definition at line 278 of file Estimate.h. References errNegPos(). Referenced by valMax(). ◆ errUp()
The signed error due to the systematic upward variation. Definition at line 288 of file Estimate.h. References errDownUp(). Referenced by YODA::divide(). ◆ hasSource()
Returns true/false if the error map contains key. Definition at line 494 of file Estimate.h. 494 {
495 return _error.count(key);
496 }
Referenced by add(), YODA::divide(), renameSource(), rmSource(), and subtract(). ◆ numErrs()
The number of error sources in the error map. Definition at line 499 of file Estimate.h. 499 {
500 return _error.size();
501 }
Referenced by deserializeSources(), and YODA::Estimate0D::mkInert(). ◆ operator+=()Definition at line 120 of file Estimate.h. 120 {
122 }
Estimate & add(const Estimate &toAdd, const std::string &pat_uncorr="^stat|^uncor") Add two Estimates. Definition Estimate.h:95 References add(). ◆ operator-=()Definition at line 149 of file Estimate.h. 149 {
151 }
Estimate & subtract(const Estimate &toSubtract, const std::string &pat_uncorr="^stat|^uncor") Subtract one Estimate from another. Definition Estimate.h:125 References subtract(). ◆ operator=() [1/2]Copy assignment Sets all the parameters using the ones provided from an existing Estimate. Definition at line 69 of file Estimate.h. 69 {
70 if (this != &toCopy) {
71 _value = toCopy._value;
72 _error = toCopy._error;
73 }
74 return *this;
75 }
Referenced by YODA::Estimate0D::operator=(), and YODA::Estimate0D::operator=(). ◆ operator=() [2/2]Move assignment Sets all the parameters using the ones provided from an existing Estimate. Definition at line 80 of file Estimate.h. 80 {
81 if (this != &toMove) {
82 _value = std::move(toMove._value);
83 _error = std::move(toMove._error);
84 }
85 return *this;
86 }
◆ quadSum()
The quadrature sum of uncertainty components.
Definition at line 358 of file Estimate.h. 358 {
359 const bool check_match = pat_match != ""; std::smatch match;
360 const std::regex re(pat_match, std::regex_constants::icase);
361 // interpret as { neg , pos } quad sums
362 std::pair<double, double> ret = { 0., 0. };
363 for (const auto& item : _error) {
364 if (item.first == "") continue;
365 if (check_match && !std::regex_search(item.first, match, re)) continue;
366 const auto [dn,up] = _downUp2NegPos(item.second);
367 ret.first += dn*dn;
368 ret.second += up*up;
369 }
370 return { - std::sqrt(ret.first), std::sqrt(ret.second) };
371 }
Referenced by quadSumAvg(), quadSumEnv(), quadSumNeg(), quadSumPos(), and totalErr(). ◆ quadSumAvg()
The unsigned average of the two quad-sum-based total uncertainty components. Definition at line 384 of file Estimate.h. 384 {
386 }
std::pair< double, double > quadSum(const std::string &pat_match="") const noexcept The quadrature sum of uncertainty components. Definition Estimate.h:358 References quadSum(). ◆ quadSumEnv()
The unsigned symmetrised uncertainty from the largest of the quad-sum-based total uncertainty components. Definition at line 390 of file Estimate.h. References quadSum(). ◆ quadSumMax()
The maximal shift of the central value from the quad-sum-based total uncertainty components. Definition at line 396 of file Estimate.h. 396 {
398 }
double quadSumPos(const std::string &pat_match="") const noexcept The positive component of the quad-sum-based total uncertainty components. Definition Estimate.h:379 References quadSumPos(), and val(). ◆ quadSumMin()
The minimal shift of the central value from the quad-sum-based total uncertainty components. Definition at line 402 of file Estimate.h. 402 {
404 }
double quadSumNeg(const std::string &pat_match="") const noexcept The negative component of the quad-sum-based total uncertainty components. Definition Estimate.h:374 References quadSumNeg(), and val(). ◆ quadSumNeg()
The negative component of the quad-sum-based total uncertainty components. Definition at line 374 of file Estimate.h. References quadSum(). Referenced by quadSumMin(). ◆ quadSumPos()
The positive component of the quad-sum-based total uncertainty components. Definition at line 379 of file Estimate.h. References quadSum(). Referenced by quadSumMax(). ◆ relErr()
Convenience alias for relErrDownUp. Definition at line 312 of file Estimate.h. 312 {
314 }
std::pair< double, double > relErrDownUp(const std::string &source="") const The relative signed error pair with respect to the central value. Definition Estimate.h:304 References relErrDownUp(). Referenced by relErrDown(), and relErrUp(). ◆ relErrAvg()
The relative uncertainty from an average of the downward/upward shifts with respect to the central value. Definition at line 328 of file Estimate.h. References relErrDownUp(). ◆ relErrDown()
The relative negative error with respect to the central value. Definition at line 317 of file Estimate.h. 317 {
319 }
std::pair< double, double > relErr(const std::string &source="") const Convenience alias for relErrDownUp. Definition Estimate.h:312 References relErr(). Referenced by YODA::divide(). ◆ relErrDownUp()
The relative signed error pair with respect to the central value. Definition at line 304 of file Estimate.h. 304 {
306 dn = _value != 0 ? dn/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
307 up = _value != 0 ? up/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
308 return {dn,up};
309 }
References errDownUp(). Referenced by relErr(), relErrAvg(), and relErrEnv(). ◆ relErrEnv()
The relative unsigned symmetrised error from the largest component of the downwards/upwards shifts with respect to the central value. Definition at line 334 of file Estimate.h. References relErrDownUp(). ◆ relErrUp()
The relative positive error with respect to the central value. Definition at line 322 of file Estimate.h. References relErr(). Referenced by YODA::divide(). ◆ relTotalErr()
The relative negative/positive total uncertainty with respect to the central value. Definition at line 457 of file Estimate.h. 457 {
459 neg = _value != 0 ? neg/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
460 pos = _value != 0 ? pos/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
461 return {neg,pos};
462 }
std::pair< double, double > totalErr(const std::string &pat_match="") const noexcept The total uncertainty. Definition Estimate.h:410 References totalErr(). Referenced by relTotalErrAvg(), relTotalErrEnv(), relTotalErrNeg(), and relTotalErrPos(). ◆ relTotalErrAvg()
The relative average of the quad-sum-based total downward/upward uncertainty components. Definition at line 476 of file Estimate.h. 476 {
478 }
std::pair< double, double > relTotalErr(const std::string &pat_match="") const noexcept The relative negative/positive total uncertainty with respect to the central value. Definition Estimate.h:457 References relTotalErr(). Referenced by YODA::efficiency(). ◆ relTotalErrEnv()
The unsigned symmetrised error from the largest downward/upward components of the relative total quad-sum-based uncertainty. Definition at line 482 of file Estimate.h. References relTotalErr(). ◆ relTotalErrNeg()
The relative negative total uncertainty on the central value. Definition at line 465 of file Estimate.h. References relTotalErr(). ◆ relTotalErrPos()
The relative positive total uncertainty on the central value. Definition at line 470 of file Estimate.h. References relTotalErr(). ◆ renameSource()
Replace a source label in the error breakdown. Definition at line 219 of file Estimate.h. 219 {
221 throw UserError("Error map has no such key: "+old_label);
222 }
223 auto entry = _error.extract(old_label);
224 entry.key() = new_label;
225 _error.insert(std::move(entry));
226 }
References hasSource(). Referenced by deserializeSources(), and YODA::Estimate0D::mkInert(). ◆ reset()
Reset the internal values. Definition at line 194 of file Estimate.h. 194 {
195 _value = std::numeric_limits<double>::quiet_NaN();
196 _error.clear();
197 }
Referenced by Estimate(), and YODA::Estimate0D::reset(). ◆ rmErrs()
Definition at line 236 of file Estimate.h. 236 {
237 _error.clear();
238 }
◆ rmSource()
Definition at line 229 of file Estimate.h. References hasSource(). ◆ scale() [1/2]
Rescale as if value and uncertainty had been different by factor scalefactor. Definition at line 201 of file Estimate.h. 201 {
202 _value *= scalefactor;
203 for (auto& item : _error) {
204 item.second = { item.second.first * scalefactor, item.second.second * scalefactor };
205 }
206 }
Referenced by transform(). ◆ scale() [2/2]
Generalised transformations with functors. Definition at line 209 of file Estimate.h. 209 {
210 trf.transform(_value, _error);
211 }
References YODA::Transformation< N, Args >::transform(). ◆ serializeSources()
◆ set() [1/2]
Set both central value and uncertainty component. Definition at line 188 of file Estimate.h. 188 {
191 }
std::pair< double, double > err(const std::string &source="") const Convenience alias for errorDownUp(source) Definition Estimate.h:263 ◆ set() [2/2]
Set both central value and uncertainty component. Definition at line 181 of file Estimate.h. References err(), setErr(), setVal(), and val(). Referenced by YODA::divide(), and YODA::efficiency(). ◆ setErr() [1/2]
◆ setErr() [2/2]
Set a signed uncertainty component. Definition at line 165 of file Estimate.h. 165 {
166 const std::string& s = Utils::toUpper(source);
167 if (s == "TOTAL")
168 throw UserError("Use empty string for the total uncertainty!");
169 _error[source] = err;
170 }
References err(). Referenced by add(), YODA::divide(), YODA::efficiency(), Estimate(), YODA::Counter::mkEstimate(), set(), set(), setErr(), and subtract(). ◆ setVal()
Alias for setValue. Definition at line 162 of file Estimate.h. void setValue(const double value) noexcept Set the central value of this estimator. Definition Estimate.h:159 References setValue(), and val(). Referenced by add(), YODA::divide(), YODA::Counter::mkEstimate(), set(), set(), and subtract(). ◆ setValue()
Set the central value of this estimator. Definition at line 159 of file Estimate.h. 159{ _value = value; }
Referenced by setVal(). ◆ sources()
The list of error source names. Definition at line 487 of file Estimate.h. 487 {
488 std::vector<std::string> keys;
489 for (const auto& item : _error) keys.push_back(item.first);
490 return keys;
491 }
Referenced by add(), YODA::divide(), YODA::efficiency(), serializeSources(), and subtract(). ◆ subtract()
Subtract one Estimate from another. Definition at line 125 of file Estimate.h. 125 {
127 std::smatch match;
128 const std::regex re(pat_uncorr, std::regex_constants::icase);
131 else if (std::regex_search(src, match, re)) {
132 // treat as uncorrelated between AOs: add in quadrature
134 const auto [r_dn,r_up] = toSubtract.errDownUp(src);
135 const double new_dn = std::sqrt(l_dn*l_dn + r_dn*r_dn);
136 const double new_up = std::sqrt(l_up*l_up + r_up*r_up);
137 setErr({-new_dn,new_up}, src);;
138 }
139 else {
140 // treat as correlated between AOs: add linearly
142 const auto [r_dn,r_up] = toSubtract.errDownUp(src);
143 setErr({l_dn+r_dn, l_up+r_up}, src);
144 }
145 }
146 return *this;
147 }
References errDownUp(), hasSource(), setErr(), setVal(), sources(), and val(). Referenced by operator-=(), YODA::Estimate0D::subtract(), and YODA::Estimate0D::subtract(). ◆ totalErr()
The total uncertainty.
Definition at line 410 of file Estimate.h. 410 {
411 // check if the user specified the total uncertainty
412 if (pat_match == "" && _error.count("")) return _downUp2NegPos(_error.at(""));
413 // otherwise return quadrature sum
415 }
References quadSum(). Referenced by relTotalErr(), totalErrAvg(), totalErrEnv(), totalErrNeg(), and totalErrPos(). ◆ totalErrAvg()
The average of the total downward/upward uncertainty shifts, which are taken to be the signed quadrature sums of the error sources. Definition at line 429 of file Estimate.h. References totalErr(). Referenced by YODA::efficiency(), and valueErr(). ◆ totalErrEnv()
The unsigned symmetrised uncertainty from the largest of the downward/upward shifts of the quad-sum-based total uncertainty. Definition at line 435 of file Estimate.h. References totalErr(). ◆ totalErrMax()
The maximal shift of the central value from the total uncertainty components. Definition at line 441 of file Estimate.h. 441 {
443 }
double totalErrPos(const std::string &pat_match="") const noexcept The positive total uncertainty. Definition Estimate.h:423 References totalErrPos(), and val(). ◆ totalErrMin()
The minimal shift of the central value from the total uncertainty components. Definition at line 447 of file Estimate.h. 447 {
449 }
double totalErrNeg(const std::string &pat_match="") const noexcept The negative total uncertainty. Definition Estimate.h:418 References totalErrNeg(), and val(). ◆ totalErrNeg()
The negative total uncertainty. Definition at line 418 of file Estimate.h. References totalErr(). Referenced by totalErrMin(). ◆ totalErrPos()
The positive total uncertainty. Definition at line 423 of file Estimate.h. References totalErr(). Referenced by YODA::Estimate0D::mkScatter(), and totalErrMax(). ◆ transform()
Generalised transformations with functors. Definition at line 214 of file Estimate.h. 214 {
215 scale(trf);
216 }
void scale(const double scalefactor) noexcept Rescale as if value and uncertainty had been different by factor scalefactor. Definition Estimate.h:201 References scale(). Referenced by YODA::transform(). ◆ val()
The central value. Definition at line 249 of file Estimate.h. 249{ return _value; }
Referenced by add(), YODA::divide(), YODA::efficiency(), YODA::Estimate0D::mkScatter(), quadSumMax(), quadSumMin(), set(), set(), setVal(), subtract(), totalErrMax(), totalErrMin(), valMax(), and valMin(). ◆ valMax()
The maximal shift of the central value according to systematic variation source. Definition at line 340 of file Estimate.h. 340 {
342 }
double errPos(const std::string &source="") const The signed positive uncertainty component. Definition Estimate.h:278 ◆ valMin()
The minimal shift of the central value according to systematic variation source. Definition at line 346 of file Estimate.h. 346 {
348 }
double errNeg(const std::string &source="") const The signed negative uncertainty component. Definition Estimate.h:273 ◆ valueErr()
The unsigned average total uncertainty. Definition at line 452 of file Estimate.h. 452 {
454 }
double totalErrAvg(const std::string &pat_match="") const The average of the total downward/upward uncertainty shifts, which are taken to be the signed quadrat... Definition Estimate.h:429 References totalErrAvg(). The documentation for this class was generated from the following file:
Generated on Mon Oct 28 2024 13:47:24 for YODA - Yet more Objects for Data Analysis by 1.9.8 |