Class: Statistical::Distribution::Gumbel

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical/distribution/gumbel.rb

Overview

Distribution class for Extreme value type-3 or Gumbel distribution

Author:

  • Vaibhav Yenamandra

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = 0, scale = 1) ⇒ Object

Returns a new Statistical::Distribution::Gumbel instance

Parameters:

  • location (Types) (defaults to: 0)

    Description



20
21
22
23
24
# File 'lib/statistical/distribution/gumbel.rb', line 20

def initialize(location = 0, scale = 1)
  @location = location.to_f
  @scale = scale.to_f
  @support = Domain[-Float::INFINITY, Float::INFINITY, :full_open]
end

Instance Attribute Details

#locationFloat (readonly)

The distributions location parameter

Returns:

  • (Float)

    the current value of location



13
14
15
# File 'lib/statistical/distribution/gumbel.rb', line 13

def location
  @location
end

#scaleFloat (readonly)

The dstribution’s scale parameter

Returns:

  • (Float)

    the current value of scale



13
14
15
# File 'lib/statistical/distribution/gumbel.rb', line 13

def scale
  @scale
end

#supportFloat (readonly)

The region of the real line where this distribution is defined to exist

Returns:

  • (Float)

    the current value of support



13
14
15
# File 'lib/statistical/distribution/gumbel.rb', line 13

def support
  @support
end

Instance Method Details

#cdf(x) ⇒ Object

Returns value of cumulative density function upto a point.

Parameters:

  • x (Numeric)

    A real valued point

Returns:

  • Cumulative density function evaluated for F(u <= x)



43
44
45
46
47
48
49
50
# File 'lib/statistical/distribution/gumbel.rb', line 43

def cdf(x)
  xa = (x - @location) / @scale
  return [
    Math.exp(-Math.exp(-xa)),
    1.0,
    0.0
  ][@support <=> x]
end

#meanObject

Returns the expected value of the mean for the calling instance.

Returns:

  • Mean of the distribution



67
68
69
# File 'lib/statistical/distribution/gumbel.rb', line 67

def mean
  return @location + @scale * Statistical::EULER_GAMMA
end

#pdf(x) ⇒ Object

Returns value of probability density function at a point.

Parameters:

  • x (Numeric)

    A real valued point

Returns:

  • Probability density function evaluated at x



30
31
32
33
34
35
36
37
# File 'lib/statistical/distribution/gumbel.rb', line 30

def pdf(x)
  xa = (x - @location) / @scale
  return [
    Math.exp(-xa - Math.exp(-xa)) / @scale,
    0.0,
    0.0
  ][@support <=> x]
end

#quantile(p) ⇒ Object Also known as: p_value

Returns value of inverse CDF for a given probability

Parameters:

  • p (Numeric)

    a value within [0, 1]

Returns:

  • Inverse CDF for valid p

Raises:

  • (RangeError)

    if p > 1 or p < 0

See Also:



59
60
61
62
# File 'lib/statistical/distribution/gumbel.rb', line 59

def quantile(p)
  raise RangeError, "`p` must be in [0, 1], found: #{p}" if p < 0 || p > 1
  return @location - @scale * Math.log(-Math.log(p))
end

#varianceObject

Returns the expected value of variance for the calling instance.

Returns:

  • Variance of the distribution



74
75
76
# File 'lib/statistical/distribution/gumbel.rb', line 74

def variance
  return ((Math::PI * @scale)**2) / 6
end