Class: ERV::GammaDistribution

Inherits:
Distribution show all
Defined in:
lib/erv/gamma_distribution.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ GammaDistribution

Returns a new instance of GammaDistribution.

Raises:

  • (ArgumentError)


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

def initialize(opts)
  super(opts)

  raise ArgumentError unless opts[:rate] and opts[:shape]
  scale = 1 / opts[:rate].to_f
  shape = opts[:shape].to_f

  if RUBY_PLATFORM == 'java'
    # create distribution
    d = JGammaDistribution.new(@rng, shape, scale,
            JGammaDistribution::DEFAULT_INVERSE_ABSOLUTE_ACCURACY)
    # setup sampling function
    @func = Proc.new { d.sample }
  else
    # setup sampling function
    @func = Proc.new { @rng.gamma(shape, scale) }
  end
end