Class: RV::Weibull
- Inherits:
-
Object
- Object
- RV::Weibull
- Includes:
- RV_Generator
- Defined in:
- lib/random_variates.rb
Overview
Weibull generator based on Devroye
- Arguments
-
rate
-> the scale parameter (rate
> 0; default: 1). -
k
-> the shape parameter (k
> 0; default: 1). -
rng
-> the (Enumerable
) source of U(0, 1)‘s (default: U_GENERATOR)
-
Direct Known Subclasses
Instance Attribute Summary collapse
-
#k ⇒ Object
readonly
Returns the value of attribute k.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
Instance Method Summary collapse
-
#initialize(rate: 1.0, k: 1.0, rng: U_GENERATOR) ⇒ Weibull
constructor
A new instance of Weibull.
- #next ⇒ Object
Methods included from RV_Generator
Constructor Details
#initialize(rate: 1.0, k: 1.0, rng: U_GENERATOR) ⇒ Weibull
Returns a new instance of Weibull.
335 336 337 338 339 340 341 342 |
# File 'lib/random_variates.rb', line 335 def initialize(rate: 1.0, k: 1.0, rng: U_GENERATOR) raise 'Rate and k must be positive.' if rate <= 0 || k <= 0 @rate = rate @k = k @rng = rng @power = 1.0 / k end |
Instance Attribute Details
#k ⇒ Object (readonly)
Returns the value of attribute k.
333 334 335 |
# File 'lib/random_variates.rb', line 333 def k @k end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
333 334 335 |
# File 'lib/random_variates.rb', line 333 def rate @rate end |
Instance Method Details
#next ⇒ Object
344 345 346 |
# File 'lib/random_variates.rb', line 344 def next (-Math.log(@rng.rand))**@power / @rate end |