YODA::DbnBase< N > Class Template Reference A 1D distribution. More...
Inheritance diagram for YODA::DbnBase< N >:
Detailed Descriptiontemplate<size_t N> class YODA::DbnBase< N > A 1D distribution. This class is used internally by YODA to centralise the calculation of statistics of unbounded, unbinned sampled distributions. Each distribution fill contributes a weight, , and a value, . By storing the total number of fills (ignoring weights), , , , and , the Dbn can calculate the mean and spread ( , and ) of the sampled distribution. It is used to provide this information in bins and for the "hidden" distribution in profile histogram bins. Member Typedef Documentation◆ BaseT
template<size_t N>
◆ DataSize
template<size_t N>
◆ FillDim
template<size_t N>
Constructor & Destructor Documentation◆ DbnBase() [1/5]
template<size_t N>
Default constructor of a new distribution. Definition at line 97 of file Dbn.h. 97{ reset(); }
References YODA::DbnBase< N >::reset(). ◆ DbnBase() [2/5]
template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim < 2)>>
Constructor to set a distribution with a pre-filled state. Principally designed for internal persistency use.
Definition at line 105 of file Dbn.h. double numEntries() const Number of entries (number of times fill was called, ignoring weights) Definition Dbn.h:309 ◆ DbnBase() [3/5]
template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
◆ DbnBase() [4/5]
template<size_t N>
Copy constructor Sets all the parameters using the ones provided from an existing DbnBase. ◆ DbnBase() [5/5]
template<size_t N>
Move constructor Sets all the parameters using the ones provided from an existing DbnBase. Member Function Documentation◆ crossTerm()
template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
The second-order cross term between axes k and l. Definition at line 341 of file Dbn.h. 341 {
342 if (A1 >= N || A2 >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
343 if (A1 >= A2) throw RangeError("Indices need to be different for cross term");
344
345 size_t idx = 0;
346 for (size_t i = 0; i < (N-1); ++i) {
347 for (size_t j = i+1; j < N; ++j) {
348 if (i == A1 && j == A2) break;
349 ++idx;
350 }
351 if (i == A1) break;
352 }
353
354 return _sumWcross.at(idx);
355 }
Referenced by YODA::DbnBase< N >::reduceTo(). ◆ dim()
template<size_t N>
◆ effNumEntries()
template<size_t N>
◆ errW()
template<size_t N>
◆ fill() [1/2]
template<size_t N>
template<typename... Args>
Templated convenience overload of fill method. Example: fill(3.0, 2.1, 3.4, 3.0) // To fill value (X=3.0,Y=2.1,Z=3.0) with weight 3.0 Definition at line 162 of file Dbn.h. 162 {
163 // N + 2 - dimension + 2 default parameters
164 static_assert(sizeof...(args) <= N + 2,
165 "Value's dimension doesn't match distribution's dimension.");
166 std::array<double, sizeof...(args)> vals = {{args...}};
167 double weight = 1.0;
168 double fraction = 1.0;
169 if (vals.size() > N) {
170 weight = vals[N];
171 if (vals.size() > N + 1) fraction = vals[N + 1];
172 }
173 const double sf = fraction * weight;
174 _numEntries += fraction;
175 _sumW.at(0) += sf;
176 _sumW2.at(0) += fraction*sqr(weight);
177 for (unsigned int i = 0; i < N; ++i) {
178 _sumW.at(i + 1) += sf * vals.at(i);
179 _sumW2.at(i + 1) += sf * sqr(vals.at(i));
180 }
181
182 if constexpr(N >= 2) {
183 size_t idx = 0;
184 for (size_t i = 0; i < (N-1); ++i) {
185 for (size_t j = i+1; j < N; ++j) {
186 _sumWcross.at(idx++) += sf * vals.at(i) * vals.at(j);
187 }
188 }
189 }
190
191 }
References YODA::sqr(). ◆ fill() [2/2]
template<size_t N>
Contribute a sample at val (from an array) with weight weight. If you use brace enclosed initializer list and call this method in this way: fill({1,2,3}, 2, 3) and get error from compiler with this note: "no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::array<double, 0>’", it likely means that your value dimension doesn't match distribution's. Definition at line 152 of file Dbn.h. 152 {
153 fill(vals, weight, fraction, std::make_index_sequence<N>{});
154 }
void fill(const std::array< double, N > vals, const double weight=1.0, const double fraction=1.0) Contribute a sample at val (from an array) with weight weight. Definition Dbn.h:152 References YODA::DbnBase< N >::fill(). Referenced by YODA::Dbn< 1 >::fill(), YODA::Dbn< 3 >::fill(), YODA::Dbn< 2 >::fill(), YODA::Dbn< 0 >::fill(), YODA::Dbn< 0 >::fill(), YODA::Dbn< 1 >::fill(), YODA::Dbn< 2 >::fill(), YODA::Dbn< 3 >::fill(), and YODA::DbnBase< N >::fill(). ◆ mean()
template<size_t N>
Weighted mean, , of distribution. Definition at line 519 of file Dbn.h. 519 {
521 }
double mean(const std::vector< int > &sample) Calculate the mean of a sample. Definition MathUtils.h:391 References YODA::mean(). Referenced by YODA::DbnStorage< DbnN, AxisT >::mean(), and YODA::DbnBase< N >::toString(). ◆ numEntries()
template<size_t N>
Number of entries (number of times Definition at line 309 of file Dbn.h. 309 {
310 return _numEntries;
311 }
Referenced by YODA::Dbn< 0 >::set(), and YODA::DbnBase< N >::set(). ◆ operator+=() [1/2]
template<size_t N>
Add two DbnBases. Definition at line 551 of file Dbn.h. 551 {
552 _numEntries += d._numEntries;
553 for (size_t i = 0; i <= N; ++i) {
554 _sumW.at(i) += d._sumW.at(i);
555 _sumW2.at(i) += d._sumW2.at(i);
556 }
557 for (size_t i = 0; i < _sumWcross.size(); ++i) {
558 _sumWcross.at(i) += d._sumWcross.at(i);
559 }
560 return *this;
561 }
◆ operator+=() [2/2]
template<size_t N>
Add two DbnBases. Definition at line 565 of file Dbn.h. 565 {
566 _numEntries += std::move(d._numEntries);
567 for (size_t i = 0; i <= N; ++i) {
568 _sumW.at(i) += std::move(d._sumW.at(i));
569 _sumW2.at(i) += std::move(d._sumW2.at(i));
570 }
571 for (size_t i = 0; i < _sumWcross.size(); ++i) {
572 _sumWcross.at(i) += std::move(d._sumWcross.at(i));
573 }
574 return *this;
575 }
◆ operator-=() [1/2]
template<size_t N>
Subtract one DbnBase from another. Definition at line 579 of file Dbn.h. 579 {
580 _numEntries -= d._numEntries;
581 for (unsigned int i =0; i<= N ; ++i) {
582 _sumW.at(i) -= d._sumW.at(i);
583 _sumW2.at(i) += d._sumW2.at(i);
584 }
585 for (size_t i = 0; i < _sumWcross.size(); ++i) {
586 _sumWcross.at(i) -= d._sumWcross.at(i);
587 }
588 return *this;
589 }
◆ operator-=() [2/2]
template<size_t N>
Subtract one DbnBase from another. Definition at line 593 of file Dbn.h. 593 {
594 _numEntries -= std::move(d._numEntries);
595 for (unsigned int i =0; i<= N ; ++i) {
596 _sumW.at(i) -= std::move(d._sumW.at(i));
597 _sumW2.at(i) += std::move(d._sumW2.at(i));
598 }
599 for (size_t i = 0; i < _sumWcross.size(); ++i) {
600 _sumWcross.at(i) -= std::move(d._sumWcross.at(i));
601 }
602 return *this;
603 }
◆ operator=() [1/2]
template<size_t N>
Copy assignment Sets all the parameters using the ones provided from an existing DbnBase. ◆ operator=() [2/2]
template<size_t N>
Move assignment Sets all the parameters using the ones provided from an existing DbnBase. ◆ reduce()Reduce operation that produces a lower-dimensional DbnBase removing the specified axes for the new DbnBase. Definition at line 415 of file Dbn.h. 415 {
416 constexpr auto new_axes = AxisFilter(std::make_index_sequence<N>{},
417 [](size_t i) { return !has_match(i, std::integer_sequence<size_t, axes...>{}); }
418 );
420 }
DbnBase< sizeof...(size_t)> reduceTo(size_t... axes) const Reduce operation that produces a lower-dimensional DbnBase keeping only the specified axes in the new... Definition Dbn.h:383 References YODA::DbnBase< N >::reduceTo(). ◆ reduceTo() [1/2]
template<size_t N>
template<typename... size_t>
Reduce operation that produces a lower-dimensional DbnBase keeping only the specified axes in the new DbnBase. Definition at line 383 of file Dbn.h. 383 {
384 if constexpr (N == sizeof...(axes)) { return *this; } // keep all axes
385 else {
386 // only select the axis moments to keep (0 is sumW, 1...N are the axis moments)
387 std::array<double, sizeof...(axes)+1> newSumW = { _sumW[0], _sumW[axes+1]... };
388 std::array<double, sizeof...(axes)+1> newSumW2 = { _sumW2[0], _sumW2[axes+1]... };
389 if constexpr (sizeof...(axes) < 2) {
391 }
392 else {
393 constexpr auto newDim = sizeof...(axes);
394 std::array<double, newDim*(newDim-1)/2> newSumWcross;
395 unsigned int idx = 0;
396 for (unsigned int i : {axes...}) {
397 for (unsigned int j : {axes...}) {
399 }
400 }
402 }
403 }
404 }
double crossTerm(const size_t A1, const size_t A2) const The second-order cross term between axes k and l. Definition Dbn.h:341 References YODA::DbnBase< N >::crossTerm(). Referenced by YODA::DbnBase< N >::reduce(), and YODA::DbnBase< N >::reduceTo(). ◆ reduceTo() [2/2]
template<size_t N>
template<size_t... Is>
Same as above but using an std::integer_sequence. Definition at line 408 of file Dbn.h. References YODA::DbnBase< N >::reduceTo(). ◆ relErrW()
template<size_t N>
The relative error on sumW. Definition at line 511 of file Dbn.h. 511 {
513 return std::numeric_limits<double>::quiet_NaN();
514 }
516 }
References YODA::effNumEntries(). ◆ relStdErr()
template<size_t N>
Relative weighted standard error on the mean, , of distribution. Definition at line 537 of file Dbn.h. 537 {
539 return std::numeric_limits<double>::quiet_NaN();
540 }
542 }
double stdErr(const size_t i) const Weighted standard error on the mean, , of distribution. Definition Dbn.h:531 References YODA::effNumEntries(), YODA::mean(), and YODA::stdErr(). ◆ reset()
template<size_t N>
Reset the internal counters. Definition at line 232 of file Dbn.h. 232 {
233 _numEntries= 0;
234 _sumW.fill(0);
235 _sumW2.fill(0);
236 _sumWcross.fill(0);
237 }
Referenced by YODA::DbnBase< N >::DbnBase(). ◆ RMS()
template<size_t N>
Weighted RMS, , of distribution. Definition at line 546 of file Dbn.h. 546 {
548 }
double RMS(const double sumWX2, const double sumW, const double sumW2) Calculate the weighted RMS of a sample. Definition MathUtils.h:489 References YODA::RMS(). Referenced by YODA::DbnStorage< DbnN, AxisT >::rms(), and YODA::DbnBase< N >::toString(). ◆ scale()
template<size_t N>
Definition at line 254 of file Dbn.h. 254 {
256 throw RangeError("Dimension index should be less than "+std::to_string(N));
257 _sumW.at(dim+1) *= factor;
259 size_t idx = 0;
260 for (size_t i = 0; i < (N-1); ++i) {
261 for (size_t j = i+1; j < N; ++j) {
263 _sumWcross.at(idx++) *= factor;
264 }
265 }
266 } // end of double loop
267 }
References YODA::DbnBase< N >::dim(), and YODA::sqr(). ◆ scaleW()
template<size_t N>
Rescale as if all fill weights had been different by factor scalefactor. Definition at line 241 of file Dbn.h. 241 {
242 _sumW.at(0) *= scalefactor;
243 _sumW2.at(0) *= sqr(scalefactor);
244 for (size_t i = 0; i< N; ++i) {
245 // first- and second-order moments
246 _sumW.at(i+1) *= scalefactor;
247 _sumW2.at(i+1) *= scalefactor;
248 }
249 for (size_t i = 0; i < _sumWcross.size(); ++i) {
250 _sumWcross.at(i) *= scalefactor;
251 }
252 }
References YODA::sqr(). ◆ set() [1/4]
template<size_t N>
◆ set() [2/4]
template<size_t N>
Set a sample with array-based number of entries numEntries, sum of weights sumW (and corresponding moments), sum of squared weights sumW2 (and corresponding moments). Definition at line 197 of file Dbn.h. 199 {
200 _numEntries = numEntries;
201 _sumW = sumW;
202 _sumW2 = sumW2;
203 _sumWcross = sumWcross;
204 }
References YODA::DbnBase< N >::numEntries(), YODA::DbnBase< N >::sumW(), and YODA::DbnBase< N >::sumW2(). Referenced by YODA::Dbn< 0 >::set(). ◆ set() [3/4]
template<size_t N>
Set a sample with vector-based number of entries numEntries, sum of weights sumW (and corresponding moments), sum of squared weights sumW2 (and corresponding moments). Definition at line 209 of file Dbn.h. 211 {}) {
213 throw UserError("Value's dimension doesn't match distribution's dimension.");
214 _numEntries = numEntries;
217 std::copy_n(std::make_move_iterator(sumWcross.begin()), sumWcross.size(), _sumWcross.begin());
218 }
◆ set() [4/4]
template<size_t N>
◆ stdDev()
template<size_t N>
Weighted standard deviation, , of distribution. Definition at line 291 of file Dbn.h. References YODA::DbnBase< N >::variance(). ◆ stdErr()
template<size_t N>
Weighted standard error on the mean, , of distribution. Definition at line 531 of file Dbn.h. 531 {
533 }
double stdErr(const double sumWX, const double sumW, const double sumWX2, const double sumW2) Calculate the weighted standard error of a sample. Definition MathUtils.h:470 References YODA::stdErr(). Referenced by YODA::DbnStorage< DbnN, AxisT >::stdErr(). ◆ sumW() [1/2]
template<size_t N>
The sum of weights. Definition at line 320 of file Dbn.h. 320 {
321 return _sumW.at(0);
322 }
Referenced by YODA::Dbn< 0 >::Dbn(), YODA::Dbn< 1 >::Dbn(), YODA::Dbn< 2 >::Dbn(), YODA::Dbn< 3 >::Dbn(), YODA::Dbn< 0 >::set(), YODA::DbnBase< N >::set(), and YODA::DbnBase< N >::toString(). ◆ sumW() [2/2]
template<size_t N>
◆ sumW2() [1/2]
template<size_t N>
The sum of weights squared. Definition at line 325 of file Dbn.h. 325 {
326 return _sumW2.at(0);
327 }
Referenced by YODA::Dbn< 0 >::set(), and YODA::DbnBase< N >::set(). ◆ sumW2() [2/2]
template<size_t N>
◆ toString()
template<size_t N>
String representation of the DbnBase for debugging. Definition at line 365 of file Dbn.h. 365 {
366 std::string res ="";
367 res += ("numEntries="+ std::to_string(_numEntries)) ;
371 }
372 return res;
373 }
References YODA::DbnBase< N >::mean(), YODA::DbnBase< N >::RMS(), and YODA::DbnBase< N >::sumW(). ◆ variance()
template<size_t N>
Weighted variance, , of distribution. Definition at line 525 of file Dbn.h. 525 {
527 }
double variance(const double sumWX, const double sumW, const double sumWX2, const double sumW2) Calculate the weighted variance of a sample. Definition MathUtils.h:421 References YODA::variance(). Referenced by YODA::DbnBase< N >::stdDev(), and YODA::DbnStorage< DbnN, AxisT >::variance(). 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 |