Honeycomb  0.1
Component-Model Framework
HyperGeo.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 
30 template<class Real>
31 class HyperGeo_ : public RandomDist<Real>
32 {
33  typedef RandomDist<Real> Super;
34  RandomDist_imports();
35  template<class> friend class HyperGeo_;
36  typedef typename Numeral<Real>::Int Int;
38 
39 public:
40  HyperGeo_(RandomGen& gen, Int N, Int m, Int n) :
41  Super(gen), N(N), m(m), n(n) { assert(N > 0 && m >= 0 && m <= N && n > 0 && n <= N); }
42 
43  virtual Real next() const;
44  virtual Real pdf(Real x) const;
45  virtual Real cdf(Real x) const;
46  virtual Real cdfInv(Real P) const;
47  virtual Real mean() const { return n*m / Real(N); }
48  virtual Real variance() const { Real Nf = N; return n * (m/Nf) * (1 - m/Nf) * (Nf-n) / (Nf-1); }
49 
50  Int N;
51  Int m;
52  Int n;
53 };
54 
58 
59 extern template class HyperGeo_<Float>;
60 extern template class HyperGeo_<Double>;
61 
62 }
HyperGeo_(RandomGen &gen, Int N, Int m, Int n)
Definition: HyperGeo.h:40
virtual Real variance() const
Calc variance.
Definition: HyperGeo.h:48
virtual Real cdfInv(Real P) const
Inverse of the CDF.
Definition: HyperGeo.cpp:101
HyperGeo_< Real > HyperGeo
Definition: HyperGeo.h:55
Random number generator interface.
Definition: Gen.h:11
virtual Real pdf(Real x) const
Probability Density Function.
Definition: HyperGeo.cpp:42
Int n
Definition: HyperGeo.h:52
Int N
Definition: HyperGeo.h:50
Class to evaluate Gamma and related functions.
Definition: Gamma.h:9
GammaFunc_< Real > GammaFunc
Definition: Gamma.h:100
HyperGeo_< Float > HyperGeo_f
Definition: HyperGeo.h:56
virtual Real cdf(Real x) const
Cumulative Distribution Function.
Definition: HyperGeo.cpp:56
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Int m
Definition: HyperGeo.h:51
HyperGeo_< Double > HyperGeo_d
Definition: HyperGeo.h:57
virtual Real next() const
Get next randomly distributed variate. Requires a random generator (see ctor or setGen()) ...
Definition: HyperGeo.cpp:11
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
Generate a random integer variate from a hypergeometric distribution.
Definition: HyperGeo.h:31
Global Honeycomb namespace.
virtual Real mean() const
Calc mean.
Definition: HyperGeo.h:47
Base class for all random distributions.
Definition: Dist.h:15