Class: Bernoulli::Distribution::Poisson

Inherits:
Object
  • Object
show all
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

Methods included from Bernoulli::Distribution

#[], #standard_deviation

Constructor Details

#initialize(l) ⇒ Poisson

Returns a new instance of Poisson.

Parameters:

  • l (Float)

    the avarage rate of success in a time period



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

#excessObject



51
52
53
# File 'lib/bernoulli/distribution/poisson.rb', line 51

def excess
  1 / @l
end

#expected_valueObject 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

Parameters:

  • k (Integer)

    number of successes (>= 0)

Returns:

  • (Float)

    the probability of ‘k` successes



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

#skewnessObject



47
48
49
# File 'lib/bernoulli/distribution/poisson.rb', line 47

def skewness
  1 / Math.sqrt(@l)
end

#to_sObject



22
23
24
# File 'lib/bernoulli/distribution/poisson.rb', line 22

def to_s
  "#<Distribution::Poisson @l=#@l>"
end

#varianceObject Also known as: v



42
43
44
# File 'lib/bernoulli/distribution/poisson.rb', line 42

def variance
  @l
end