1 #ifndef UTIL_DISTRIBUTION_H 2 #define UTIL_DISTRIBUTION_H 11 #include <util/param/ParamComposite.h> 12 #include <util/containers/DArray.h> 13 #include <util/math/feq.h> 91 template <
class Archive>
92 void serialize(Archive& ar,
const unsigned int version);
104 virtual void clear();
111 void output(std::ostream& out);
147 void reduce(MPI::Intracomm& communicator,
int root);
197 template <
class Archive>
209 if (histogram_.capacity() !=
nBin_) {
210 UTIL_THROW(
"Inconsistent histogram capacity");
212 if (!
feq(binWidth_, (max_ - min_)/
double(nBin_))) {
double max_
maximum value.
void serialize(Archive &ar, const unsigned int version)
Serialize this Distribution to/from an archive.
int nSample_
Number of sampled values in Histogram.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
double binWidth() const
Get binWidth, the width of each bin.
int binIndex(double value) const
Return the index of the bin for a value.
double min_
minimum value.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
double binWidth_
width of bin = (max_-min_)/nBin_ .
Utility classes for scientific computation.
Distribution & operator=(const Distribution &other)
Assignment operator.
void sample(double value)
Sample a value.
double min() const
Get minimum value in range of histogram.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
void output(std::ostream &out)
Output the distribution to file.
virtual void clear()
Clear (i.e., zero) previously allocated histogram.
DArray< long > histogram_
Histogram of occurences, one element per bin.
Saving archive for binary istream.
int nReject_
Number of sampled values that were out of range.
int nBin() const
Get the number of bins.
void reduce(MPI::Intracomm &communicator, int root)
Reduce (add) distributions from multiple MPI processors.
virtual ~Distribution()
Destructor.
void setParam(double min, double max, int nBin)
Set parameters and initialize.
A distribution (or histogram) of values for a real variable.
An object that can read multiple parameters from file.
Distribution()
Default constructor.
bool feq(double x, double y, double eps=1.0E-10)
Are two floating point numbers equal to within round-off error?
double max() const
Get maximum value in range of histogram.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.