Class: Statistical::Distribution::Exponential
- Inherits:
-
Object
- Object
- Statistical::Distribution::Exponential
- Defined in:
- lib/statistical/distribution/exponential.rb
Overview
Abstraction of common statistical properties of the exponential
distribution
Instance Attribute Summary collapse
-
#rate ⇒ Numeric
readonly
Rate parameter controlling the exponential distribution.
-
#support ⇒ Object
readonly
Returns the value of attribute support.
Instance Method Summary collapse
-
#cdf(x) ⇒ Float
Returns value of cumulative density function at a point.
-
#initialize(rate = 1) ⇒ Object
constructor
Returns a new ‘Statistical::Distribution::Uniform` instance.
-
#mean ⇒ Object
Returns the mean value for the calling instance.
-
#pdf(x) ⇒ Float
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(rate = 1) ⇒ Object
Returns a new ‘Statistical::Distribution::Uniform` instance
19 20 21 22 |
# File 'lib/statistical/distribution/exponential.rb', line 19 def initialize(rate = 1) @rate = rate @support = Domain[0.0, Float::INFINITY, :right_open] end |
Instance Attribute Details
#rate ⇒ Numeric (readonly)
Rate parameter controlling the exponential distribution. Same as ‘λ` in the canonical version
11 12 13 |
# File 'lib/statistical/distribution/exponential.rb', line 11 def rate @rate end |
#support ⇒ Object (readonly)
Returns the value of attribute support.
12 13 14 |
# File 'lib/statistical/distribution/exponential.rb', line 12 def support @support end |
Instance Method Details
#cdf(x) ⇒ Float
Returns value of cumulative density function at a point.
36 37 38 |
# File 'lib/statistical/distribution/exponential.rb', line 36 def cdf(x) return [1 - Math.exp(-@rate * x), 1.0, 0.0][@support <=> x] end |
#mean ⇒ Object
Returns the mean value for the calling instance. Calculated mean, and
not inferred from simulations
56 57 58 |
# File 'lib/statistical/distribution/exponential.rb', line 56 def mean return 1.0 / @rate end |
#pdf(x) ⇒ Float
Returns value of probability density function at a point.
28 29 30 |
# File 'lib/statistical/distribution/exponential.rb', line 28 def pdf(x) return [@rate * Math.exp(-@rate * x), 0.0, 0.0][@support <=> x] end |
#quantile(p) ⇒ Object Also known as: p_value
Returns value of inverse CDF for a given probability
47 48 49 50 |
# File 'lib/statistical/distribution/exponential.rb', line 47 def quantile(p) raise RangeError, "`p` must be in [0, 1], found: #{p}" if p < 0 || p > 1 return Math.log(1 - p) / -@rate end |
#variance ⇒ Object
Returns the expected value of variance for the calling instance.
63 64 65 |
# File 'lib/statistical/distribution/exponential.rb', line 63 def variance return (1.0 / @rate)**2 end |