21#include <framework/core/FrameworkExceptions.h>
22#include <framework/logging/Logger.h>
41 template<
class DataType>
64 bool addMin(DataType newVal,
bool allow2Grow) {
return addEntry(newVal,
true, allow2Grow); }
69 bool addMax(DataType newVal,
bool allow2Grow) {
return addEntry(newVal,
false, allow2Grow); }
74 bool addEntry(DataType newVal,
bool isMinContainer,
bool allow2Grow)
97 void sortIn(DataType newVal,
bool isMinContainer)
103 if (isMinContainer) {
118 {
return unsigned(
double(
m_sampleSize) *
double(aQuantile) + 0.5); }
128 if (newCalcThreshold > container.size() ) {
return true; }
157 "The quantiles you asked for (%1% and %2%) are not within the collected range of data (0-%3% and %4%-1) to prevent this happening, you have to pass a bigger value for QuantileCut when constructing a MinMaxCollector-Instance!");
171 if (0 > quantileCut or 0.5 < quantileCut) {
throw (Quantile_out_of_bounds() << quantileCut); }
182 std::pair<DataType, DataType>
getMinMax(DataType minQuantile = 0., DataType maxQuantile = 1.)
const
185 if (0 > minQuantile or 1 < minQuantile) {
throw (Quantile_out_of_bounds() << minQuantile); }
186 if (0 > maxQuantile or 1 < maxQuantile) {
throw (Quantile_out_of_bounds() << maxQuantile); }
191 unsigned minIndex =
getIndex(minQuantile);
193 unsigned maxIndex =
getIndex(1. - maxQuantile);
197 if (minIndex > (
m_smallestValues.size() - 1)) { B2ERROR(
"minIndex " << minIndex <<
" calculated for minQuantile " << minQuantile <<
" bigger than nSmallestValues " <<
m_smallestValues.size() <<
"!"); }
198 if (finalMaxIndex > (
m_biggestValues.size() - 1)) { B2ERROR(
"maxIndex " << maxIndex <<
" calculated for maxQuantile " << maxQuantile <<
" bigger than nBiggestValues " <<
m_biggestValues.size() <<
"!"); }
206 {
append(std::move(newVal));}
212 {
append(std::move(newVal));}
239 B2WARNING(
"MinMaxCollector::merge: other collector has differing size in quantileCut. If this is not the purpose, this could indicate unintended behavior!");
284 void print(
bool printFull =
false)
const
285 { B2INFO(
getName(printFull)); }
290 std::string
getName(
bool printFull =
false)
const
295 string out =
"MinMaxCollector with sampleSize " + to_string(
m_sampleSize) +
297 " has nSmallestValues/nBiggestValues: " + to_string(nSmallest) +
298 "/" + to_string(nBiggest) +
"\n";
300 if (!printFull) out +=
"The 5 values each describe for the valueContainer pos[0], pos[1], pos[mean], pos[max-1], pos[max]\n";
301 out +=
"SmallestValues: ";
303 if (printFull or
size() < 6) {
305 out +=
"\n" + string(
"BiggestValues: ");
306 for (DataType entry :
m_biggestValues) { out += to_string(entry) +
", "; }
309 DataType smallestTotal = 0, biggestTotal = 0, smallestMean, biggestMean;
311 smallestMean = smallestTotal / DataType(nSmallest);
314 +
", mean: " + to_string(smallestMean)
318 biggestMean = biggestTotal / DataType(nBiggest);
319 out +=
"\n" + string(
"BiggestValues: ");
322 +
", mean: " + to_string(biggestMean)
A container for collecting data, where min- and max-quantiles near q(0) and q(1) are to be found.
bool checkVectorSize(const std::deque< DataType > &container)
returns true, if vector is allowed to grow
std::pair< DataType, DataType > getMinMax(DataType minQuantile=0., DataType maxQuantile=1.) const
for given pair of quantiles, the according cuts (min, max) will be returned.
unsigned size() const
returns the size (in a sense of roughly collected data)
void print(bool printFull=false) const
print an overview of the entries collected.
unsigned sampleSize() const
returns actual sampleSize
std::string getName(bool printFull=false) const
return a string of an overview of the entries collected.
BELLE2_DEFINE_EXCEPTION(Illegal_quantile, "The quantiles you asked for (%1% and %2%) are not within the collected range of data (0-%3% and %4%-1) to prevent this happening, you have to pass a bigger value for QuantileCut when constructing a MinMaxCollector-Instance!")
exception shall be thrown if the requested quantiles are not within the ranges collected
DataType m_quantileCut
sets the threshold for storing data.
unsigned totalSize() const
returns the combined size of the containers storing the values
void append(DataType newVal)
append new value
MinMaxCollector(DataType quantileCut=0.025, unsigned warmUpThreshold=10)
constructor.
bool empty() const
returns if internal containers are empty
unsigned m_warmUpThreshold
sets a threshold for warm-up.
bool addMax(DataType newVal, bool allow2Grow)
add entry to maxContainer if it fits in
unsigned m_sampleSize
counts number of values added so far
BELLE2_DEFINE_EXCEPTION(Request_in_empty_Container, "Data of an empty container was requested!")
exception shall be thrown if value is not between 0-1 and therefore not normalized
friend std::ostream & operator<<(std::ostream &out, const MinMaxCollector &mmCol)
overloaded '<<' stream operator.
void merge(const MinMaxCollector< DataType > &other)
fill the stuff of the other one with this one
unsigned getIndex(DataType aQuantile) const
the correct access-index for given quantile will be determined
void push_back(DataType newVal)
for convenience reasons, pipe to append.
bool addEntry(DataType newVal, bool isMinContainer, bool allow2Grow)
add entry to container if it fits in
std::deque< DataType > m_biggestValues
collects biggest values occurred so far
BELLE2_DEFINE_EXCEPTION(Quantile_out_of_bounds, "The quantileCut (%1%) you gave is illegal (only allowed between 0-1)")
returns true, if the valueContainers were increased in size.
void clear()
deletes all values collected so far and resets to constructor-settings.
void insert(DataType newVal)
for convenience reasons, pipe to append.
std::deque< DataType > m_smallestValues
collects smallest values occurred so far
void sortIn(DataType newVal, bool isMinContainer)
add newVal to appropriate container
bool addMin(DataType newVal, bool allow2Grow)
add entry to minContainer if it fits in
Abstract base class for different kinds of events.