8#include "AverageStage.h"
9#include <util/format/Int.h>
10#include <util/format/Dbl.h>
31 blockFactor_(blockFactor)
45 stageInterval_(stageInterval),
49 blockFactor_(blockFactor)
68 UTIL_THROW(
"Attempt to reset block factor when nSample > 0");
70 if (blockFactor < 2) {
73 blockFactor_ = blockFactor;
76 void AverageStage::registerDescendant(
AverageStage* descendantPtr)
111 const double d = value - shift_;
120 if (nBlockSample_ == blockFactor_) {
123 long nextStageInterval = stageInterval_*blockFactor_;
124 int nextStageId = stageId_ + 1;
125 childPtr_ =
new AverageStage(nextStageInterval, nextStageId,
126 rootPtr_, blockFactor_);
127 rootPtr_->registerDescendant(childPtr_);
131 childPtr_->sample(blockSum_ /
double(blockFactor_));
145 {
return shift_ + sum_/double(nSample_); }
152 double rSample_ = double(nSample_);
153 double ave = sum_/rSample_;
154 double aveSq = sumSq_/rSample_;
155 double var = aveSq - ave*ave;
157 return (var < 0.0) ? 0.0 : var;
176 {
return stageInterval_; }
182 {
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.