Class: Weibull
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.
Attributes included from RV_Generator
Instance Method Summary collapse
-
#initialize(rate: 1.0, k: 1.0, rng: U_GENERATOR) ⇒ Weibull
constructor
A new instance of Weibull.
Methods included from RV_Generator
Constructor Details
#initialize(rate: 1.0, k: 1.0, rng: U_GENERATOR) ⇒ Weibull
Returns a new instance of Weibull.
295 296 297 298 299 300 301 302 303 304 |
# File 'lib/random_variates.rb', line 295 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 power = 1.0 / k @generator = Enumerator.new do |yielder| loop { yielder << (-Math.log(rng.next))**power / rate } end end |
Instance Attribute Details
#k ⇒ Object (readonly)
Returns the value of attribute k.
293 294 295 |
# File 'lib/random_variates.rb', line 293 def k @k end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
293 294 295 |
# File 'lib/random_variates.rb', line 293 def rate @rate end |