Main Page · Modules · All Classes · Class Hierarchy
MCSampleStatistics.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MCContainers.hpp"
25 #include "MCDefs.hpp"
26 #include "MCSamples.hpp"
27 
28 #include <list>
29 
30 #include <math.h>
31 
32 template <typename T>
33 class MCIqr;
34 
43 template <typename T>
45 {
46 public:
47  /*
48  * Create an arithmetic sum statistic
49  *
50  * @param name Unique statistic name
51  *
52  */
53 
54  MCArithmeticSum(const std::string& name = "ArithmeticSum") : MCSampleStatistic<T>(name), Result(0.0)
55  { }
56  virtual ~MCArithmeticSum() {}
57 
58  virtual float GetResult() override
59  {
60  if (unlikely(!MCSampleStatistic<T>::Valid))
61  return MCFloatInfinity();
62 
63  return (float)Result;
64  }
65 
66  virtual MCSampleStatistic<T>* Clone() override
67  {
69 
70  *NewInstance = *this;
71  return NewInstance;
72  }
73 
74  virtual bool Add(const T value, const float weight, const T prev_value,
75  const float prev_weight) override
76  {
77  MC_UNUSED(weight);
78  MC_UNUSED(prev_value);
79  MC_UNUSED(prev_weight);
80  Result += (float)value;
81  return true;
82  }
83 
84  virtual void Remove(const T value, const float weight, const T next_value,
85  const float next_weight) override
86  {
87  MC_UNUSED(weight);
88  MC_UNUSED(next_value);
89  MC_UNUSED(next_weight);
90  Result -= (float)value;
91  }
92 
93  virtual void Reset() override
94  {
96  Result = 0.0;
97  }
98 
99 private:
101  double Result;
102 };
103 
107 template <typename T>
109 {
110 public:
111  /*
112  * Create an absolute sum statistic
113  *
114  * @param name Unique statistic name
115  *
116  */
117 
118  MCAbsoluteSum(const std::string& name = "AbsoluteSum") : MCArithmeticSum<T>(name), Result(0.0)
119  { }
120  virtual ~MCAbsoluteSum() { }
121 
122  virtual float GetResult() override
123  {
124  if (unlikely(!MCSampleStatistic<T>::Valid))
125  return MCFloatInfinity();
126 
127  return (float)Result;
128  }
129 
130  virtual MCSampleStatistic<T>* Clone() override
131  {
133 
134  *NewInstance = *this;
135  return NewInstance;
136  }
137 
138  virtual bool Add(const T value, const float weight, const T prev_value,
139  const float prev_weight) override
140  {
141  MC_UNUSED(weight);
142  MC_UNUSED(prev_value);
143  MC_UNUSED(prev_weight);
144  Result += (double)MCAbs(value);
145  return true;
146  }
147 
148  virtual void Remove(const T value, const float weight, const T next_value,
149  const float next_weight) override
150  {
151  MC_UNUSED(weight);
152  MC_UNUSED(next_value);
153  MC_UNUSED(next_weight);
154  Result -= (double)MCAbs(value);
155  }
156 
157 private:
159  double Result;
160 };
161 
165 template <typename T>
167 {
168 public:
169  /*
170  * Create an arithmetic mean statistic
171  *
172  * @param name Unique statistic name
173  *
174  */
175 
176  MCArithmeticMean(const std::string& name = "ArithmeticMean") : MCSampleStatistic<T>(name), Result(0.0)
177  { }
178  virtual ~MCArithmeticMean() {}
179 
180  virtual float GetResult() override
181  {
182  if (unlikely(!MCSampleStatistic<T>::Valid))
183  return MCFloatInfinity();
184 
185  return (float)Result;
186  }
187 
188  virtual MCSampleStatistic<T>* Clone() override
189  {
191 
192  *NewInstance = *this;
193  return NewInstance;
194  }
195 
196  virtual bool Add(const T value, const float weight, const T prev_value,
197  const float prev_weight) override
198  {
199  MC_UNUSED(weight);
200  MC_UNUSED(prev_value);
201  MC_UNUSED(prev_weight);
202  Result += (float)value / MCSampleStatistic<T>::Size;
203  return true;
204  }
205 
206  virtual void Remove(const T value, const float weight, const T next_value,
207  const float next_weight) override
208  {
209  MC_UNUSED(weight);
210  MC_UNUSED(next_value);
211  MC_UNUSED(next_weight);
212  Result -= (float)value / MCSampleStatistic<T>::Size;
213  }
214 
215  virtual void Reset() override
216  {
218  Result = 0;
219  }
220 
221 private:
223  double Result;
224 };
225 
229 template <typename T>
231 {
232 public:
233  /*
234  * Create an non-zero count statistic
235  *
236  * @param name Unique statistic name
237  *
238  */
239 
240  MCNonZeroCount(const std::string& name = "NonZeroCount") : MCSampleStatistic<T>(name), Count(0)
241  { }
242  virtual ~MCNonZeroCount() { }
243 
244  virtual float GetResult() override
245  {
246  if (unlikely(!MCSampleStatistic<T>::Valid))
247  return MCFloatInfinity();
248 
249  return (float)Count;
250  }
251 
252  virtual MCSampleStatistic<T>* Clone() override
253  {
255 
256  *NewInstance = *this;
257  return NewInstance;
258  }
259 
260  virtual bool Add(const T value, const float weight, const T prev_value,
261  const float prev_weight) override
262  {
263  MC_UNUSED(weight);
264  MC_UNUSED(prev_value);
265  MC_UNUSED(prev_weight);
266 
267  Count += (value > 0);
268  return true;
269  }
270 
271  virtual void Remove(const T value, const float weight, const T next_value,
272  const float next_weight) override
273  {
274  MC_UNUSED(weight);
275  MC_UNUSED(next_value);
276  MC_UNUSED(next_weight);
277 
278  Count -= (value > 0);
279  }
280 
281  virtual void Reset() override
282  {
284  Count = 0;
285  }
286 
287 private:
289  int Count;
290 };
291 
295 template <typename T>
297 {
298 public:
299  /*
300  * Create an arithmetic mean head statistic
301  *
302  * @param name Unique statistic name
303  *
304  */
305 
306  MCArithmeticMeanHead(int degree, const std::string& name = "ArithmeticMeanHead") :
307  MCSampleStatistic<T>(name), Degree(degree)
308  { }
309  virtual ~MCArithmeticMeanHead() { }
310 
311  virtual float GetResult() override
312  {
313  if (unlikely(!MCSampleStatistic<T>::Valid))
314  return MCFloatInfinity();
315 
316  double Result = 0;
317 
318  Degree = MCBound(1, Degree, MCSampleStatistic<T>::Size);
319  for (int i = 0; i < Degree; ++i)
320  {
321  Result += (double)SampleCache[i];
322  }
323  return (float)(Result / Degree);
324  }
325 
326  virtual MCSampleStatistic<T>* Clone() override
327  {
329 
330  *NewInstance = *this;
331  return NewInstance;
332  }
333 
334  virtual bool Add(const T value, const float weight, const T prev_value,
335  const float prev_weight) override
336  {
337  MC_UNUSED(weight);
338  MC_UNUSED(prev_value);
339  MC_UNUSED(prev_weight);
340  if ((int) SampleCache.size() == MCSampleStatistic<T>::Size)
341  SampleCache.erase(SampleCache.begin());
342 
343  SampleCache.push_back((float) value);
344  return true;
345  }
346 
347  virtual void Remove(const T value, const float weight, const T next_value,
348  const float next_weight) override
349  {
350  MC_UNUSED(value);
351  MC_UNUSED(weight);
352  MC_UNUSED(next_value);
353  MC_UNUSED(next_weight);
354  }
355 
356  virtual void Reset() override
357  {
359  SampleCache.clear();
360  }
361 
362 private:
364  int Degree;
366  std::vector<float> SampleCache;
367 };
368 
372 template <typename T>
374 {
375 public:
376  /*
377  * Create an arithmetic mean tail statistic
378  *
379  * @param name Unique statistic name
380  *
381  */
382 
383  MCArithmeticMeanTail(int degree, const std::string& name = "ArithmeticMeanTail") :
384  MCSampleStatistic<T>(name), Degree(degree)
385  { }
386  virtual ~MCArithmeticMeanTail() { }
387 
388  virtual float GetResult() override
389  {
390  if (unlikely(!MCSampleStatistic<T>::Valid))
391  return MCFloatInfinity();
392 
393  double Result = 0;
394 
395  Degree = MCBound(1, Degree, MCSampleStatistic<T>::Size);
396  for (int i = MCSampleStatistic<T>::Size-Degree; i < MCSampleStatistic<T>::Size; ++i)
397  {
398  Result += (double)SampleCache[i];
399  }
400  return (float)(Result / Degree);
401  }
402 
403  virtual MCSampleStatistic<T>* Clone() override
404  {
406 
407  *NewInstance = *this;
408  return NewInstance;
409  }
410 
411  virtual bool Add(const T value, const float weight, const T prev_value,
412  const float prev_weight) override
413  {
414  MC_UNUSED(weight);
415  MC_UNUSED(prev_value);
416  MC_UNUSED(prev_weight);
417  if ((int)SampleCache.size() == MCSampleStatistic<T>::Size)
418  SampleCache.erase(SampleCache.begin());
419 
420  SampleCache.push_back((float) value);
421  return true;
422  }
423 
424  virtual void Remove(const T value, const float weight, const T next_value,
425  const float next_weight) override
426  {
427  MC_UNUSED(value);
428  MC_UNUSED(weight);
429  MC_UNUSED(next_value);
430  MC_UNUSED(next_weight);
431  }
432 
433  virtual void Reset() override
434  {
436  SampleCache.clear();
437  }
438 
439 private:
441  int Degree;
443  std::vector<float> SampleCache;
444 };
445 
449 template <typename T>
451 {
452 public:
453  /*
454  * Create a weighted arithmetic mean statistic
455  *
456  * @param name Unique statistic name
457  *
458  */
459 
460  MCWeightedArithmeticMean(const std::string& name = "WeightedArithmeticMean") :
461  MCSampleStatistic<T>(name), Result(0.0), Weights(0.0)
462  { }
463  virtual ~MCWeightedArithmeticMean() {}
464 
465  virtual float GetResult() override
466  {
467  if (unlikely(!MCSampleStatistic<T>::Valid))
468  return MCFloatInfinity();
469 
470  return (float)(Result / Weights);
471  }
472 
473  virtual MCSampleStatistic<T>* Clone() override
474  {
476 
477  *NewInstance = *this;
478  return NewInstance;
479  }
480 
481  virtual bool Add(const T value, const float weight, const T prev_value,
482  const float prev_weight) override
483  {
484  MC_UNUSED(prev_value);
485  MC_UNUSED(prev_weight);
486  Result += (float)value*weight;
487  Weights += weight;
488  return true;
489  }
490 
491  virtual void Remove(const T value, const float weight, const T next_value,
492  const float next_weight) override
493  {
494  MC_UNUSED(next_value);
495  MC_UNUSED(next_weight);
496  Result -= (float)value*weight;
497  Weights -= weight;
498  }
499 
500  virtual void Reset() override
501  {
503  Weights = 0.0;
504  Result = 0.0;
505  }
506 
507 private:
509  double Result;
511  double Weights;
512 };
513 
517 template <typename T>
519 {
520 public:
521  /*
522  * Create a decreasingly weighted mean statistic
523  *
524  * @param name Unique statistic name
525  *
526  */
527 
528  MCDecreasinglyWeightedMean(const std::string& name = "DecreasinglyWeightedMean") :
530  { }
531  virtual ~MCDecreasinglyWeightedMean() {}
532 
533  virtual float GetResult() override
534  {
535  if (unlikely(!MCSampleStatistic<T>::Valid))
536  return MCFloatInfinity();
537 
538  double Sum = 0.0;
539  double WeightSum = 0.0;
540  double OneThirdWeight { 1.0 / 3.0 };
541  double TwoThirdWeight { 2.0 / 3.0 };
542  const unsigned int OneThirdCount { (unsigned int)MCSampleStatistic<T>::Size / 3 };
543  const unsigned int TwoThirdCount { (unsigned int)MCSampleStatistic<T>::Size*2 / 3 };
544 
545  foreach_i(i, sample, SampleCache)
546  {
547  if (i < OneThirdCount)
548  {
549  Sum += (double)(*sample)*OneThirdWeight;
550  WeightSum += OneThirdWeight;
551  } else
552  if (i >= OneThirdCount && i < TwoThirdCount)
553  {
554  Sum += (double)(*sample)*TwoThirdWeight;
555  WeightSum += TwoThirdWeight;
556  } else
557  if (i >= TwoThirdCount)
558  {
559  Sum += (double)(*sample);
560  WeightSum += 1.0;
561  }
562  }
563  return (float)Sum / WeightSum;
564  }
565 
566  virtual MCSampleStatistic<T>* Clone() override
567  {
569 
570  *NewInstance = *this;
571  return NewInstance;
572  }
573 
574  virtual bool Add(const T value, const float weight, const T prev_value,
575  const float prev_weight) override
576  {
577  MC_UNUSED(weight);
578  MC_UNUSED(prev_value);
579  MC_UNUSED(prev_weight);
580  if ((int)SampleCache.size() == MCSampleStatistic<T>::Size)
581  SampleCache.erase(SampleCache.begin());
582 
583  SampleCache.push_back((float)value);
584  return true;
585  }
586 
587  virtual void Remove(const T value, const float weight, const T next_value,
588  const float next_weight) override
589  {
590  MC_UNUSED(value);
591  MC_UNUSED(weight);
592  MC_UNUSED(next_value);
593  MC_UNUSED(next_weight);
594  }
595 
596  virtual void Reset() override
597  {
599  SampleCache.clear();
600  }
601 
602 private:
604  std::vector<float> SampleCache;
605 };
606 
610 template <typename T>
612 {
613 public:
614  /*
615  * Create a harmonic mean statistic
616  *
617  * @param name Unique statistic name
618  *
619  */
620 
621  MCHarmonicMean(const std::string& name = "HarmonicMean") : MCSampleStatistic<T>(name), Result(0)
622  { }
623  virtual ~MCHarmonicMean() { }
624 
625  virtual float GetResult() override
626  {
627  if (unlikely(!MCSampleStatistic<T>::Valid))
628  return MCFloatInfinity();
629 
630  return (float)((double)MCSampleStatistic<T>::Size / Result);
631  }
632 
633  virtual MCSampleStatistic<T>* Clone() override
634  {
636 
637  *NewInstance = *this;
638  return NewInstance;
639  }
640 
641  virtual bool Add(const T value, const float weight, const T prev_value,
642  const float prev_weight) override
643  {
644  MC_UNUSED(weight);
645  MC_UNUSED(prev_value);
646  MC_UNUSED(prev_weight);
647  if (value == (T)0)
648  return false;
649 
650  Result += (double)1.0 / value;
651  return true;
652  }
653 
654  virtual void Remove(const T value, const float weight, const T next_value,
655  const float next_weight) override
656  {
657  MC_UNUSED(weight);
658  MC_UNUSED(next_value);
659  MC_UNUSED(next_weight);
660 
661  Result -= (double)1.0 / value;
662  }
663 
664  virtual void Reset() override
665  {
667  Result = 0;
668  }
669 
670 private:
672  double Result;
673 };
674 
678 template <typename T>
680 {
681 public:
682  /*
683  * Create a geometric mean statistic
684  *
685  * @param name Unique statistic name
686  *
687  */
688 
689  MCGeometricMean(const std::string& name = "GeometricMean") : MCSampleStatistic<T>(name)
690  { }
691  virtual ~MCGeometricMean() {}
692 
693  virtual float GetResult() override
694  {
695  float Result = 1.0;
696 
697  for (auto& sample : SampleCache)
698  {
699  Result *= sample;
700  }
701  return Result;
702  }
703 
704  virtual MCSampleStatistic<T>* Clone() override
705  {
707 
708  *NewInstance = *this;
709  return NewInstance;
710  }
711 
712  virtual bool Add(const T value, const float weight, const T prev_value,
713  const float prev_weight) override
714  {
715  MC_UNUSED(weight);
716  MC_UNUSED(prev_value);
717  MC_UNUSED(prev_weight);
718  if (value <= (T)0.0)
719  return false;
720 
721  if ((int)SampleCache.size() == MCSampleStatistic<T>::Size)
722  SampleCache.erase(SampleCache.begin());
723 
724  SampleCache.push_back((float)pow((float)value, (float)1.0 / MCSampleStatistic<T>::Size));
725  return true;
726  }
727 
728  virtual void Remove(const T value, const float weight, const T next_value,
729  const float next_weight) override
730  {
731  MC_UNUSED(value);
732  MC_UNUSED(weight);
733  MC_UNUSED(next_value);
734  MC_UNUSED(next_weight);
735  }
736 
737  virtual void Reset() override
738  {
740  SampleCache.clear();
741  }
742 
743 private:
745  std::vector<float> SampleCache;
746 };
747 
751 template <typename T>
752 class MCQuartile : public MCSampleStatistic<T>
753 {
754 public:
755  /*
756  * Create a quartile-based statistic
757  *
758  * @param degree Degree-th quartile
759  * @param name Unique statistic name
760  *
761  */
762 
763  MCQuartile(int degree, const std::string& name) : MCSampleStatistic<T>(name),
764  Degree(MCBound(1, degree, 3)), DegreeMultiplier(Degree / 4.0)
765  { }
766  virtual ~MCQuartile() {}
767 
768  virtual void SetSize(int size) override
769  {
771  DegreeMultiplier = Degree / 4.0;
772  }
773 
774  virtual float GetResult() override
775  {
776  if (unlikely(MCSampleStatistic<T>::Samples < 2))
777  return MCFloatInfinity();
778  if (unlikely(MCSampleStatistic<T>::Samples == 2))
779  {
780  auto FirstIter = List.begin();
781  auto SecondIter = FirstIter++;
782 
783  return (*FirstIter+*SecondIter) / 2;
784  }
785  List.sort();
786 
787  auto Iter = List.begin();
788  unsigned int i = 0;
789  unsigned int ExpectedIndex { (unsigned int)((float)MCSampleStatistic<T>::Samples*DegreeMultiplier) };
790 
791  if (MCSampleStatistic<T>::Samples % 2 == 1)
792  {
793  for (; Iter != List.end(); ++Iter)
794  {
795  if (i == ExpectedIndex)
796  {
797  return (float)*Iter;
798  }
799  i++;
800  }
801  } else {
802  for (; Iter != List.end(); ++Iter)
803  {
804  if (i+1 == ExpectedIndex)
805  {
806  T TempValue = *Iter;
807 
808  ++Iter;
809  if (unlikely(Iter == List.end()))
810  {
811  return (float)TempValue;
812  }
813  return (float)(TempValue+*Iter) / 2;
814  }
815  i++;
816  }
817  }
818  return MCFloatInfinity();
819  }
820 
821  virtual bool Add(const T value, const float weight, const T prev_value,
822  const float prev_weight) override
823  {
824  MC_UNUSED(weight);
825  MC_UNUSED(prev_value);
826  MC_UNUSED(prev_weight);
827  List.push_back(value);
828  return true;
829  }
830 
831  virtual void Remove(const T value, const float weight, const T next_value,
832  const float next_weight) override
833  {
834  MC_UNUSED(weight);
835  MC_UNUSED(next_value);
836  MC_UNUSED(next_weight);
837 
838  for (auto Iter = List.begin(); Iter != List.end(); ++Iter)
839  {
840  if ((*Iter) == value)
841  {
842  List.erase(Iter);
843  return;
844  }
845  }
846  }
847 
848  virtual void Reset() override
849  {
851  List.clear();
852  }
853 
854 private:
856  std::list<T> List;
858  int Degree;
861 };
862 
866 template <typename T>
867 class MCFirstQuartile : public MCQuartile<T>
868 {
869  friend class MCIqr<T>;
870 public:
871  /*
872  * Create a first quartile statistic
873  *
874  * @param name Unique statistic name
875  *
876  */
877 
878  MCFirstQuartile(const std::string& name = "FirstQuartile") : MCQuartile<T>(1, name)
879  { }
880  virtual ~MCFirstQuartile() {}
881 
882  virtual MCSampleStatistic<T>* Clone() override
883  {
885 
886  *NewInstance = *this;
887  return NewInstance;
888  }
889 };
890 
894 template <typename T>
895 class MCMedian : public MCQuartile<T>
896 {
897 public:
898  /*
899  * Create a median statistic
900  *
901  * @param name Unique statistic name
902  *
903  */
904 
905  MCMedian(const std::string& name = "Median") : MCQuartile<T>(2, name)
906  { }
907  virtual ~MCMedian() {}
908 
909  virtual MCSampleStatistic<T>* Clone() override
910  {
912 
913  *NewInstance = *this;
914  return NewInstance;
915  }
916 };
917 
921 template <typename T>
922 class MCThirdQuartile : public MCQuartile<T>
923 {
924  friend class MCIqr<T>;
925 public:
926  /*
927  * Create a third quartile statistic
928  *
929  * @param name Unique statistic name
930  *
931  */
932 
933  MCThirdQuartile(const std::string& name = "ThirdQuartile") : MCQuartile<T>(3, name)
934  { }
935  virtual ~MCThirdQuartile() {}
936 
937  virtual MCSampleStatistic<T>* Clone() override
938  {
940 
941  *NewInstance = *this;
942  return NewInstance;
943  }
944 };
945 
949 template <typename T>
950 class MCIqr : public MCSampleStatistic<T>
951 {
952 public:
953  /*
954  * Create an interquartile range statistic
955  *
956  * @param name Unique statistic name
957  *
958  */
959 
960  MCIqr(const std::string& name = "InterquartileRange") : MCSampleStatistic<T>(name), Fq(), Tq()
961  { }
962  virtual ~MCIqr() {}
963 
964  virtual void SetSize(int size) override
965  {
967  Fq.SetSize(size);
968  Tq.SetSize(size);
969  }
970 
971  virtual float GetResult() override
972  {
973  return Fq.GetResult()-Tq.GetResult();
974  }
975 
976  virtual MCSampleStatistic<T>* Clone() override
977  {
978  MCIqr<T>* NewInstance = new MCIqr<T>(MCSampleStatistic<T>::Name);
979 
980  *NewInstance = *this;
981  return NewInstance;
982  }
983 
984  virtual bool Add(const T value, const float weight, const T prev_value,
985  const float prev_weight) override
986  {
987  Fq.AddValue(value, weight, prev_value, prev_weight);
988  Tq.AddValue(value, weight, prev_value, prev_weight);
989  return true;
990  }
991 
992  virtual void Remove(const T value, const float weight, const T next_value,
993  const float next_weight) override
994  {
995  Fq.RemoveValue(value, weight, next_value, next_weight);
996  Tq.RemoveValue(value, weight, next_value, next_weight);
997  }
998 
999 private:
1004 };
1005 
1009 template <typename T>
1011 {
1012 public:
1013  /*
1014  * Create a standard deviation statistic
1015  *
1016  * @param name Unique statistic name
1017  *
1018  */
1019 
1020  MCStandardDeviation(const std::string& name = "StandardDeviation") : MCArithmeticMean<T>(name)
1021  { }
1022  virtual ~MCStandardDeviation() {}
1023 
1024  virtual float GetResult() override
1025  {
1026  if (unlikely(!MCSampleStatistic<T>::Valid))
1027  return MCFloatInfinity();
1028 
1029  float Mean { MCArithmeticMean<T>::GetResult() };
1030  float FinalResult = 0.0;
1031 
1032  for (int i = 0; i < MCSampleStatistic<T>::Size; ++i)
1033  {
1034  FinalResult += (MCSampleStatistic<T>::Storage[i]-Mean)*(MCSampleStatistic<T>::Storage[i]-Mean);
1035  }
1036  FinalResult /= (MCSampleStatistic<T>::Size-1);
1037  FinalResult = sqrt(FinalResult);
1038  return FinalResult;
1039  }
1040 
1041  virtual MCSampleStatistic<T>* Clone() override
1042  {
1044 
1045  *NewInstance = *this;
1046  return NewInstance;
1047  }
1048 };
1049 
1053 template <typename T>
1054 class MCMinimum : public MCSampleStatistic<T>
1055 {
1056 public:
1057  /*
1058  * Create a minimum statistic
1059  *
1060  * @param name Unique statistic name
1061  *
1062  */
1063 
1064  MCMinimum(const std::string& name = "Minimum") : MCSampleStatistic<T>(name), Result(MCFloatInfinity())
1065  { }
1066  virtual ~MCMinimum() {}
1067 
1068  virtual float GetResult() override
1069  {
1070  if (unlikely(!MCSampleStatistic<T>::Valid))
1071  return MCFloatInfinity();
1072 
1073  return Result;
1074  }
1075 
1076  virtual MCSampleStatistic<T>* Clone() override
1077  {
1079 
1080  *NewInstance = *this;
1081  return NewInstance;
1082  }
1083 
1084  virtual bool Add(const T value, const float weight, const T prev_value,
1085  const float prev_weight) override
1086  {
1087  MC_UNUSED(weight);
1088  MC_UNUSED(prev_value);
1089  MC_UNUSED(prev_weight);
1090  if (unlikely(MCIsDoubleInfinity(Result)))
1091  {
1092  // Recalculate the minimum value if needed
1093  if (likely(MCSampleStatistic<T>::Valid))
1094  {
1096  for (int i = 1; i < MCSampleStatistic<T>::Size; ++i)
1097  {
1099  }
1100  } else
1101  // Initial setting of the minimal value
1102  Result = value;
1103  } else {
1104  Result = MCMin(Result, (double)value);
1105  }
1106  return true;
1107  }
1108 
1109  virtual void Remove(const T value, const float weight, const T next_value,
1110  const float next_weight) override
1111  {
1112  MC_UNUSED(weight);
1113  MC_UNUSED(next_value);
1114  MC_UNUSED(next_weight);
1115  // Invalidate the current minimum
1116  if (unlikely(value == Result))
1117  {
1119  }
1120  }
1121 
1122  virtual void Reset() override
1123  {
1125  Result = MCFloatInfinity();
1126  }
1127 
1128 private:
1130  double Result;
1131 };
1132 
1136 template <typename T>
1137 class MCMaximum : public MCSampleStatistic<T>
1138 {
1139 public:
1140  /*
1141  * Create a maximum statistic
1142  *
1143  * @param name Unique statistic name
1144  *
1145  */
1146 
1147  MCMaximum(const std::string& name = "Maximum") : MCSampleStatistic<T>(name), Result(MCFloatInfinity())
1148  { }
1149  virtual ~MCMaximum() {}
1150 
1151  virtual float GetResult() override
1152  {
1153  if (unlikely(!MCSampleStatistic<T>::Valid))
1154  return MCFloatInfinity();
1155 
1156  return Result;
1157  }
1158 
1159  virtual MCSampleStatistic<T>* Clone() override
1160  {
1162 
1163  *NewInstance = *this;
1164  return NewInstance;
1165  }
1166 
1167  virtual bool Add(const T value, const float weight, const T prev_value,
1168  const float prev_weight) override
1169  {
1170  MC_UNUSED(weight);
1171  MC_UNUSED(prev_value);
1172  MC_UNUSED(prev_weight);
1173  if (unlikely(MCIsDoubleInfinity(Result)))
1174  {
1175  // Recalculate the maximum value if needed
1176  if (likely(MCSampleStatistic<T>::Valid))
1177  {
1179  for (int i = 1; i < MCSampleStatistic<T>::Size; ++i)
1180  {
1182  }
1183  } else
1184  // Initial setting of the minimal value
1185  Result = value;
1186  } else {
1187  Result = MCMax(Result, (double)value);
1188  }
1189  return true;
1190  }
1191 
1192  virtual void Remove(const T value, const float weight, const T next_value,
1193  const float next_weight) override
1194  {
1195  MC_UNUSED(weight);
1196  MC_UNUSED(next_value);
1197  MC_UNUSED(next_weight);
1198  // Invalidate the current maximum
1199  if (unlikely(value == Result))
1200  {
1202  }
1203  }
1204 
1205  virtual void Reset() override
1206  {
1209  }
1210 
1211 private:
1213  double Result;
1214 };
1215 
1219 template <typename T>
1221 {
1222 public:
1223  /*
1224  * Create a square sum statistic
1225  *
1226  * @param name Unique statistic name
1227  *
1228  */
1229 
1230  MCSquareSum(const std::string& name = "SquareSum") : MCSampleStatistic<T>(name), Result(0.0)
1231  { }
1232  virtual ~MCSquareSum() {}
1233 
1234  virtual float GetResult() override
1235  {
1236  if (unlikely(MCSampleStatistic<T>::Samples == 0))
1237  {
1238  return MCFloatInfinity();
1239  }
1240  return Result;
1241  }
1242 
1243  virtual MCSampleStatistic<T>* Clone() override
1244  {
1246 
1247  *NewInstance = *this;
1248  return NewInstance;
1249  }
1250 
1251  virtual bool Add(const T value, const float weight, const T prev_value,
1252  const float prev_weight) override
1253  {
1254  MC_UNUSED(weight);
1255  MC_UNUSED(prev_value);
1256  MC_UNUSED(prev_weight);
1257  Result += (double)value*value;
1258  return true;
1259  }
1260 
1261  virtual void Remove(const T value, const float weight, const T next_value,
1262  const float next_weight) override
1263  {
1264  MC_UNUSED(weight);
1265  MC_UNUSED(next_value);
1266  MC_UNUSED(next_weight);
1267  Result -= (double)value*value;
1268  }
1269 
1270  virtual void Reset() override
1271  {
1273  Result = 0.0;
1274  }
1275 
1276 protected:
1278  double Result;
1279 };
1280 
1281 
1285 template <typename T>
1287 {
1288 public:
1289  /*
1290  * Create a logarithmic square sum statistic
1291  *
1292  * @param name Unique statistic name
1293  *
1294  */
1295 
1296  MCLogarithmicSquareSum(const std::string& name = "LogarithmicSquareSum") : MCSquareSum<T>(name)
1297  { }
1298  virtual ~MCLogarithmicSquareSum() { }
1299 
1300  virtual MCSampleStatistic<T>* Clone() override
1301  {
1303 
1304  *NewInstance = *this;
1305  return NewInstance;
1306  }
1307 
1308  virtual bool Add(const T value, const float weight, const T prev_value,
1309  const float prev_weight) override
1310  {
1311  MC_UNUSED(weight);
1312  MC_UNUSED(prev_value);
1313  MC_UNUSED(prev_weight);
1314  MCSquareSum<T>::Result += log((double)value*value);
1315  return true;
1316  }
1317 
1318  virtual void Remove(const T value, const float weight, const T next_value,
1319  const float next_weight) override
1320  {
1321  MC_UNUSED(weight);
1322  MC_UNUSED(next_value);
1323  MC_UNUSED(next_weight);
1324  MCSquareSum<T>::Result -= log((double)value*value);
1325  }
1326 };
1327 
1331 template <typename T>
1333 {
1334 public:
1335  /*
1336  * Create a root mean square statistic
1337  *
1338  * @param name Unique statistic name
1339  *
1340  */
1341 
1342  MCRootMeanSquare(const std::string& name = "RootMeanSquare") : MCSquareSum<T>(name)
1343  { }
1344  virtual ~MCRootMeanSquare() {}
1345 
1346  virtual float GetResult() override
1347  {
1348  if (unlikely(MCSampleStatistic<T>::Samples == 0))
1349  {
1350  return MCFloatInfinity();
1351  }
1353  }
1354 
1355  virtual MCSampleStatistic<T>* Clone() override
1356  {
1358 
1359  *NewInstance = *this;
1360  return NewInstance;
1361  }
1362 };
1363 
1367 template <typename T>
1368 class MCPower : public MCSquareSum<T>
1369 {
1370 public:
1371  /*
1372  * Create a power statistic for signals
1373  *
1374  * @param name Unique statistic name
1375  *
1376  */
1377 
1378  MCPower(const std::string& name = "Power") : MCSquareSum<T>(name)
1379  { }
1380  virtual ~MCPower() {}
1381 
1382  virtual float GetResult() override
1383  {
1384  if (unlikely(MCSampleStatistic<T>::Samples == 0))
1385  {
1386  return MCFloatInfinity();
1387  }
1389  }
1390 
1391  virtual MCSampleStatistic<T>* Clone() override
1392  {
1393  MCPower<T>* NewInstance = new MCPower<T>(MCSampleStatistic<T>::Name);
1394 
1395  *NewInstance = *this;
1396  return NewInstance;
1397  }
1398 };
1399 
1403 template <typename T>
1405 {
1406 public:
1407  /*
1408  * Create a root counter statistic
1409  *
1410  * @param name Unique statistic name
1411  *
1412  */
1413 
1414  MCRootCounter(const std::string& name = "RootCounter") : MCSampleStatistic<T>(name), Result(0)
1415  { }
1416  virtual ~MCRootCounter() {}
1417 
1418  virtual float GetResult() override
1419  {
1420  if (unlikely(!MCSampleStatistic<T>::Valid))
1421  return MCFloatInfinity();
1422 
1423  return (float)Result;
1424  }
1425 
1426  virtual MCSampleStatistic<T>* Clone() override
1427  {
1429 
1430  *NewInstance = *this;
1431  return NewInstance;
1432  }
1433 
1434  virtual bool Add(const T value, const float weight, const T prev_value,
1435  const float prev_weight) override
1436  {
1437  MC_UNUSED(weight);
1438  if (MCIsFloatInfinity(prev_weight))
1439  return true;
1440 
1441  if ((value > (T)0 && prev_value < (T)0) ||
1442  (value < (T)0 && prev_value > (T)0) ||
1443  value == (T)0)
1444  {
1445  Result++;
1446  }
1447  return true;
1448  }
1449 
1450  virtual void Remove(const T value, const float weight, const T next_value,
1451  const float next_weight) override
1452  {
1453  MC_UNUSED(weight);
1454  MC_UNUSED(next_weight);
1455  if ((value > (T)0 && next_value < (T)0) ||
1456  (value < (T)0 && next_value > (T)0) ||
1457  value == (T)0)
1458  {
1459  Result--;
1460  }
1461  }
1462 
1463  virtual void Reset() override
1464  {
1466  Result = 0;
1467  }
1468 
1469 private:
1471  int Result;
1472 };
1473 
1477 template <typename T>
1479 {
1480 public:
1481  /*
1482  * Create a value range counter statistic
1483  *
1484  * @param range_lower_limit Lower limit of the range
1485  * @param range_upper_limit Upper limit of the range
1486  * @param name Unique statistic name
1487  *
1488  * The statistic counts the values falling into a range in a series.
1489  *
1490  */
1491 
1492  MCValueRangeCounter(float range_lower_limit, float range_upper_limit,
1493  const std::string& name = "ValueRangeCounter") :
1494  MCSampleStatistic<T>(name), Result(0), RangeLowerLimit(MCMin(range_lower_limit, range_upper_limit)),
1495  RangeUpperLimit(MCMax(range_lower_limit, range_upper_limit))
1496  { }
1497  virtual ~MCValueRangeCounter() {}
1498 
1499  virtual float GetResult() override
1500  {
1501  if (unlikely(!MCSampleStatistic<T>::Valid))
1502  return MCFloatInfinity();
1503 
1504  return (float)Result;
1505  }
1506 
1507  virtual MCSampleStatistic<T>* Clone() override
1508  {
1509  MCValueRangeCounter<T>* NewInstance = new MCValueRangeCounter<T>(RangeLowerLimit, RangeUpperLimit,
1511 
1512  *NewInstance = *this;
1513  return NewInstance;
1514  }
1515 
1516  virtual bool Add(const T value, const float weight, const T prev_value,
1517  const float prev_weight) override
1518  {
1519  MC_UNUSED(prev_value);
1520  MC_UNUSED(weight);
1521  MC_UNUSED(prev_weight);
1522  if ((float)value > RangeLowerLimit && (float)value < RangeUpperLimit)
1523  {
1524  Result++;
1525  }
1526  return true;
1527  }
1528 
1529  virtual void Remove(const T value, const float weight, const T next_value,
1530  const float next_weight) override
1531  {
1532  MC_UNUSED(weight);
1533  MC_UNUSED(next_value);
1534  MC_UNUSED(next_weight);
1535  if ((float)value > RangeLowerLimit && (float)value < RangeUpperLimit)
1536  {
1537  Result--;
1538  }
1539  }
1540 
1541  virtual void Reset() override
1542  {
1544  Result = 0;
1545  }
1546 
1547 private:
1549  int Result;
1554 };
1555 
1559 template <typename T>
1561 {
1562 public:
1563  /*
1564  * Create a value change counter statistic
1565  *
1566  * @param name Unique statistic name
1567  *
1568  * The statistic sums the absolute difference between neighbor values in a series.
1569  *
1570  */
1571 
1572  MCValueChangeCounter(const std::string& name = "ValueChangeCounter") : MCSampleStatistic<T>(name),
1574  { }
1575  virtual ~MCValueChangeCounter() {}
1576 
1577  virtual float GetResult() override
1578  {
1579  if (unlikely(!MCSampleStatistic<T>::Valid))
1580  return MCDoubleInfinity();
1581 
1582  return (float)Result;
1583  }
1584 
1585  virtual MCSampleStatistic<T>* Clone() override
1586  {
1588 
1589  *NewInstance = *this;
1590  return NewInstance;
1591  }
1592 
1593  virtual bool Add(const T value, const float weight, const T prev_value,
1594  const float prev_weight) override
1595  {
1596  MC_UNUSED(weight);
1597  MC_UNUSED(prev_weight);
1598  if (unlikely(MCIsDoubleInfinity(Result)))
1599  {
1600  Result = MCAbs(prev_value-value);
1601  } else {
1602  Result += MCAbs(prev_value-value);
1603  }
1604  return true;
1605  }
1606 
1607  virtual void Remove(const T value, const float weight, const T next_value,
1608  const float next_weight) override
1609  {
1610  MC_UNUSED(weight);
1611  MC_UNUSED(next_weight);
1612  Result -= MCAbs(next_value-value);
1613  }
1614 
1615  virtual void Reset() override
1616  {
1619  }
1620 
1621 private:
1623  double Result;
1624 };
1625 
1629 template <typename T>
1631 {
1632 public:
1633  /*
1634  * Create a value trend counter statistic
1635  *
1636  * @param positive_trend Whether it counts the positive (increasing) trend
1637  * @param name Unique statistic name
1638  *
1639  * The statistic can count the increasing or decreasing trends of a value series,
1640  * but the intervals are skipped when the value stagnates (it does not change).
1641  *
1642  */
1643 
1644  MCValueTrendCounter(bool positive_trend, const std::string& name = "ValueTrendCounter") :
1645  MCSampleStatistic<T>(name), PositiveTrend(positive_trend), Result(0.0)
1646  { }
1647  virtual ~MCValueTrendCounter() {}
1648 
1649  virtual float GetResult() override
1650  {
1651  if (unlikely(!MCSampleStatistic<T>::Valid))
1652  return MCDoubleInfinity();
1653 
1654  return (float)Result;
1655  }
1656 
1657  virtual MCSampleStatistic<T>* Clone() override
1658  {
1660 
1661  *NewInstance = *this;
1662  return NewInstance;
1663  }
1664 
1665  virtual bool Add(const T value, const float weight, const T prev_value,
1666  const float prev_weight) override
1667  {
1668  MC_UNUSED(weight);
1669  MC_UNUSED(prev_weight);
1670  if (PositiveTrend && prev_value-value > 0)
1671  Result++;
1672  if (!PositiveTrend && prev_value-value < 0)
1673  Result++;
1674  return true;
1675  }
1676 
1677  virtual void Remove(const T value, const float weight, const T next_value,
1678  const float next_weight) override
1679  {
1680  MC_UNUSED(weight);
1681  MC_UNUSED(next_weight);
1682  if (PositiveTrend && value-next_value > 0)
1683  Result--;
1684  if (!PositiveTrend && value-next_value < 0)
1685  Result--;
1686  }
1687 
1688  virtual void Reset() override
1689  {
1691  Result = 0.0;
1692  }
1693 
1694 private:
1698  double Result;
1699 };
1700 
1713 template <typename T>
1714 float MCCalculateVectorStatistic(const std::vector<T>& vector, MCSampleStatistic<T>& statistic)
1715 {
1716  if (vector.size() < 2)
1717  {
1718  MC_WARNING("Vector size must be at least 2 for statistics calculations (%d)", vector.size());
1719  return MCFloatInfinity();
1720  }
1721  MCSamples<T> VectorSamples(vector.size(), statistic);
1722 
1723  VectorSamples << vector;
1724  return statistic.GetResult();
1725 }
1726 
1739 template <typename T>
1740 float MCCalculateTableStatistic(const std::vector<std::vector<T> >& table, MCSampleStatistic<T>& statistic)
1741 {
1742  if (!MCIsConsistentTable(table))
1743  {
1744  MC_WARNING("The table is not consistent for statistics calculations");
1745  return MCFloatInfinity();
1746  }
1747  MCSamples<T> Samples(table.size()*table[0].size(), statistic);
1748 
1749  for (auto& row : table)
1750  Samples << row;
1751 
1752  return statistic.GetResult();
1753 }
1754 
1768 template <typename T>
1769 float MCCalculateColumnStatInTable(const std::vector<std::vector<T> >& table, int column,
1770  MCSampleStatistic<T>& statistic)
1771 {
1772  MCSamples<T> ColumnSamples(table.size(), statistic);
1773  int ColumnIndex = MCBound(0, column, (int)table.size()-1);
1774 
1775  for (auto& row : table)
1776  {
1777  ColumnSamples << row[ColumnIndex];
1778  }
1779  return statistic.GetResult();
1780 }
1781 
1793 template <typename T, typename U >
1794 MC::FloatList MCCalculateColumnStatsInTable(const std::vector<std::vector<T> >& table)
1795 {
1796  MC::FloatList Results;
1797 
1798  for (unsigned int i = 0; i < table[0].size(); ++i)
1799  {
1800  Results.push_back(MCCalculateColumnStatInTable(table, i, *new U));
1801  }
1802  return Results;
1803 }
1804 
1818 template <typename T>
1819 float MCCalculateDiagonalStatInTable(const std::vector<std::vector<T> >& table,
1820  MCSampleStatistic<T>& statistic, bool topleft_to_rightbottom = true)
1821 {
1822  if (table.empty())
1823  return 0.0;
1824  if (!MCIsConsistentTable(table) || table.size() != table[0].size())
1825  {
1826  MC_WARNING("Table is not consistent or squared to calculate statistics.");
1827  return 0.0;
1828  }
1829  MCSamples<T> DiagonalSamples(table.size(), statistic);
1830 
1831  for (unsigned int i = 0; i < table.size(); ++i)
1832  {
1833  const int Index = topleft_to_rightbottom ? i : (table.size()-i-1);
1834 
1835  DiagonalSamples << table[Index][Index];
1836  }
1837  return statistic.GetResult();
1838 }
1839 
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.
Sample cache class.
Definition: MCSamples.hpp:52
virtual float GetResult() override
Get the current result of the statistic.
Absolute sum statistic.
Power statistic for signals.
Minimum 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.
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.
Definition: MCDefs.cpp:116
Arithmetic mean head statistic.
bool MCIsDoubleInfinity(const double value)
Check a value for double infinity.
Definition: MCDefs.cpp:132
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.
Definition: MCLog.hpp:43
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.
Definition: MCDefs.hpp:527
T MCAbs(const T &value)
Calculate absolute value.
Definition: MCDefs.hpp:399
#define foreach_i(_i, _iter, _container)
For each cycle with auto keyword and index values.
Definition: MCDefs.hpp:63
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.
Definition: MCSamples.hpp:718
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.
Definition: MCSamples.hpp:696
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.
Definition: MCSamples.hpp:732
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.
Definition: MCSamples.hpp:30
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.
Definition: MCDefs.cpp:122
virtual float GetResult() override
Get the current result of the statistic.
Square sum 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.
Definition: MCDefs.hpp:601
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 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 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.
Maximum statistic.
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.
Definition: MCDefs.cpp:110
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.
Harmonic mean 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.
Median statistic.
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.
Root 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 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.