8#include "AverageStage.h" 
    9#include <util/format/Int.h> 
   10#include <util/format/Dbl.h> 
   30      blockFactor_(blockFactor)
 
 
   43      stageInterval_(stageInterval),
 
   47      blockFactor_(blockFactor)
 
   66         UTIL_THROW(
"Attempt to reset block factor when nSample > 0");
 
   68      if (blockFactor < 2) {
 
   71      blockFactor_ = blockFactor;
 
 
   74   void AverageStage::registerDescendant(
AverageStage* descendantPtr)
 
  100      sumSq_ += (value*value);
 
  107      if (nBlockSample_ == blockFactor_) {
 
  110            long nextStageInterval = stageInterval_*blockFactor_;
 
  111            int  nextStageId       = stageId_ + 1;
 
  112            childPtr_ = 
new AverageStage(nextStageInterval, nextStageId, 
 
  113                                         rootPtr_, blockFactor_);
 
  114            rootPtr_->registerDescendant(childPtr_);
 
  118         childPtr_->sample(blockSum_ / 
double(blockFactor_));
 
 
  132   {  
return sum_/double(nSample_); }
 
 
  139      double rSample_ = double(nSample_);
 
  140      double ave   = sum_/rSample_;
 
  141      double aveSq = sumSq_/rSample_;
 
  142      return aveSq - ave*ave;
 
 
  161   {  
return stageInterval_; }
 
 
  167   {  
return sqrt(
variance()/
double(nSample_-1)); }
 
 
Evaluate average with hierarchical blocking error analysis.
 
void setBlockFactor(int blockFactor)
Reset the value of blockFactor.
 
virtual ~AverageStage()
Destructor.
 
long stageInterval() const
Return the number of sampled values per block at this stage.
 
virtual void sample(double value)
Add a sampled value to the ensemble.
 
virtual void clear()
Initialize all accumulators and recursively destroy all children.
 
AverageStage(int blockFactor=2)
Constructor.
 
double average() const
Return the average of all sampled values.
 
double variance() const
Return the variance of all sampled values.
 
double error() const
Return a naive estimate for the std deviation of the average.
 
long nSample() const
Return the number of sampled values in this sequence.
 
double stdDeviation() const
Return the standard deviation of all sampled values.
 
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
 
Utility classes for scientific computation.