Class: Statistical::Distribution::Gumbel
- Inherits:
-
Object
- Object
- Statistical::Distribution::Gumbel
- Defined in:
- lib/statistical/distribution/gumbel.rb
Overview
Distribution class for Extreme value type-3 or Gumbel distribution
Instance Attribute Summary collapse
-
#location ⇒ Float
readonly
The distributions location parameter.
-
#scale ⇒ Float
readonly
The dstribution’s scale parameter.
-
#support ⇒ Float
readonly
The region of the real line where this distribution is defined to exist.
Instance Method Summary collapse
-
#cdf(x) ⇒ Object
Returns value of cumulative density function upto a point.
-
#initialize(location = 0, scale = 1) ⇒ Object
constructor
Returns a new
Statistical::Distribution::Gumbelinstance. -
#mean ⇒ Object
Returns the expected value of the mean for the calling instance.
-
#pdf(x) ⇒ Object
Returns value of probability density function at a point.
-
#quantile(p) ⇒ Object
(also: #p_value)
Returns value of inverse CDF for a given probability.
-
#variance ⇒ Object
Returns the expected value of variance for the calling instance.
Constructor Details
#initialize(location = 0, scale = 1) ⇒ Object
Returns a new Statistical::Distribution::Gumbel instance
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
#location ⇒ Float (readonly)
The distributions location parameter
13 14 15 |
# File 'lib/statistical/distribution/gumbel.rb', line 13 def location @location end |
#scale ⇒ Float (readonly)
The dstribution’s scale parameter
13 14 15 |
# File 'lib/statistical/distribution/gumbel.rb', line 13 def scale @scale end |
#support ⇒ Float (readonly)
The region of the real line where this distribution is defined to exist
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.
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 |
#mean ⇒ Object
Returns the expected value of the mean for the calling instance.
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.
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
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 |
#variance ⇒ Object
Returns the expected value of variance for the calling instance.
74 75 76 |
# File 'lib/statistical/distribution/gumbel.rb', line 74 def variance return ((Math::PI * @scale)**2) / 6 end |