Class: Statistical::Distribution::Weibull
- Inherits:
-
Object
- Object
- Statistical::Distribution::Weibull
- Defined in:
- lib/statistical/distribution/weibull.rb
Overview
Any caveats you want to talk about go here…
Say something useful about this class.
Instance Attribute Summary collapse
-
#scale ⇒ Float
readonly
The distribution’s scale parameter.
-
#shape ⇒ Float
readonly
The distribution’s shape parameter.
-
#support ⇒ Object
readonly
Returns the value of attribute support.
Instance Method Summary collapse
-
#cdf(x) ⇒ Object
Returns value of cumulative density function at a point.
-
#initialize(scale = 1, shape = 1) ⇒ Object
constructor
Returns a new ‘Statistical::Distribution::Weibull` instance.
-
#mean ⇒ Object
Returns the expected value of 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(scale = 1, shape = 1) ⇒ Object
Returns a new ‘Statistical::Distribution::Weibull` instance
20 21 22 23 24 25 |
# File 'lib/statistical/distribution/weibull.rb', line 20 def initialize(scale = 1, shape = 1) @scale = scale.to_f @shape = shape.to_f @support = Domain[0.0, Float::INFINITY, :right_open] self end |
Instance Attribute Details
#scale ⇒ Float (readonly)
The distribution’s scale parameter
12 13 14 |
# File 'lib/statistical/distribution/weibull.rb', line 12 def scale @scale end |
#shape ⇒ Float (readonly)
The distribution’s shape parameter
12 13 14 |
# File 'lib/statistical/distribution/weibull.rb', line 12 def shape @shape end |
#support ⇒ Object (readonly)
Returns the value of attribute support.
13 14 15 |
# File 'lib/statistical/distribution/weibull.rb', line 13 def support @support end |
Instance Method Details
#cdf(x) ⇒ Object
Returns value of cumulative density function at a point. Calculated
using some technique that you might want to name
45 46 47 48 49 50 |
# File 'lib/statistical/distribution/weibull.rb', line 45 def cdf(x) return [1 - Math.exp(-((x / @scale)**@shape)), 1.0, 0.0 ][@support <=> x] end |
#mean ⇒ Object
Returns the expected value of mean for the calling instance.
67 68 69 |
# File 'lib/statistical/distribution/weibull.rb', line 67 def mean return @scale * Math.gamma(1 + 1 / @shape) end |
#pdf(x) ⇒ Object
Returns value of probability density function at a point. Calculated
using some technique that you might want to name
32 33 34 35 36 37 38 |
# File 'lib/statistical/distribution/weibull.rb', line 32 def pdf(x) return [(@shape / @scale) * ((x / @scale)**(@shape - 1)) * Math.exp(-((x / @scale)**@shape)), 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/weibull.rb', line 59 def quantile(p) raise RangeError, "`p` must be in [0, 1], found: #{p}" if p < 0 || p > 1 return @scale * ((-Math.log(1 - p))**(1 / @shape)) end |
#variance ⇒ Object
Returns the expected value of variance for the calling instance.
74 75 76 77 |
# File 'lib/statistical/distribution/weibull.rb', line 74 def variance m = mean (@scale * @scale) * Math.gamma(1 + 2 / @shape) - (m * m) end |