8 #include "Distribution.h" 9 #include <util/format/Dbl.h> 43 for (
int i=0; i <
nBin_; ++i) {
60 if (
this == &other)
return *
this;
63 if (other.
nBin_ > 0) {
66 assert(other.
nBin_ == 0);
83 for (
int i=0; i <
nBin_; ++i) {
102 read<double>(in,
"min",
min_);
103 read<double>(in,
"max",
max_);
104 read<int>(in,
"nBin",
nBin_);
132 loadParameter<double>(ar,
"min",
min_);
133 loadParameter<double>(ar,
"max",
max_);
134 loadParameter<int>(ar,
"nBin",
nBin_);
141 if (histogram_.capacity() !=
nBin_) {
142 UTIL_THROW(
"Inconsistent histogram capacity");
162 for (
int i=0; i <
nBin_; ++i) {
188 for (
int i=0; i <
nBin_; ++i) {
192 out <<
Dbl(x, 18, 8) <<
Dbl(rho, 18, 8) << std::endl;
203 long* totHistogram =
new long[
nBin_];
205 if (communicator.Get_rank() == root) {
206 for (
int i=0; i <
nBin_; ++i) {
210 for (
int i=0; i <
nBin_; ++i) {
214 delete [] totHistogram;
217 communicator.Reduce(&
nSample_, &totSample, 1, MPI::LONG, MPI::SUM, root);
218 if (communicator.Get_rank() == root) {
225 communicator.Reduce(&
nReject_, &totReject, 1, MPI::LONG, MPI::SUM, root);
226 if (communicator.Get_rank() == root) {
double max_
maximum value.
int nSample_
Number of sampled values in Histogram.
Data * cArray()
Return pointer to underlying C array.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
int binIndex(double value) const
Return the index of the bin for a value.
Wrapper for a double precision number, for formatted ostream output.
File containing preprocessor macros for error handling.
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.
void setClassName(const char *className)
Set class name string.
virtual ~Distribution()
Destructor.
int capacity() const
Return allocated size.
void allocate(int capacity)
Allocate the underlying C array.
void setParam(double min, double max, int nBin)
Set parameters and initialize.
A distribution (or histogram) of values for a real variable.
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.