Class: Statistical::Rng::Exponential

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical/rng/exponential.rb

Overview

Companion RNG class for the exponential distribution. Requires a

distrbution object of the corresponding distribution

Author:

  • Vaibhav Yenamandra

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dobj = nil, seed = Random.new_seed) ⇒ Exponential

Returns a new instance of Exponential.



17
18
19
20
21
22
23
24
25
26
# File 'lib/statistical/rng/exponential.rb', line 17

def initialize(dobj = nil, seed = Random.new_seed)
  unless dobj.nil? || dobj.is_a?(Statistical::Distribution::Exponential)
    raise TypeError,
          "Expected Distribution object or nil, found #{dobj.class}"
  end
  dobj = Statistical::Distribution::Exponential.new if dobj.nil?
  @generator = Random.new(seed)
  @rate = dobj.rate
  @sdist = dobj
end

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



15
16
17
# File 'lib/statistical/rng/exponential.rb', line 15

def generator
  @generator
end

#rateNumeric (readonly)

Rate parameter of the exponential distribution

Returns:

  • (Numeric)

    the current value of rate



14
15
16
# File 'lib/statistical/rng/exponential.rb', line 14

def rate
  @rate
end

#upperNumeric (readonly)

The upper bound of the uniform distribution

Returns:

  • (Numeric)

    the current value of upper



14
15
16
# File 'lib/statistical/rng/exponential.rb', line 14

def upper
  @upper
end

Instance Method Details

#randNumeric

Return the next random number from the sequence

Returns:

  • (Numeric)

    next random number in the sequence



31
32
33
# File 'lib/statistical/rng/exponential.rb', line 31

def rand
  return @sdist.quantile(@generator.rand)
end

#typeObject

Return the type of the source distribution

Returns:

  • source distribution’s type



48
49
50
# File 'lib/statistical/rng/exponential.rb', line 48

def type
  @sdist.class
end