Class: Statistical::Rng::Exponential
- Inherits:
-
Object
- Object
- Statistical::Rng::Exponential
- Defined in:
- lib/statistical/rng/exponential.rb
Overview
Companion RNG class for the exponential distribution. Requires a
distrbution object of the corresponding distribution
Instance Attribute Summary collapse
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#rate ⇒ Numeric
readonly
Rate parameter of the exponential distribution.
-
#upper ⇒ Numeric
readonly
The upper bound of the uniform distribution.
Instance Method Summary collapse
-
#initialize(dobj = nil, seed = Random.new_seed) ⇒ Exponential
constructor
A new instance of Exponential.
-
#rand ⇒ Numeric
Return the next random number from the sequence.
-
#type ⇒ Object
Return the type of the source distribution.
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
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
15 16 17 |
# File 'lib/statistical/rng/exponential.rb', line 15 def generator @generator end |
#rate ⇒ Numeric (readonly)
Rate parameter of the exponential distribution
14 15 16 |
# File 'lib/statistical/rng/exponential.rb', line 14 def rate @rate end |
#upper ⇒ Numeric (readonly)
The upper bound of the uniform distribution
14 15 16 |
# File 'lib/statistical/rng/exponential.rb', line 14 def upper @upper end |
Instance Method Details
#rand ⇒ Numeric
Return the next random number from the sequence
31 32 33 |
# File 'lib/statistical/rng/exponential.rb', line 31 def rand return @sdist.quantile(@generator.rand) end |
#type ⇒ Object
Return the type of the source distribution
48 49 50 |
# File 'lib/statistical/rng/exponential.rb', line 48 def type @sdist.class end |