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");
65 if (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];
147 double sigma = error/sqrt(2.0*
double(nSample-1));
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];
160 error = ptr->
error();
161 if (fabs(error - aveErr) < 2.0*oldSig) {
163 sigma = error/sqrt(2.0*
double(nSample-1));
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];
196 error = ptr->
error();
203 <<
Dbl(error/sqrt(
double(nSample)))
204 <<
Int(nSample) <<
"\n";
213 void Average::registerDescendant(
AverageStage* descendantPtr)
214 { descendants_.push_back(descendantPtr); }
void clear()
Clear all accumulators, set to empty initial state.
double variance() const
Return the variance of all sampled values.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
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.
long stageInterval() const
Return the number of sampled values per block at this stage.
Wrapper for a double precision number, for formatted ostream output.
double blockingError() const
Return estimated error on average from blocking analysis.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Average(int blockFactor=2)
Constructor.
void readParameters(std::istream &in)
Read parameter nSamplePerBlock from file and initialize.
Utility classes for scientific computation.
Wrapper for an int, for formatted ostream output.
virtual ~Average()
Destructor.
virtual void sample(double value)
Add a sampled value to the ensemble.
void output(std::ostream &out) const
Output final statistical properties to file.
double stdDeviation() const
Return the standard deviation of all sampled values.
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
Saving archive for binary istream.
void sample(double value)
Add a sampled value to the ensemble.
long nSample() const
Return the number of sampled values in this sequence.
Evaluate average with hierarchical blocking error analysis.
int nSamplePerBlock() const
Get number of samples per block average.
void setClassName(const char *className)
Set class name string.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
An object that can read multiple parameters from file.
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.