Class: Croupier::Distributions::Poisson
- Inherits:
-
Croupier::Distribution
- Object
- Croupier::Distribution
- Croupier::Distributions::Poisson
- 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.
Instance Attribute Summary
Attributes inherited from Croupier::Distribution
#description, #name, #parameters
Class Method Summary collapse
Instance Method Summary collapse
- #default_parameters ⇒ Object
- #generate_number ⇒ Object
-
#initialize(options = {}) ⇒ Poisson
constructor
A new instance of Poisson.
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(={}) @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() end |
Class Method Details
.cli_name ⇒ Object
34 35 36 |
# File 'lib/croupier/distributions/poisson.rb', line 34 def self.cli_name "poisson" end |
.cli_options ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/croupier/distributions/poisson.rb', line 38 def self. {: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_parameters ⇒ Object
30 31 32 |
# File 'lib/croupier/distributions/poisson.rb', line 30 def default_parameters {:lambda => 50} end |
#generate_number ⇒ Object
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 |