Class: Croupier::Distributions::Poisson

Inherits:
Croupier::Distribution show all
Defined in:
lib/croupier/distributions/poisson.rb

Overview

Poisson Distribution Discrete probability distribution that expresses the probability of a given number of event occurrin in a fixed interval of time and/or space if these events occur with a known average rate and independently of the time since the las event.

Wikipedia en.wikipedia.org/wiki/Poisson_distribution

Instance Attribute Summary

Attributes inherited from Croupier::Distribution

#description, #name, #parameters

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Croupier::Distribution

#configure, #generate_sample, #params

Constructor Details

#initialize(options = {}) ⇒ Poisson

Returns a new instance of Poisson.



14
15
16
17
18
# File 'lib/croupier/distributions/poisson.rb', line 14

def initialize(options={})
  @name = "Poisson distribution"
  @description = "Discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time."
  configure(options)
end

Class Method Details

.cli_nameObject



34
35
36
# File 'lib/croupier/distributions/poisson.rb', line 34

def self.cli_name
  "poisson"
end

.cli_optionsObject



38
39
40
41
42
43
44
# File 'lib/croupier/distributions/poisson.rb', line 38

def self.cli_options
  {:options => [
     [:lambda, 'rate parameter (equal to the mean of the distribution)', {:type=>:integer, :default => 50}]
   ],
   :banner => "Poisson distribution. Discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time."
  }
end

Instance Method Details

#default_parametersObject



30
31
32
# File 'lib/croupier/distributions/poisson.rb', line 30

def default_parameters
  {:lambda => 50}
end

#generate_numberObject



20
21
22
23
24
25
26
27
28
# File 'lib/croupier/distributions/poisson.rb', line 20

def generate_number
  l = Math.exp(-params[:lambda])
  k = 0; p = 1;
  while p > l
    p *= rand
    k += 1;
  end
  k-1
end