Class: RubyStatistics::Distribution::Poisson
- Inherits:
-
Object
- Object
- RubyStatistics::Distribution::Poisson
- Defined in:
- lib/ruby-statistics/distribution/poisson.rb
Instance Attribute Summary collapse
-
#expected_number_of_occurrences ⇒ Object
(also: #mean, #variance)
Returns the value of attribute expected_number_of_occurrences.
Instance Method Summary collapse
- #cumulative_function(k) ⇒ Object
-
#initialize(l) ⇒ Poisson
constructor
A new instance of Poisson.
- #probability_mass_function(k) ⇒ Object
Constructor Details
#initialize(l) ⇒ Poisson
Returns a new instance of Poisson.
9 10 11 |
# File 'lib/ruby-statistics/distribution/poisson.rb', line 9 def initialize(l) self.expected_number_of_occurrences = l end |
Instance Attribute Details
#expected_number_of_occurrences ⇒ Object Also known as: mean, variance
Returns the value of attribute expected_number_of_occurrences.
4 5 6 |
# File 'lib/ruby-statistics/distribution/poisson.rb', line 4 def expected_number_of_occurrences @expected_number_of_occurrences end |
Instance Method Details
#cumulative_function(k) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby-statistics/distribution/poisson.rb', line 24 def cumulative_function(k) return if k < 0 || expected_number_of_occurrences < 0 k = k.to_i upper = Math.lower_incomplete_gamma_function((k + 1).floor, expected_number_of_occurrences) lower = Math.factorial(k.floor) # We need the right tail, i.e.: The upper incomplete gamma function. This can be # achieved by doing a substraction between 1 and the lower incomplete gamma function. 1 - (upper/lower.to_r) end |
#probability_mass_function(k) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby-statistics/distribution/poisson.rb', line 13 def probability_mass_function(k) return if k < 0 || expected_number_of_occurrences < 0 k = k.to_i upper = (expected_number_of_occurrences ** k) * Math.exp(-expected_number_of_occurrences) lower = Math.factorial(k) upper/lower.to_r end |