UtilRunningAverageVector Class Reference
[Util]

A vector version of UtilRunningAverage. More...

#include <UtilRunningAverageVector.h>

Inheritance diagram for UtilRunningAverageVector:
UtilBlockedRunningAverageVector

List of all members.

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

Detailed Description

A vector version of UtilRunningAverage.

Author:
(last to touch it)
Author
rhatcher
Version:
Revision
1.3
Date:
Date
2011/10/27 18:28:26

Contact: bv@bnl.gov

Created on: Fri Apr 15 10:16:28 2005

Id
UtilRunningAverageVector.h,v 1.3 2011/10/27 18:28:26 rhatcher Exp

Definition at line 30 of file UtilRunningAverageVector.h.


Constructor & Destructor Documentation

UtilRunningAverageVector::UtilRunningAverageVector ( int  vector_size,
int  target_sample_size = 10 
)

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 }

UtilRunningAverageVector::~UtilRunningAverageVector (  )  [virtual]

Definition at line 16 of file UtilRunningAverageVector.cxx.

00017 {
00018 }


Member Function Documentation

virtual int UtilRunningAverageVector::Add ( const std::vector< double > &  val  )  [virtual]

Add a new value to the sample and population. Returns the size of the sample set after this addition.

Reimplemented in UtilBlockedRunningAverageVector.

void UtilRunningAverageVector::Clear ( bool  clear_population = true  )  [virtual]

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.

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 }

int UtilRunningAverageVector::GetPopulationSize (  )  const

Get the current population size.

Definition at line 36 of file UtilRunningAverageVector.cxx.

References fPn.

Referenced by BeamMonSwicPedsDbuModule::Dump().

00037 {
00038     return fPn;
00039 }

int UtilRunningAverageVector::GetSampleSize (  )  const [virtual]

Get the current sample size.

Definition at line 32 of file UtilRunningAverageVector.cxx.

References fSn.

00033 {
00034     return fSn;
00035 }

bool UtilRunningAverageVector::IsSampleFull (  )  const

Return true if the sample set is up to the configured size.

Definition at line 41 of file UtilRunningAverageVector.cxx.

References fSampleTargetSize, and fSn.

Referenced by BDSwicPedAccessor::SetSpillTime().

00042 {
00043     return fSn >= fSampleTargetSize;
00044 }

vector< double > UtilRunningAverageVector::LastSample (  )  const [virtual]

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, and fSn.

00121 {
00122     if (!fSn) return vector<double>();
00123     return fSamples.front();
00124 }

std::vector<double> UtilRunningAverageVector::PopulationDeviation ( const std::vector< double > &  value  )  const

Same as above but for the population.

vector< double > UtilRunningAverageVector::PopulationMean (  )  const

As above but for the population.

Definition at line 82 of file UtilRunningAverageVector.cxx.

References fPn, and fPx.

Referenced by BeamMonSwicPedsDbuModule::Dump().

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 }

vector< double > UtilRunningAverageVector::PopulationSigma (  )  const

As above but for the population.

Definition at line 106 of file UtilRunningAverageVector.cxx.

References fPn, fPx, and fPxx.

Referenced by BeamMonSwicPedsDbuModule::Dump().

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 }

std::vector<double> UtilRunningAverageVector::SampleDeviation ( const std::vector< double > &  value  )  const

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).

vector< double > UtilRunningAverageVector::SampleMean (  )  const

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.

References fSn, and fSx.

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 }

vector< double > UtilRunningAverageVector::SampleSigma (  )  const

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.

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 }

void UtilRunningAverageVector::SetSampleSize ( int  size  )  [virtual]

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 }


Member Data Documentation

size_t UtilRunningAverageVector::fPn [protected]
std::vector<double> UtilRunningAverageVector::fPx [protected]

Definition at line 87 of file UtilRunningAverageVector.h.

Referenced by Clear(), PopulationMean(), and PopulationSigma().

std::vector<double> UtilRunningAverageVector::fPxx [protected]

Definition at line 87 of file UtilRunningAverageVector.h.

Referenced by Clear(), and PopulationSigma().

std::deque<std::vector<double> > UtilRunningAverageVector::fSamples [protected]

Definition at line 86 of file UtilRunningAverageVector.h.

Referenced by Clear(), LastSample(), and SetSampleSize().

size_t UtilRunningAverageVector::fSn [protected]
std::vector<double> UtilRunningAverageVector::fSx [protected]
std::vector<double> UtilRunningAverageVector::fSxx [protected]

The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1