Class: RV::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

Instance Method Summary collapse

Methods included from RV_Generator

#each

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

#kObject (readonly)

Returns the value of attribute k.



333
334
335
# File 'lib/random_variates.rb', line 333

def k
  @k
end

#rateObject (readonly)

Returns the value of attribute rate.



333
334
335
# File 'lib/random_variates.rb', line 333

def rate
  @rate
end

Instance Method Details

#nextObject



344
345
346
# File 'lib/random_variates.rb', line 344

def next
  (-Math.log(@rng.rand))**@power / @rate
end