Class: Bernoulli::Distribution::Poisson
- Inherits:
-
Object
- Object
- Bernoulli::Distribution::Poisson
- Includes:
- Bernoulli::Distribution
- Defined in:
- lib/bernoulli/distribution/poisson.rb
Overview
Implements Poisson distributed random variable See en.wikipedia.org/wiki/Poisson_distribution for more information
Instance Method Summary collapse
- #excess ⇒ Object
- #expected_value ⇒ Object (also: #ev)
-
#initialize(l) ⇒ Poisson
constructor
A new instance of Poisson.
-
#probability(k) ⇒ Float
in the time period.
- #probability_range(r) ⇒ Object
- #skewness ⇒ Object
- #to_s ⇒ Object
- #variance ⇒ Object (also: #v)
Methods included from Bernoulli::Distribution
Constructor Details
#initialize(l) ⇒ Poisson
Returns a new instance of Poisson.
15 16 17 18 19 20 |
# File 'lib/bernoulli/distribution/poisson.rb', line 15 def initialize(l) if l <= 0.0 raise 'Expecting l > 0.0' end @l = l.to_f end |
Instance Method Details
#excess ⇒ Object
51 52 53 |
# File 'lib/bernoulli/distribution/poisson.rb', line 51 def excess 1 / @l end |
#expected_value ⇒ Object Also known as: ev
37 38 39 |
# File 'lib/bernoulli/distribution/poisson.rb', line 37 def expected_value @l end |
#probability(k) ⇒ Float
in the time period
29 30 31 |
# File 'lib/bernoulli/distribution/poisson.rb', line 29 def probability(k) (@l**k / Math.factorial(k)) * Math.exp(-@l) end |
#probability_range(r) ⇒ Object
33 34 35 |
# File 'lib/bernoulli/distribution/poisson.rb', line 33 def probability_range(r) Math.exp(-@l) * r.inject(0) { |s, k| s + (@l**k / Math.factorial(k)) } end |
#skewness ⇒ Object
47 48 49 |
# File 'lib/bernoulli/distribution/poisson.rb', line 47 def skewness 1 / Math.sqrt(@l) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/bernoulli/distribution/poisson.rb', line 22 def to_s "#<Distribution::Poisson @l=#@l>" end |
#variance ⇒ Object Also known as: v
42 43 44 |
# File 'lib/bernoulli/distribution/poisson.rb', line 42 def variance @l end |