8#include "IntDistribution.h"
9#include <util/format/Int.h>
35 nSample_(other.nSample_),
36 nReject_(other.nReject_)
42 for (
int i=0; i <
nBin_; ++i) {
60 if (
this == &other)
return *
this;
63 if (other.
nBin_ > 0) {
67 assert(other.
nBin_ == 0);
69 assert(other.
min_ == 0);
70 assert(other.
max_ == 0);
85 for (
int i=0; i <
nBin_; ++i) {
104 read<int>(in,
"min",
min_);
105 read<int>(in,
"max",
max_);
128 loadParameter<int>(ar,
"min",
min_);
129 loadParameter<int>(ar,
"max",
max_);
140 UTIL_THROW(
"Inconsistent histogram capacity");
157 for (
int i=0; i <
nBin_; ++i) {
168 if (value >=
min_ && value <=
max_) {
182 for (
int i=0; i <
nBin_; ++i) {
int capacity() const
Return allocated size.
Saving archive for binary istream.
Saving / output archive for binary ostream.
void allocate(int capacity)
Allocate the underlying C array.
A distribution (or histogram) of values for an int variable.
IntDistribution()
Default constructor.
virtual ~IntDistribution()
Destructor.
void setParam(int min, int max)
Set parameters and initialize.
int nSample_
Number of sampled values in Histogram.
int max() const
Get maximum value in range of histogram.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
int binIndex(int value)
Return the index of the bin for a value.
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
void sample(int value)
Sample a value.
DArray< long > histogram_
Histogram array.
IntDistribution & operator=(const IntDistribution &other)
Assignment operator.
void readParameters(std::istream &in)
Read parameters from file and initialize.
int min() const
Get minimum value in range of histogram.
void output(std::ostream &out)
Output the distribution to file.
int nReject_
Number of sampled values that were out of range.
void clear()
Clear (i.e., zero) previously allocated histogram.
Wrapper for an int, for formatted ostream output.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.