1#ifndef UTIL_AVERAGE_STAGE_H
2#define UTIL_AVERAGE_STAGE_H
106 virtual void sample(
double value);
114 template <
class Archive>
115 void serialize(Archive& ar,
const unsigned int version);
142 double error()
const;
236 virtual void registerDescendant(
AverageStage* descendantPtr);
246 {
return bool(childPtr_); }
252 {
return *childPtr_; }
259 template <
class Archive>
264 double sum = sum_ + double(nSample_)*shift_;
265 double sumSq = sumSq_ + shift_*(2.0*sum_ + double(nSample_)*shift_);
273 if (Archive::is_loading()) {
276 shift_ = (nSample_ > 0) ? sum/
double(nSample_) : 0.0;
277 sum_ = sum - double(nSample_)*shift_;
278 sumSq_ = sumSq - double(nSample_)*shift_*shift_;
283 if (Archive::is_saving()) {
284 hasChild = (childPtr_ == 0) ? 0 : 1;
290 if (Archive::is_loading()) {
291 long nextStageInterval = stageInterval_*blockFactor_;
292 int nextStageId = stageId_ + 1;
293 childPtr_ =
new AverageStage(nextStageInterval, nextStageId,
294 rootPtr_, blockFactor_);
295 rootPtr_->registerDescendant(childPtr_);
299 if (Archive::is_loading()) {
bool hasChild() const
Does this object have a child AverageStage for block averages?
void setBlockFactor(int blockFactor)
Reset the value of blockFactor.
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.
void serialize(Archive &ar, const unsigned int version)
Add a sampled value to the ensemble.
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.
AverageStage & child()
Return the child AverageStage by reference.
long nSample() const
Return the number of sampled values in this sequence.
double stdDeviation() const
Return the standard deviation of all sampled values.
File containing preprocessor macros for error handling.
Utility classes for scientific computation.