Class: Weibull

Inherits:
Object
  • Object
show all
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

Erlang

Instance Attribute Summary collapse

Attributes included from RV_Generator

#generator

Instance Method Summary collapse

Methods included from RV_Generator

#each, #next

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

#kObject (readonly)

Returns the value of attribute k.



293
294
295
# File 'lib/random_variates.rb', line 293

def k
  @k
end

#rateObject (readonly)

Returns the value of attribute rate.



293
294
295
# File 'lib/random_variates.rb', line 293

def rate
  @rate
end