9#include <util/format/Dbl.h>
10#include <util/format/Int.h>
30 descendants_.push_back(
this);
54 read<int>(in,
"nSamplePerBlock", nSamplePerBlock_);
55 if (nSamplePerBlock_ < 0) {
56 UTIL_THROW(
"Invalid input: nSamplePerBlock < 0");
66 UTIL_THROW(
"Attempt to set nSamplePerBlock < 0");
79 loadParameter<int>(ar,
"nSamplePerBlock", nSamplePerBlock_);
80 if (nSamplePerBlock_ < 0) {
81 UTIL_THROW(
"Loading value nSamplePerBlock < 0");
99 if (nSamplePerBlock_) {
100 if (iBlock_ == nSamplePerBlock_) {
117 if (nSamplePerBlock_) {
118 if (iBlock_ == nSamplePerBlock_) {
124 if (iBlock_ == nSamplePerBlock_) {
125 out <<
Dbl(blockSum_/
double(iBlock_)) <<
"\n";
137 int n = descendants_.size();
140 while (nSample < 16 && i > 0) {
142 ptr = descendants_[i];
148 double weight = 1.0/(sigma*sigma);
149 double sum =
error*weight;
150 double norm = weight;
151 double aveErr =
error;
156 while (next && i > 0) {
159 ptr = descendants_[i];
161 if (fabs(
error - aveErr) < 2.0*oldSig) {
164 weight = 1.0/(sigma*sigma);
183 <<
" +- " <<
Dbl(aveErr, 9, 2) <<
"\n";
188 out <<
"Hierarchichal Error Analysis:" <<
"\n";
193 int n = descendants_.size();
194 for (
int i = 0; i < n; ++i) {
195 ptr = descendants_[i];
213 void Average::registerDescendant(
AverageStage* descendantPtr)
214 { descendants_.push_back(descendantPtr); }
Evaluate average with hierarchical blocking error analysis.
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.
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.
long nSample() const
Return the number of sampled values in this sequence.
double stdDeviation() const
Return the standard deviation of all sampled values.
void clear()
Clear all accumulators, set to empty initial state.
virtual ~Average()
Destructor.
int nSamplePerBlock() const
Get number of samples per block average.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Average(int blockFactor=2)
Constructor.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void output(std::ostream &out) const
Output final statistical properties to file.
void readParameters(std::istream &in)
Read parameter nSamplePerBlock from file and initialize.
double blockingError() const
Return estimated error on average from blocking analysis.
void sample(double value)
Add a sampled value to the ensemble.
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
Saving archive for binary istream.
Saving / output archive for binary ostream.
Wrapper for a double precision number, for formatted ostream output.
Wrapper for an int, for formatted ostream output.
An object that can read multiple parameters from file.
void setClassName(const char *className)
Set class name string.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.