Method: ERV::GammaDistribution#initialize

Defined in:
lib/erv/gamma_distribution.rb

#initialize(opts = {}) ⇒ GammaDistribution

Returns a new instance of GammaDistribution.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/erv/gamma_distribution.rb', line 16

def initialize(opts={})
  super(opts)

  raise ArgumentError unless opts[:scale] and opts[:shape]
  @scale = opts[:scale].to_f
  @shape = opts[:shape].to_f

  raise ArgumentError, "scale parameter must be greater than zero!" unless @scale > 0.0
  raise ArgumentError, "shape parameter must be greater than zero!" unless @shape > 0.0

  @mean = @shape / @scale
  @variance = @shape / (@scale ** 2)
end