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)); }
double variance() const
Return the variance of all sampled values.
double average() const
Return the average of all sampled values.
virtual ~AverageStage()
Destructor.
long stageInterval() const
Return the number of sampled values per block at this stage.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void setBlockFactor(int blockFactor)
Reset the value of blockFactor.
Utility classes for scientific computation.
virtual void sample(double value)
Add a sampled value to the ensemble.
double stdDeviation() const
Return the standard deviation of all sampled values.
long nSample() const
Return the number of sampled values in this sequence.
Evaluate average with hierarchical blocking error analysis.
AverageStage(int blockFactor=2)
Constructor.
double error() const
Return a naive estimate for the std deviation of the average.
virtual void clear()
Initialize all accumulators and recursively destroy all children.