Honeycomb  0.1
Component-Model Framework
Binomial.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 
24 template<class Real>
25 class Binomial_ : public RandomDist<Real>
26 {
27  typedef RandomDist<Real> Super;
28  RandomDist_imports();
29  template<class> friend class Binomial_;
30  typedef typename Numeral<Real>::Int Int;
32  typedef Beta_<Double> Beta;
33 
34 public:
35  Binomial_(RandomGen& gen, Int n, Real p) : RandomDist<Real>(gen), n(n), p(p) { assert(n > 0 && p >= 0 && p <= 1); }
36 
37  virtual Real next() const;
38  virtual Real pdf(Real x) const;
39  virtual Real cdf(Real x) const;
40  virtual Real cdfInv(Real P) const;
41  virtual Real mean() const { return n*p; }
42  virtual Real variance() const { return n*p*(1-p); }
43 
45 
49  static Real trialProb(Int x, Int n, Real P);
50 
51  Int n;
53 };
54 
58 
59 extern template class Binomial_<Float>;
60 extern template class Binomial_<Double>;
61 
62 }
virtual Real variance() const
Calc variance.
Definition: Binomial.h:42
Beta_< Real > Beta
Definition: Beta.h:57
Generate a random variate from a beta distribution .
Definition: Beta.h:30
Random number generator interface.
Definition: Gen.h:11
virtual Real pdf(Real x) const
Probability Density Function.
Definition: Binomial.cpp:48
virtual Real cdfInv(Real P) const
Inverse of the CDF.
Definition: Binomial.cpp:69
Class to evaluate Gamma and related functions.
Definition: Gamma.h:9
GammaFunc_< Real > GammaFunc
Definition: Gamma.h:100
Binomial_< Real > Binomial
Definition: Binomial.h:55
Binomial_< Float > Binomial_f
Definition: Binomial.h:56
Binomial_< Double > Binomial_d
Definition: Binomial.h:57
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
virtual Real next() const
Get next randomly distributed variate. Requires a random generator (see ctor or setGen()) ...
Definition: Binomial.cpp:11
virtual Real mean() const
Calc mean.
Definition: Binomial.h:41
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
static Real trialProb(Int x, Int n, Real P)
Calculate trial probability given all other values.
Definition: Binomial.cpp:79
Binomial_(RandomGen &gen, Int n, Real p)
Definition: Binomial.h:35
Generate a random integer variate from a binomial distribution.
Definition: Binomial.h:25
Int n
Definition: Binomial.h:51
Real p
Definition: Binomial.h:52
Global Honeycomb namespace.
virtual Real cdf(Real x) const
Cumulative Distribution Function.
Definition: Binomial.cpp:58
Base class for all random distributions.
Definition: Dist.h:15