#include <UtilBlockedRunningAverage.h>
Inheritance diagram for UtilBlockedRunningAverage:

Public Member Functions | |
| UtilBlockedRunningAverage (int size=10) | |
| virtual | ~UtilBlockedRunningAverage () |
| void | SetSampleSize (int size) |
| int | Add (double val) |
| int | Add (double mean, double sigma, int nsamples) |
| double | LastSample () const |
| virtual void | Clear (bool clear_population=true) |
Private Attributes | |
| std::deque< double > | fMeans |
| std::deque< double > | fSigmas |
| std::deque< size_t > | fNsamples |
This class is like UtilRunningAverage but instead of only allowing single samples to be accumulated, it allows blocks of samples that already have statistics calculated on them to be accumulated such that correct statistics can be formed on the union of all blocks.
In this class, the "population" statistics will be identical to that of UtilRunningAverage.
The "sample" statistics will in general differ because a different rule governs the sample size. Namely this class will keep all blocked samples such that removing the oldest does not bring the sample size below the target.
All blocked samples are retained so that the statistics can be calculated in O(1) time.
This class uses UtilRunningAverage to perform some of the lifting.
Created on: Fri Apr 15 10:13:08 2005
Definition at line 49 of file UtilBlockedRunningAverage.h.
|
|
Definition at line 3 of file UtilBlockedRunningAverage.cxx. 00004 : UtilRunningAverage(size) 00005 { 00006 }
|
|
|
Definition at line 52 of file UtilBlockedRunningAverage.h. 00052 {}
|
|
||||||||||||||||
|
Add a new block of samples. Return the size of the sample set after this addition. Note, this size be be smaller than before the addition if a larger block is pushed out of the set. However, once the sample size is larger than the target, it will never be allowed to go smaller than the target. Definition at line 40 of file UtilBlockedRunningAverage.cxx. References fMeans, fNsamples, fSigmas, and SetSampleSize(). 00041 {
00042 fNsamples.push_front(nsamples);
00043 fMeans.push_front(mean);
00044 fSigmas.push_front(sigma);
00045
00046 double x = nsamples*mean;
00047 double xx = sigma*sigma*(nsamples-1) + nsamples*mean*mean;
00048
00049 fSx += x;
00050 fSxx += xx;
00051
00052 fPx += x;
00053 fPxx += xx;
00054
00055 fPn += nsamples;
00056 fSn += nsamples;
00057
00058 this->SetSampleSize(fSampleTargetSize); // remove any blocks if total sample is full
00059 return fSn;
00060 }
|
|
|
Add a new single (not blocked!) value to the sample and population. Returns the size of the sample set after this addition. Reimplemented from UtilRunningAverage. Definition at line 36 of file UtilBlockedRunningAverage.cxx. 00037 {
00038 return this->Add(val,0,1);
00039 }
|
|
|
Clear all samples. If clear_population is false, only the sample set is cleared. Reimplemented from UtilRunningAverage. Definition at line 67 of file UtilBlockedRunningAverage.cxx. References UtilRunningAverage::Clear(), fMeans, fNsamples, and fSigmas. 00068 {
00069 this->UtilRunningAverage::Clear(clear_population);
00070 fMeans.clear();
00071 fSigmas.clear();
00072 fNsamples.clear();
00073 }
|
|
|
Return the last sample, ie, the last mean added. Returns 0.0 if samples are empty. Reimplemented from UtilRunningAverage. Definition at line 61 of file UtilBlockedRunningAverage.cxx. References fMeans.
|
|
|
Set the target sample size. The actual sample size may be temporarily smaller than this. Once full, the actual sample size will never go below this but in general will fluctuate higher as more blocks of samples are added or removed. Reimplemented from UtilRunningAverage. Definition at line 7 of file UtilBlockedRunningAverage.cxx. References fMeans, fNsamples, and fSigmas. Referenced by Add(). 00008 {
00009 fSampleTargetSize = size; // target size
00010
00011 size_t current_size = fNsamples.size();
00012 if (!current_size) return;
00013
00014 size_t nlost = fNsamples.back();
00015 while (fSn - nlost >= fSampleTargetSize) {
00016
00017 double lost_mean = fMeans.back();
00018 double lost_sigma = fSigmas.back();
00019
00020 double x = nlost*lost_mean;
00021 double xx = lost_sigma*lost_sigma*(nlost-1) + nlost*lost_mean*lost_mean;
00022
00023 fSn -= nlost;
00024 fSx -= x;
00025 fSxx -= xx;
00026
00027 fNsamples.pop_back();
00028 fMeans.pop_back();
00029 fSigmas.pop_back();
00030
00031 if (!fNsamples.size()) break;
00032 nlost = fNsamples.back();
00033 }
00034 }
|
|
|
Definition at line 82 of file UtilBlockedRunningAverage.h. Referenced by Add(), Clear(), LastSample(), and SetSampleSize(). |
|
|
Definition at line 83 of file UtilBlockedRunningAverage.h. Referenced by Add(), Clear(), and SetSampleSize(). |
|
|
Definition at line 82 of file UtilBlockedRunningAverage.h. Referenced by Add(), Clear(), and SetSampleSize(). |
1.3.9.1