UtilBlockedRunningAverageVector Class Reference
[Util]

Maintain a blocked running average of a vector value. More...

#include <UtilBlockedRunningAverageVector.h>

Inheritance diagram for UtilBlockedRunningAverageVector:
UtilRunningAverageVector

List of all members.

Public Member Functions

 UtilBlockedRunningAverageVector (int vector_size, int target_sample_size=10)
virtual ~UtilBlockedRunningAverageVector ()
void SetSampleSize (int size)
int Add (const std::vector< double > &val)
int Add (const std::vector< double > &mean, const std::vector< double > &sigma, int nsamples)
std::vector< double > LastSample () const
virtual void Clear (bool clear_population=true)

Private Attributes

std::deque< std::vector< double > > fMeans
std::deque< std::vector< double > > fSigmas
std::deque< size_t > fNsamples

Detailed Description

Maintain a blocked running average of a vector value.

This class is like a vectorized version of UtilRunningAverage. See that classes docs for an overview.

Author:
(last to touch it)
Author
bv
Version:
Revision
1.2
Date:
Date
2005/04/15 14:19:15

Contact: bv@bnl.gov

Created on: Fri Apr 15 10:13:39 2005

Id
UtilBlockedRunningAverageVector.h,v 1.2 2005/04/15 14:19:15 bv Exp

Definition at line 33 of file UtilBlockedRunningAverageVector.h.


Constructor & Destructor Documentation

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

Definition at line 5 of file UtilBlockedRunningAverageVector.cxx.

00006     : UtilRunningAverageVector(vector_size,target_sample_size)
00007 {
00008 }

virtual UtilBlockedRunningAverageVector::~UtilBlockedRunningAverageVector (  )  [inline, virtual]

Definition at line 36 of file UtilBlockedRunningAverageVector.h.

00036 {}


Member Function Documentation

int UtilBlockedRunningAverageVector::Add ( const std::vector< double > &  mean,
const std::vector< double > &  sigma,
int  nsamples 
)

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.

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

Add a new single (not blocked!) value to the sample and population. Returns the size of the sample set after this addition.

Reimplemented from UtilRunningAverageVector.

Referenced by BDSwicPedAccessor::SetSpillTime().

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

Clear all samples. If clear_population is false, only the sample set is cleared.

Reimplemented from UtilRunningAverageVector.

Definition at line 80 of file UtilBlockedRunningAverageVector.cxx.

References fMeans, fNsamples, and fSigmas.

00081 {
00082     this->UtilRunningAverageVector::Clear(clear_population);
00083     fMeans.clear();
00084     fSigmas.clear();
00085     fNsamples.clear();
00086 }

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

Return the last sample, ie, the last mean added. Returns 0.0 if samples are empty.

Reimplemented from UtilRunningAverageVector.

Definition at line 74 of file UtilBlockedRunningAverageVector.cxx.

References fMeans.

00075 {
00076     if (!fMeans.size()) return vector<double>();
00077     return fMeans.back();
00078 }

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

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

Definition at line 9 of file UtilBlockedRunningAverageVector.cxx.

References fMeans, fNsamples, UtilRunningAverageVector::fSampleTargetSize, fSigmas, UtilRunningAverageVector::fSn, UtilRunningAverageVector::fSx, and UtilRunningAverageVector::fSxx.

00010 {
00011     fSampleTargetSize = size;                   // target size
00012 
00013     size_t vsiz = fSx.size();
00014 
00015     size_t current_size = fNsamples.size();
00016     if (!current_size) return;
00017     
00018     size_t nlost = fNsamples.back();    
00019     while (fSn - nlost >= fSampleTargetSize) {
00020 
00021         vector<double> lost_mean = fMeans.back();
00022         vector<double> lost_sigma = fSigmas.back();
00023         
00024         for (size_t ind=0; ind<vsiz; ++ind) {
00025             double x = nlost*lost_mean[ind];
00026             double xx = lost_sigma[ind]*lost_sigma[ind]*(nlost-1)
00027                 + nlost*lost_mean[ind]*lost_mean[ind];
00028         
00029             fSn -= nlost;
00030             fSx[ind] -= x;
00031             fSxx[ind] -= xx;
00032         }
00033 
00034         fNsamples.pop_back();
00035         fMeans.pop_back();
00036         fSigmas.pop_back();
00037 
00038         if (!fNsamples.size()) break;
00039         nlost = fNsamples.back();
00040     }
00041 }


Member Data Documentation

std::deque<std::vector<double> > UtilBlockedRunningAverageVector::fMeans [private]

Definition at line 66 of file UtilBlockedRunningAverageVector.h.

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

std::deque<size_t> UtilBlockedRunningAverageVector::fNsamples [private]

Definition at line 67 of file UtilBlockedRunningAverageVector.h.

Referenced by Clear(), and SetSampleSize().

std::deque<std::vector<double> > UtilBlockedRunningAverageVector::fSigmas [private]

Definition at line 66 of file UtilBlockedRunningAverageVector.h.

Referenced by Clear(), and SetSampleSize().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1