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

Public Member Functions | |
| UtilRunningAverageVector (int vector_size, int target_sample_size=10) | |
| Create a UtilRunningAverage with optional sample size. | |
| virtual | ~UtilRunningAverageVector () |
| virtual void | SetSampleSize (int size) |
| Set the number of samples to retain. | |
| virtual int | GetSampleSize () const |
| Get the current sample size. | |
| int | GetPopulationSize () const |
| Get the current population size. | |
| bool | IsSampleFull () const |
| Return true if the sample set is up to the configured size. | |
| virtual int | Add (const std::vector< double > &val) |
| std::vector< double > | SampleMean () const |
| std::vector< double > | PopulationMean () const |
| As above but for the population. | |
| std::vector< double > | SampleSigma () const |
| std::vector< double > | PopulationSigma () const |
| As above but for the population. | |
| virtual std::vector< double > | LastSample () const |
| Return the last sample. Returns empty vector if there are no samples. | |
| virtual void | Clear (bool clear_population=true) |
| std::vector< double > | SampleDeviation (const std::vector< double > &value) const |
| std::vector< double > | PopulationDeviation (const std::vector< double > &value) const |
| Same as above but for the population. | |
Protected Attributes | |
| std::deque< std::vector< double > > | fSamples |
| std::vector< double > | fSx |
| std::vector< double > | fSxx |
| std::vector< double > | fPx |
| std::vector< double > | fPxx |
| size_t | fSampleTargetSize |
| size_t | fSn |
| size_t | fPn |
Created on: Fri Apr 15 10:16:28 2005
Definition at line 29 of file UtilRunningAverageVector.h.
|
||||||||||||
|
Create a UtilRunningAverage with optional sample size.
Definition at line 8 of file UtilRunningAverageVector.cxx. References SetSampleSize(). 00010 :fSx(vector_size,0),fSxx(vector_size,0) 00011 , fPx(vector_size,0),fPxx(vector_size,0) 00012 , fSampleTargetSize(0), fSn(0), fPn(0) 00013 { 00014 this->SetSampleSize(target_sample_size); 00015 }
|
|
|
Definition at line 16 of file UtilRunningAverageVector.cxx. 00017 {
00018 }
|
|
|
Add a new value to the sample and population. Returns the size of the sample set after this addition. Reimplemented in UtilBlockedRunningAverageVector. Definition at line 46 of file UtilRunningAverageVector.cxx. References fPx, fPxx, fSamples, fSn, fSx, and fSxx. 00047 {
00048 // Remove effect of oldest sample if sample set is full
00049 if (fSn == fSampleTargetSize) {
00050 vector<double>& old = fSamples.back();
00051 for (size_t ind=0; ind<old.size(); ++ind) {
00052 fSx[ind] -= old[ind];
00053 fSxx[ind] -= old[ind]*old[ind];
00054 }
00055 --fSn;
00056 fSamples.pop_back();
00057 }
00058
00059 // Add new sample
00060 fSamples.push_front(val);
00061 ++fSn;
00062 ++fPn;
00063 for (size_t ind=0; ind<val.size(); ++ind) {
00064 fSx[ind] += val[ind];
00065 fSxx[ind] += val[ind]*val[ind];
00066
00067 fPx[ind] += val[ind];
00068 fPxx[ind] += val[ind]*val[ind];
00069 }
00070 return fSn;
00071 }
|
|
|
Clear all samples. If clear_population is false, only the sample set is cleared. Reimplemented in UtilBlockedRunningAverageVector. Definition at line 126 of file UtilRunningAverageVector.cxx. References fPn, fPx, fPxx, fSamples, fSn, fSx, and fSxx. Referenced by UtilBlockedRunningAverageVector::Clear(). 00127 {
00128 fSamples.clear();
00129 fSn = 0;
00130
00131 size_t siz = fSx.size();
00132 for (size_t ind = 0; ind<siz; ++ind) {
00133 fSx[ind] = 0;
00134 fSxx[ind] = 0;
00135 }
00136
00137 if (clear_population) {
00138 for (size_t ind = 0; ind<siz; ++ind) {
00139 fPx[ind] = 0;
00140 fPxx[ind] = 0;
00141 }
00142 fPn = 0;
00143 }
00144 }
|
|
|
Get the current population size.
Definition at line 36 of file UtilRunningAverageVector.cxx. Referenced by BeamMonSwicPedsDbuModule::Dump(), and BDSwicPedAccessor::GetPeds(). 00037 {
00038 return fPn;
00039 }
|
|
|
Get the current sample size.
Definition at line 32 of file UtilRunningAverageVector.cxx. 00033 {
00034 return fSn;
00035 }
|
|
|
Return true if the sample set is up to the configured size.
Definition at line 41 of file UtilRunningAverageVector.cxx. References fSn. Referenced by BDSwicPedAccessor::SetSpillTime(). 00042 {
00043 return fSn >= fSampleTargetSize;
00044 }
|
|
|
Return the last sample. Returns empty vector if there are no samples.
Reimplemented in UtilBlockedRunningAverageVector. Definition at line 120 of file UtilRunningAverageVector.cxx. References fSamples. 00121 {
00122 if (!fSn) return vector<double>();
00123 return fSamples.front();
00124 }
|
|
|
Same as above but for the population.
Definition at line 166 of file UtilRunningAverageVector.cxx. References PopulationMean(), and PopulationSigma(). 00167 {
00168 vector<double> ret;
00169
00170 vector<double> mean = this->PopulationMean();
00171 size_t siz = mean.size();
00172 if (!siz) return ret;
00173 vector<double> sig = this->PopulationSigma();
00174 for (size_t ind=0; ind<siz; ++ind) {
00175 double sigind = sig[ind];
00176 if (sigind == 0.0) {
00177 if (value[ind] > mean[ind])
00178 sigind = +numeric_limits<double>::infinity();
00179 else
00180 sigind = -numeric_limits<double>::infinity();
00181 }
00182 ret.push_back((mean[ind]-value[ind])/sigind);
00183 }
00184 return ret;
00185 }
|
|
|
As above but for the population.
Definition at line 82 of file UtilRunningAverageVector.cxx. Referenced by BeamMonSwicPedsDbuModule::Dump(), BDSwicPedAccessor::GetPeds(), and PopulationDeviation(). 00083 {
00084 if (!fPn) return vector<double>();
00085
00086 size_t siz= fPx.size();
00087
00088 vector<double> ret(siz,1.0/fPn);
00089 for (size_t ind=0; ind<siz; ++ind) ret[ind] *= fPx[ind];
00090 return ret;
00091 }
|
|
|
As above but for the population.
Definition at line 106 of file UtilRunningAverageVector.cxx. References fPn, fPx, and fPxx. Referenced by BeamMonSwicPedsDbuModule::Dump(), BDSwicPedAccessor::GetPeds(), and PopulationDeviation(). 00107 {
00108 if (fPn<=1) return vector<double>();
00109 size_t siz = fPx.size();
00110 vector<double> ret(siz,0);
00111 for (size_t ind=0; ind<siz; ++ind) {
00112 double dif = fPxx[ind] - fPx[ind]*fPx[ind]/fPn;
00113 if (dif < 0) dif = 0;
00114 double var = (dif)/(fPn-1);
00115 ret[ind] = sqrt(var);
00116 }
00117 return ret;
00118 }
|
|
|
Convenience routine to return the number of sigma the value is away from the mean. The sign of the result reflects if the value is smaller or larger than the mean. The value can be +/- std::numeric_limits<double>::infinity() if Sigma is zero (either because of two few samples, or accidently). Definition at line 146 of file UtilRunningAverageVector.cxx. References SampleMean(), and SampleSigma(). 00147 {
00148 vector<double> ret;
00149
00150 vector<double> mean = this->SampleMean();
00151 size_t siz = mean.size();
00152 if (!siz) return ret;
00153 vector<double> sig = this->SampleSigma();
00154 for (size_t ind=0; ind<siz; ++ind) {
00155 double sigind = sig[ind];
00156 if (sigind == 0.0) {
00157 if (value[ind] > mean[ind])
00158 sigind = +numeric_limits<double>::infinity();
00159 else
00160 sigind = -numeric_limits<double>::infinity();
00161 }
00162 ret.push_back((mean[ind]-value[ind])/sigind);
00163 }
00164 return ret;
00165 }
|
|
|
Return the arithmetic mean. Will use the number of samples actually collected and will return empty vector if there are no samples. Definition at line 73 of file UtilRunningAverageVector.cxx. Referenced by SampleDeviation(). 00074 {
00075 if (!fSn) return vector<double>();
00076
00077 size_t siz= fSx.size();
00078 vector<double> ret(siz,1.0/fSn);
00079 for (size_t ind=0; ind<siz; ++ind) ret[ind] *= fSx[ind];
00080 return ret;
00081 }
|
|
|
Return the standard deviation of the arithmetic mean. Will use the number of samples actually collected and will return an empty vector if there are not more than 1 sample. Definition at line 93 of file UtilRunningAverageVector.cxx. References fSn, fSx, and fSxx. Referenced by SampleDeviation(). 00094 {
00095 if (fSn<=1) return vector<double>();
00096 size_t siz = fSx.size();
00097 vector<double> ret(siz,0);
00098 for (size_t ind=0; ind<siz; ++ind) {
00099 double dif = fSxx[ind] - fSx[ind]*fSx[ind]/fSn;
00100 if (dif < 0) dif = 0;
00101 double var = (dif)/(fSn-1);
00102 ret[ind] = sqrt(var);
00103 }
00104 return ret;
00105 }
|
|
|
Set the number of samples to retain.
Reimplemented in UtilBlockedRunningAverageVector. Definition at line 19 of file UtilRunningAverageVector.cxx. References fSamples, fSampleTargetSize, fSn, fSx, and fSxx. Referenced by UtilRunningAverageVector(). 00020 {
00021 fSampleTargetSize = size;
00022 while (fSn > fSampleTargetSize) {
00023 vector<double>& old = fSamples.back();
00024 for (size_t ind=0; ind<old.size(); ++ind) {
00025 fSx[ind] -= old[ind];
00026 fSxx[ind] -= old[ind]*old[ind];
00027 --fSn;
00028 }
00029 fSamples.pop_back();
00030 }
00031 }
|
|
|
Definition at line 89 of file UtilRunningAverageVector.h. Referenced by Clear(), PopulationMean(), and PopulationSigma(). |
|
|
Definition at line 86 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), PopulationMean(), and PopulationSigma(). |
|
|
Definition at line 86 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), and PopulationSigma(). |
|
|
Definition at line 85 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), LastSample(), and SetSampleSize(). |
|
|
Definition at line 89 of file UtilRunningAverageVector.h. Referenced by SetSampleSize(). |
|
|
Definition at line 89 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), IsSampleFull(), SampleMean(), SampleSigma(), and SetSampleSize(). |
|
|
Definition at line 86 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), SampleMean(), SampleSigma(), and SetSampleSize(). |
|
|
Definition at line 86 of file UtilRunningAverageVector.h. Referenced by Add(), Clear(), SampleSigma(), and SetSampleSize(). |
1.3.9.1