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);
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::pair< double, double > errDownUp(const std::string &source="") const The signed absolute error on the central value. Definition Estimate.h:244 bool hasSource(const std::string &key) const noexcept Definition Estimate.h:414 References errDownUp(), hasSource(), setErr(), setVal(), sources(), and val(). Referenced by YODA::Estimate0D::add(), YODA::Estimate0D::add(), and operator+=(). ◆ deserializeSources()
Definition at line 482 of file Estimate.h. 482 {
483
485 if (data.size() != nErrs)
486 throw UserError("Expected " + std::to_string(nErrs) + " error source labels!");
487
488 for (size_t i = 0; i < data.size(); ++i) {
489 const std::string name("source" + std::to_string(i+1));
490 if (!_error.count(name))
491 throw UserError("Key names have already been updated!");
492 renameSource(name, data[i]);
493 }
494
495 }
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 252 of file Estimate.h. References errDownUp(). ◆ errAvg()
The average uncertainty component. Definition at line 282 of file Estimate.h. References errDownUp(). ◆ errDown()
The signed error due to the systematic downward variation. Definition at line 272 of file Estimate.h. References errDownUp(). Referenced by YODA::divide(). ◆ errDownUp()
The signed absolute error on the central value.
Definition at line 244 of file Estimate.h. 244 {
245 const size_t count = _error.count(source);
246 if (!count)
247 throw RangeError("Error map has no such key: "+source);
248 return _error.at(source);
249 }
Referenced by add(), err(), errAvg(), errDown(), errNegPos(), errUp(), relErrDownUp(), and subtract(). ◆ errNeg()
The signed negative uncertainty component. Definition at line 262 of file Estimate.h. 262 {
264 }
std::pair< double, double > errNegPos(std::string source="") const The signed negative and positive uncertainty component. Definition Estimate.h:257 References errNegPos(). Referenced by valMin(). ◆ errNegPos()
The signed negative and positive uncertainty component. Definition at line 257 of file Estimate.h. References errDownUp(). ◆ errPos()
The signed positive uncertainty component. Definition at line 267 of file Estimate.h. References errNegPos(). Referenced by valMax(). ◆ errUp()
The signed error due to the systematic upward variation. Definition at line 277 of file Estimate.h. References errDownUp(). Referenced by YODA::divide(). ◆ hasSource()
Definition at line 414 of file Estimate.h. 414 {
415 return _error.count(key);
416 }
Referenced by add(), YODA::divide(), renameSource(), and subtract(). ◆ numErrs()
Definition at line 418 of file Estimate.h. 418 {
419 return _error.size();
420 }
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()
Get the quadrature sum of uncertainty components.
Definition at line 330 of file Estimate.h. 330 {
331 // interpret as { neg , pos } quad sums
332 std::pair<double, double> ret = { 0., 0. };
333 for (const auto& item : _error) {
334 const auto [dn,up] = _downUp2NegPos(item.second);
335 ret.first += dn*dn;
336 ret.second += up*up;
337 }
338 return { - std::sqrt(ret.first), std::sqrt(ret.second) };
339 }
Referenced by YODA::Estimate0D::mkScatter(), quadSumAvg(), quadSumNeg(), quadSumPos(), and totalErr(). ◆ quadSumAvg()
The average uncertainty component. Definition at line 350 of file Estimate.h. 350 {
352 }
std::pair< double, double > quadSum() const noexcept Get the quadrature sum of uncertainty components. Definition Estimate.h:330 References quadSum(). ◆ quadSumNeg()
Definition at line 341 of file Estimate.h. References quadSum(). ◆ quadSumPos()
Definition at line 345 of file Estimate.h. References quadSum(). ◆ relErr()
Convenience alias for relErrDownUp. Definition at line 295 of file Estimate.h. 295 {
297 }
std::pair< double, double > relErrDownUp(const std::string &source="") const The relative error on the central value. Definition Estimate.h:287 References relErrDownUp(). Referenced by relErrDown(), and relErrUp(). ◆ relErrAvg()
The average uncertainty component. Definition at line 310 of file Estimate.h. References relErrDownUp(). ◆ relErrDown()
The relative negative on the central value. Definition at line 300 of file Estimate.h. 300 {
302 }
std::pair< double, double > relErr(const std::string &source="") const Convenience alias for relErrDownUp. Definition Estimate.h:295 References relErr(). Referenced by YODA::divide(). ◆ relErrDownUp()
The relative error on the central value. Definition at line 287 of file Estimate.h. 287 {
289 dn = _value != 0 ? dn/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
290 up = _value != 0 ? up/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
291 return {dn,up};
292 }
References errDownUp(). Referenced by relErr(), and relErrAvg(). ◆ relErrUp()
The relative positive on the central value. Definition at line 305 of file Estimate.h. References relErr(). Referenced by YODA::divide(). ◆ relTotalErr()
The relative negative/positive total uncertainty on the central value. Definition at line 386 of file Estimate.h. 386 {
388 neg = _value != 0 ? neg/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
389 pos = _value != 0 ? pos/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
390 return {neg,pos};
391 }
std::pair< double, double > totalErr() const noexcept The total uncertainty. Definition Estimate.h:358 References totalErr(). Referenced by relTotalErrAvg(), relTotalErrNeg(), and relTotalErrPos(). ◆ relTotalErrAvg()
The average uncertainty component. Definition at line 404 of file Estimate.h. 404 {
406 }
std::pair< double, double > relTotalErr() const noexcept The relative negative/positive total uncertainty on the central value. Definition Estimate.h:386 References relTotalErr(). Referenced by YODA::efficiency(). ◆ relTotalErrNeg()
The relative negative total uncertainty on the central value. Definition at line 394 of file Estimate.h. References relTotalErr(). ◆ relTotalErrPos()
The relative positive total uncertainty on the central value. Definition at line 399 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(). ◆ 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:252 ◆ 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(), YODA::efficiency(), and YODA::Counter::mkEstimate(). ◆ 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(), 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(), 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()
Definition at line 408 of file Estimate.h. 408 {
409 std::vector<std::string> keys;
410 for (const auto& item : _error) keys.push_back(item.first);
411 return keys;
412 }
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);
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 358 of file Estimate.h. 358 {
359 // check if the user specified the total uncertainty
360 if (_error.count("")) return _downUp2NegPos(_error.at(""));
361 // otherwise return quadrature sum
363 }
References quadSum(). Referenced by relTotalErr(), totalErrAvg(), totalErrNeg(), and totalErrPos(). ◆ totalErrAvg()
The average total uncertainty. Definition at line 376 of file Estimate.h. References totalErr(). Referenced by YODA::efficiency(), and valueErr(). ◆ totalErrNeg()
◆ totalErrPos()
◆ 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 238 of file Estimate.h. 238{ return _value; }
Referenced by add(), YODA::divide(), YODA::efficiency(), YODA::Estimate0D::mkScatter(), set(), set(), setVal(), subtract(), valMax(), and valMin(). ◆ valMax()
The maximal shift of the central value according to systematic variation source Definition at line 316 of file Estimate.h. 316 {
318 }
double errPos(const std::string &source="") const The signed positive uncertainty component. Definition Estimate.h:267 ◆ valMin()
The minimal shift of the central value according to systematic variation source Definition at line 322 of file Estimate.h. 322 {
324 }
double errNeg(const std::string &source="") const The signed negative uncertainty component. Definition Estimate.h:262 ◆ valueErr()
The unsigned average total uncertainty. Definition at line 381 of file Estimate.h. References totalErrAvg(). The documentation for this class was generated from the following file:
Generated on Thu Feb 29 2024 12:47:15 for YODA - Yet more Objects for Data Analysis by 1.9.8 |