Class: Croupier::Distributions::Gamma

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

Overview

Gamma Distribution Family of continuous distributions with two parameters shape (defaults to 1) and scale (defaults to 1).

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, #to_enum

Constructor Details

#initialize(options = {}) ⇒ Gamma

Returns a new instance of Gamma.



10
11
12
13
14
# File 'lib/croupier/distributions/gamma.rb', line 10

def initialize(options={})
  @name = "Gamma distribution"
  @description = "Family of continuous distributions with two parameters, shape and scale"
  configure(options)
end

Class Method Details

.cli_nameObject



24
25
26
# File 'lib/croupier/distributions/gamma.rb', line 24

def self.cli_name
  "gamma"
end

.cli_optionsObject



28
29
30
31
32
33
34
35
# File 'lib/croupier/distributions/gamma.rb', line 28

def self.cli_options
  {:options => [
     [:shape, 'shape of the distribution', {:type=>:float, :default => 1.0}],
     [:scale, 'scale of the distribution', {:type=>:float, :default => 1.0}]
   ],
   :banner => "Family of continuous distributions with two parameters, shape and scale."
  }
end

Instance Method Details

#default_parametersObject



20
21
22
# File 'lib/croupier/distributions/gamma.rb', line 20

def default_parameters
  {:shape => 1.0, :std => 1.0}
end

#generate_numberObject



16
17
18
# File 'lib/croupier/distributions/gamma.rb', line 16

def generate_number
  params[:scale] * (gen_xi - (1..params[:shape].floor).map { Math.log(1 - rand) }.inject(&:+) )
end