Honeycomb  0.1
Component-Model Framework
DiscreteGen.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 
6 namespace honey
7 {
8 
10 
18 template<class Real>
19 class DiscreteGen_ : public RandomDist<Real>
20 {
21  typedef RandomDist<Real> Super;
22  RandomDist_imports();
23  template<class> friend class DiscreteGen_;
24  typedef vector<Double> Listd;
25 
26  struct Elem
27  {
28  Double bisector;
29  szt indexTwo;
30  };
31  typedef vector<Elem> Table;
32 
33 public:
34 
35  typedef vector<Real> List;
36 
37  DiscreteGen_(RandomGen& gen, List pdf);
38 
39  virtual Real next() const;
40  virtual Real pdf(Real x) const;
41  virtual Real cdf(Real x) const;
42  virtual Real cdfInv(Real P) const;
43  virtual Real mean() const { return _mean; }
44  virtual Real variance() const { return _variance; }
45 
46  szt variateMin() const { return 0; }
47  szt variateMax() const { return _pdf.size() > 0 ? _pdf.size()-1 : 0; }
48 
49 private:
50  Listd _pdf;
51  Listd _cdf;
52  Double _mean;
53  Double _variance;
54  Table _table;
55 };
56 
60 
61 extern template class DiscreteGen_<Float>;
62 extern template class DiscreteGen_<Double>;
63 
64 }
virtual Real mean() const
Calc mean.
Definition: DiscreteGen.h:43
Double_::Real Double
double type
Definition: Double.h:60
Random number generator interface.
Definition: Gen.h:11
Generate a random integer variate from a generalized discrete distribution.
Definition: DiscreteGen.h:19
friend class DiscreteGen_
Definition: DiscreteGen.h:23
szt variateMax() const
Definition: DiscreteGen.h:47
DiscreteGen_< Float > DiscreteGen_f
Definition: DiscreteGen.h:58
Double_::Real Double
Definition: Dist.h:20
virtual Real next() const
Get next randomly distributed variate. Requires a random generator (see ctor or setGen()) ...
Definition: DiscreteGen.cpp:128
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
virtual Real cdfInv(Real P) const
Inverse of the CDF.
Definition: DiscreteGen.cpp:156
DiscreteGen_< Real > DiscreteGen
Definition: DiscreteGen.h:57
virtual Real pdf(Real x) const
Probability Density Function.
Definition: DiscreteGen.cpp:136
vector< Real > List
Definition: DiscreteGen.h:35
szt variateMin() const
Definition: DiscreteGen.h:46
virtual Real cdf(Real x) const
Cumulative Distribution Function.
Definition: DiscreteGen.cpp:145
DiscreteGen_< Double > DiscreteGen_d
Definition: DiscreteGen.h:59
Global Honeycomb namespace.
virtual Real variance() const
Calc variance.
Definition: DiscreteGen.h:44
Base class for all random distributions.
Definition: Dist.h:15