Class: Statistical::Rng::Weibull

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical/rng/weibull.rb

Overview

Companion RNG class for the continuous uniform distribution. Requires a

distrbution object of the corresponding distribution

Author:

  • Vaibhav Yenamandra

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dobj = nil, seed = Random.new_seed) ⇒ Weibull

Returns a new instance of Weibull.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/statistical/rng/weibull.rb', line 17

def initialize(dobj = nil, seed = Random.new_seed)
  unless dobj.nil? || dobj.is_a?(Statistical::Distribution::Weibull)
    raise TypeError,
          "Expected Distribution object or nil, found #{dobj.class}"
  end
  dobj = Statistical::Distribution::Weibull.new if dobj.nil?
  @generator = Rng::Uniform.new(Distribution::Uniform.new, seed)
  @scale = dobj.scale
  @shape = dobj.shape
  @sdist = dobj
end

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



15
16
17
# File 'lib/statistical/rng/weibull.rb', line 15

def generator
  @generator
end

#scaleNumeric (readonly)

The scale parameter of the Weibull distribution

Returns:

  • (Numeric)

    the current value of scale



14
15
16
# File 'lib/statistical/rng/weibull.rb', line 14

def scale
  @scale
end

#shapeNumeric (readonly)

The shape parameter of the Weibull distribution

Returns:

  • (Numeric)

    the current value of shape



14
15
16
# File 'lib/statistical/rng/weibull.rb', line 14

def shape
  @shape
end

Instance Method Details

#randObject

Return the next random number from the sequence

Returns:

  • next random number in the sequence



32
33
34
# File 'lib/statistical/rng/weibull.rb', line 32

def rand
  return @sdist.quantile(@generator.rand)
end

#typeObject

Return the type of the source distribution

Returns:

  • source distribution’s class



50
51
52
# File 'lib/statistical/rng/weibull.rb', line 50

def type
  @sdist.class
end