Simpatico  v1.10
IntDistribution.h
1 #ifndef UTIL_INT_DISTRIBUTION_H
2 #define UTIL_INT_DISTRIBUTION_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/param/ParamComposite.h>
12 #include <util/containers/DArray.h>
13 
14 namespace Util
15 {
16 
23  {
24 
25  public:
26 
31 
37  IntDistribution(const IntDistribution& other);
38 
45 
49  virtual ~IntDistribution();
50 
59  void readParameters(std::istream& in);
60 
67  void setParam(int min, int max);
68 
74  virtual void loadParameters(Serializable::IArchive& ar);
75 
81  virtual void save(Serializable::OArchive& ar);
82 
89  template <class Archive>
90  void serialize(Archive& ar, const unsigned int version);
91 
95  void clear();
96 
102  void sample(int value);
103 
109  void output(std::ostream& out);
110 
116  int binIndex(int value);
117 
121  int min() const;
122 
126  int max() const;
127 
131  int nBin() const;
132 
140  const DArray<long>& data() const
141  { return histogram_; }
142 
143  protected:
144 
146  int min_;
147  int max_;
148  int nBin_;
149  int nSample_;
150  int nReject_;
151 
152  };
153 
154  // inline method definitions
155 
156  /*
157  * Return the index of the bin for a value.
158  */
159  inline int IntDistribution::binIndex(int value)
160  { return (value - min_); }
161 
162  /*
163  * Get minimum value in range of histogram.
164  */
165  inline int IntDistribution::min() const
166  { return min_; }
167 
168  /*
169  * Get maximum value in range of histogram.
170  */
171  inline int IntDistribution::max() const
172  { return max_; }
173 
174  /*
175  * Get the number of bins
176  */
177  inline int IntDistribution::nBin() const
178  { return nBin_; }
179 
180  /*
181  * Serialize this Distribution.
182  */
183  template <class Archive>
184  void IntDistribution::serialize(Archive& ar, const unsigned int version)
185  {
186  ar & min_;
187  ar & max_;
188  ar & nBin_;
189  ar & nSample_;
190  ar & nReject_;
191  ar & histogram_;
192  }
193 
194 }
195 #endif
DArray< long > histogram_
Histogram array.
IntDistribution()
Default constructor.
IntDistribution & operator=(const IntDistribution &other)
Assignment operator.
int binIndex(int value)
Return the index of the bin for a value.
virtual ~IntDistribution()
Destructor.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
A distribution (or histogram) of values for an int variable.
Saving / output archive for binary ostream.
void output(std::ostream &out)
Output the distribution to file.
void clear()
Clear (i.e., zero) previously allocated histogram.
void setParam(int min, int max)
Set parameters and initialize.
void sample(int value)
Sample a value.
Utility classes for scientific computation.
Definition: accumulators.mod:1
int max_
maximum value.
int min_
minimum value.
int max() const
Get maximum value in range of histogram.
int nBin_
number of bins.
const DArray< long > & data() const
Get histogram array.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
int nBin() const
Get the number of bins.
Saving archive for binary istream.
void readParameters(std::istream &in)
Read parameters from file and initialize.
int min() const
Get minimum value in range of histogram.
int nReject_
Number of sampled values that were out of range.
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
An object that can read multiple parameters from file.
int nSample_
Number of sampled values in Histogram.