24 #include "MCContainers.hpp" 26 #include "MCSamples.hpp" 74 virtual bool Add(
const T value,
const float weight,
const T prev_value,
75 const float prev_weight)
override 84 virtual void Remove(
const T value,
const float weight,
const T next_value,
85 const float next_weight)
override 107 template <
typename T>
134 *NewInstance = *
this;
138 virtual bool Add(
const T value,
const float weight,
const T prev_value,
139 const float prev_weight)
override 148 virtual void Remove(
const T value,
const float weight,
const T next_value,
149 const float next_weight)
override 165 template <
typename T>
192 *NewInstance = *
this;
196 virtual bool Add(
const T value,
const float weight,
const T prev_value,
197 const float prev_weight)
override 206 virtual void Remove(
const T value,
const float weight,
const T next_value,
207 const float next_weight)
override 229 template <
typename T>
256 *NewInstance = *
this;
260 virtual bool Add(
const T value,
const float weight,
const T prev_value,
261 const float prev_weight)
override 267 Count += (value > 0);
271 virtual void Remove(
const T value,
const float weight,
const T next_value,
272 const float next_weight)
override 278 Count -= (value > 0);
295 template <
typename T>
319 for (
int i = 0; i < Degree; ++i)
321 Result += (double)SampleCache[i];
323 return (
float)(Result / Degree);
330 *NewInstance = *
this;
334 virtual bool Add(
const T value,
const float weight,
const T prev_value,
335 const float prev_weight)
override 341 SampleCache.erase(SampleCache.begin());
343 SampleCache.push_back((
float) value);
347 virtual void Remove(
const T value,
const float weight,
const T next_value,
348 const float next_weight)
override 372 template <
typename T>
398 Result += (double)SampleCache[i];
400 return (
float)(Result / Degree);
407 *NewInstance = *
this;
411 virtual bool Add(
const T value,
const float weight,
const T prev_value,
412 const float prev_weight)
override 418 SampleCache.erase(SampleCache.begin());
420 SampleCache.push_back((
float) value);
424 virtual void Remove(
const T value,
const float weight,
const T next_value,
425 const float next_weight)
override 449 template <
typename T>
470 return (
float)(
Result / Weights);
477 *NewInstance = *
this;
481 virtual bool Add(
const T value,
const float weight,
const T prev_value,
482 const float prev_weight)
override 486 Result += (float)value*weight;
491 virtual void Remove(
const T value,
const float weight,
const T next_value,
492 const float next_weight)
override 496 Result -= (float)value*weight;
517 template <
typename T>
539 double WeightSum = 0.0;
540 double OneThirdWeight { 1.0 / 3.0 };
541 double TwoThirdWeight { 2.0 / 3.0 };
547 if (i < OneThirdCount)
549 Sum += (double)(*sample)*OneThirdWeight;
550 WeightSum += OneThirdWeight;
552 if (i >= OneThirdCount && i < TwoThirdCount)
554 Sum += (double)(*sample)*TwoThirdWeight;
555 WeightSum += TwoThirdWeight;
557 if (i >= TwoThirdCount)
559 Sum += (double)(*sample);
563 return (
float)Sum / WeightSum;
570 *NewInstance = *
this;
574 virtual bool Add(
const T value,
const float weight,
const T prev_value,
575 const float prev_weight)
override 581 SampleCache.erase(SampleCache.begin());
583 SampleCache.push_back((
float)value);
587 virtual void Remove(
const T value,
const float weight,
const T next_value,
588 const float next_weight)
override 610 template <
typename T>
637 *NewInstance = *
this;
641 virtual bool Add(
const T value,
const float weight,
const T prev_value,
642 const float prev_weight)
override 650 Result += (double)1.0 / value;
654 virtual void Remove(
const T value,
const float weight,
const T next_value,
655 const float next_weight)
override 661 Result -= (double)1.0 / value;
678 template <
typename T>
697 for (
auto& sample : SampleCache)
708 *NewInstance = *
this;
712 virtual bool Add(
const T value,
const float weight,
const T prev_value,
713 const float prev_weight)
override 722 SampleCache.erase(SampleCache.begin());
728 virtual void Remove(
const T value,
const float weight,
const T next_value,
729 const float next_weight)
override 751 template <
typename T>
764 Degree(
MCBound(1, degree, 3)), DegreeMultiplier(Degree / 4.0)
771 DegreeMultiplier = Degree / 4.0;
780 auto FirstIter = List.begin();
781 auto SecondIter = FirstIter++;
783 return (*FirstIter+*SecondIter) / 2;
787 auto Iter = List.begin();
793 for (; Iter != List.end(); ++Iter)
795 if (i == ExpectedIndex)
802 for (; Iter != List.end(); ++Iter)
804 if (i+1 == ExpectedIndex)
809 if (unlikely(Iter == List.end()))
811 return (
float)TempValue;
813 return (
float)(TempValue+*Iter) / 2;
821 virtual bool Add(
const T value,
const float weight,
const T prev_value,
822 const float prev_weight)
override 827 List.push_back(value);
831 virtual void Remove(
const T value,
const float weight,
const T next_value,
832 const float next_weight)
override 838 for (
auto Iter = List.begin(); Iter != List.end(); ++Iter)
840 if ((*Iter) == value)
866 template <
typename T>
869 friend class MCIqr<T>;
886 *NewInstance = *
this;
894 template <
typename T>
913 *NewInstance = *
this;
921 template <
typename T>
924 friend class MCIqr<T>;
941 *NewInstance = *
this;
949 template <
typename T>
973 return Fq.GetResult()-Tq.GetResult();
980 *NewInstance = *
this;
984 virtual bool Add(
const T value,
const float weight,
const T prev_value,
985 const float prev_weight)
override 987 Fq.AddValue(value, weight, prev_value, prev_weight);
988 Tq.AddValue(value, weight, prev_value, prev_weight);
992 virtual void Remove(
const T value,
const float weight,
const T next_value,
993 const float next_weight)
override 995 Fq.RemoveValue(value, weight, next_value, next_weight);
996 Tq.RemoveValue(value, weight, next_value, next_weight);
1009 template <
typename T>
1030 float FinalResult = 0.0;
1032 for (
int i = 0; i < MCSampleStatistic<T>::Size; ++i)
1037 FinalResult = sqrt(FinalResult);
1045 *NewInstance = *
this;
1053 template <
typename T>
1080 *NewInstance = *
this;
1084 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1085 const float prev_weight)
override 1096 for (
int i = 1; i < MCSampleStatistic<T>::Size; ++i)
1109 virtual void Remove(
const T value,
const float weight,
const T next_value,
1110 const float next_weight)
override 1116 if (unlikely(value ==
Result))
1136 template <
typename T>
1163 *NewInstance = *
this;
1167 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1168 const float prev_weight)
override 1179 for (
int i = 1; i < MCSampleStatistic<T>::Size; ++i)
1192 virtual void Remove(
const T value,
const float weight,
const T next_value,
1193 const float next_weight)
override 1199 if (unlikely(value ==
Result))
1219 template <
typename T>
1247 *NewInstance = *
this;
1251 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1252 const float prev_weight)
override 1257 Result += (double)value*value;
1261 virtual void Remove(
const T value,
const float weight,
const T next_value,
1262 const float next_weight)
override 1267 Result -= (double)value*value;
1285 template <
typename T>
1304 *NewInstance = *
this;
1308 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1309 const float prev_weight)
override 1318 virtual void Remove(
const T value,
const float weight,
const T next_value,
1319 const float next_weight)
override 1331 template <
typename T>
1359 *NewInstance = *
this;
1367 template <
typename T>
1395 *NewInstance = *
this;
1403 template <
typename T>
1430 *NewInstance = *
this;
1434 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1435 const float prev_weight)
override 1441 if ((value > (T)0 && prev_value < (T)0) ||
1442 (value < (T)0 && prev_value > (T)0) ||
1450 virtual void Remove(
const T value,
const float weight,
const T next_value,
1451 const float next_weight)
override 1455 if ((value > (T)0 && next_value < (T)0) ||
1456 (value < (T)0 && next_value > (T)0) ||
1477 template <
typename T>
1493 const std::string& name =
"ValueRangeCounter") :
1495 RangeUpperLimit(
MCMax(range_lower_limit, range_upper_limit))
1512 *NewInstance = *
this;
1516 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1517 const float prev_weight)
override 1522 if ((
float)value > RangeLowerLimit && (
float)value < RangeUpperLimit)
1529 virtual void Remove(
const T value,
const float weight,
const T next_value,
1530 const float next_weight)
override 1535 if ((
float)value > RangeLowerLimit && (
float)value < RangeUpperLimit)
1559 template <
typename T>
1589 *NewInstance = *
this;
1593 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1594 const float prev_weight)
override 1607 virtual void Remove(
const T value,
const float weight,
const T next_value,
1608 const float next_weight)
override 1629 template <
typename T>
1661 *NewInstance = *
this;
1665 virtual bool Add(
const T value,
const float weight,
const T prev_value,
1666 const float prev_weight)
override 1670 if (PositiveTrend && prev_value-value > 0)
1672 if (!PositiveTrend && prev_value-value < 0)
1677 virtual void Remove(
const T value,
const float weight,
const T next_value,
1678 const float next_weight)
override 1682 if (PositiveTrend && value-next_value > 0)
1684 if (!PositiveTrend && value-next_value < 0)
1713 template <
typename T>
1716 if (vector.size() < 2)
1718 MC_WARNING(
"Vector size must be at least 2 for statistics calculations (%d)", vector.size());
1723 VectorSamples << vector;
1739 template <
typename T>
1744 MC_WARNING(
"The table is not consistent for statistics calculations");
1749 for (
auto& row : table)
1768 template <
typename T>
1773 int ColumnIndex =
MCBound(0, column, (
int)table.size()-1);
1775 for (
auto& row : table)
1777 ColumnSamples << row[ColumnIndex];
1793 template <
typename T,
typename U >
1796 MC::FloatList Results;
1798 for (
unsigned int i = 0; i < table[0].size(); ++i)
1818 template <
typename T>
1826 MC_WARNING(
"Table is not consistent or squared to calculate statistics.");
1831 for (
unsigned int i = 0; i < table.size(); ++i)
1833 const int Index = topleft_to_rightbottom ? i : (table.size()-i-1);
1835 DiagonalSamples << table[Index][Index];
Arithmetic sum statistic.
Base class for quartile statistics (first quartile, median, third quartile)
virtual float GetResult() override
Get the current result of the statistic.
float MCCalculateColumnStatInTable(const std::vector< std::vector< T > > &table, int column, MCSampleStatistic< T > &statistic)
Calculate a statistic over a column in a table.
Non-zero sample count statistic.
virtual float GetResult() override
Get the current result of the statistic.
Power statistic for signals.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
std::list< T > List
List variable.
virtual void Reset() override
Reset the statistic to a default state.
virtual void Reset() override
Reset the statistic to a default state.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual float GetResult() override
Get the current result of the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
float DegreeMultiplier
The degree multiplier.
virtual float GetResult() override
Get the current result of the statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
float MCCalculateDiagonalStatInTable(const std::vector< std::vector< T > > &table, MCSampleStatistic< T > &statistic, bool topleft_to_rightbottom=true)
Calculate a statistic over a diagonal in a squared table.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
const T MCMin(const U &container)
Get the minimal value of a container.
virtual void SetSize(int size) override
Set the sample vector size for the calculation.
float MCCalculateTableStatistic(const std::vector< std::vector< T > > &table, MCSampleStatistic< T > &statistic)
Calculate a statistic over a table.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual void Reset() override
Reset the statistic to a default state.
double Result
The result value.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
Geometric mean statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual float GetResult() override
Get the current result of the statistic.
double Weights
The sum of weights.
double MCDoubleInfinity()
Get double infinity.
Arithmetic mean head statistic.
bool MCIsDoubleInfinity(const double value)
Check a value for double infinity.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual float GetResult()=0
Get the current result of the statistic.
Root mean square statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
float MCCalculateVectorStatistic(const std::vector< T > &vector, MCSampleStatistic< T > &statistic)
Calculate a statistic over a vector.
virtual float GetResult() override
Get the current result of the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
int Result
The result value.
virtual float GetResult() override
Get the current result of the statistic.
std::vector< float > SampleCache
Sample cache for the statistic.
#define MC_WARNING(...)
Warning macro.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual void Reset() override
Reset the statistic to a default state.
const T & MCBound(const T &min, const T &value, const T &max)
Check a value bound according to a range.
T MCAbs(const T &value)
Calculate absolute value.
#define foreach_i(_i, _iter, _container)
For each cycle with auto keyword and index values.
virtual void Reset() override
Reset the statistic to a default state.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
std::vector< float > SampleCache
Sample cache for the statistic (value order is important)
virtual void Reset()
Reset the statistic to a default state.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual float GetResult() override
Get the current result of the statistic.
float RangeLowerLimit
Lower limit of the range.
virtual void Reset() override
Reset the statistic to a default state.
double Result
The result value.
virtual void Reset() override
Reset the statistic to a default state.
int Result
The result value.
virtual float GetResult() override
Get the current result of the statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual void SetSize(int size)
Set the sample vector size for the calculation.
virtual void Reset() override
Reset the statistic to a default state.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
double Result
The result value.
First quartile statistic.
int Samples
Counted samples in the calculations.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
Sample statistic base class.
float RangeUpperLimit
Upper limit of the range.
Interquartile range statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual float GetResult() override
Get the current result of the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
bool MCIsFloatInfinity(const float value)
Check a value for float infinity.
virtual float GetResult() override
Get the current result of the statistic.
int Count
Non-zero item count.
double Result
The result value.
#define MC_UNUSED(a)
Helper macro to avoid compiler warning about unused function parameters.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
double Result
The result value.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
bool MCIsConsistentTable(V &table)
Check the consistency of a table.
double Result
The result value.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
Value trend counter statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual float GetResult() override
Get the current result of the statistic.
virtual float GetResult() override
Get the current result of the statistic.
Arithmetic mean tail statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Reset() override
Reset the statistic to a default state.
std::vector< float > SampleCache
Sample cache for the statistic (value order is important)
Value change counter statistic.
double Result
The result value.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual void SetSize(int size) override
Set the sample vector size for the calculation.
Third quartile statistic.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
double Result
The result value.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual float GetResult() override
Get the current result of the statistic.
virtual void Reset() override
Reset the statistic to a default state.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual float GetResult() override
Get the current result of the statistic.
MCThirdQuartile< T > Tq
Third quartile statistic.
bool PositiveTrend
Whether it is a positive (increasing) trend counter.
MCFirstQuartile< T > Fq
First quartile statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual float GetResult() override
Get the current result of the statistic.
MC::FloatList MCCalculateColumnStatsInTable(const std::vector< std::vector< T > > &table)
Calculate a statistic over the column of a table.
virtual void Reset() override
Reset the statistic to a default state.
float MCFloatInfinity()
Get float infinity.
Logarithmic square sum statistic.
virtual void Reset() override
Reset the statistic to a default state.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual float GetResult() override
Get the current result of the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
Standard deviation statistic.
virtual void Reset() override
Reset the statistic to a default state.
Value range counter statistic.
const T MCMax(const U &container)
Get the maximal value of a container.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
virtual void Reset() override
Reset the statistic to a default state.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
int Degree
Degree (1 = first quartile, 2 = median or 3 = third quartile)
virtual bool Add(const T value, const float weight, const T prev_value, const float prev_weight) override
Input value calculation.
std::vector< float > SampleCache
Sample cache for the statistic (value order is important)
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Reset() override
Reset the statistic to a default state.
virtual float GetResult() override
Get the current result of the statistic.
virtual MCSampleStatistic< T > * Clone() override
Clone the statistic.
double Result
The result value.
Decreasingly weighted mean statistic.
virtual float GetResult() override
Get the current result of the statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
double Result
The result value.
Arithmetic mean statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual float GetResult() override
Get the current result of the statistic.
Weighted arithmetic mean statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual float GetResult() override
Get the current result of the statistic.
virtual void Remove(const T value, const float weight, const T next_value, const float next_weight) override
Remove a value.
virtual void Reset() override
Reset the statistic to a default state.
virtual float GetResult() override
Get the current result of the statistic.
virtual void Reset() override
Reset the statistic to a default state.