Class: ERV::ExponentialDistribution

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

Instance Method Summary collapse

Methods inherited from Distribution

#sample

Constructor Details

#initialize(opts) ⇒ ExponentialDistribution

Returns a new instance of ExponentialDistribution.

Raises:

  • (ArgumentError)


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

def initialize(opts)
  super(opts)

  raise ArgumentError unless opts[:mean]
  mean = opts[:mean].to_f

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