class Statistical::Distribution::Exponential
Abstraction of common statistical properties of the exponential
distribution
@author Vaibhav Yenamandra @attr_reader [Numeric] rate Rate parameter controlling the
exponential distribution. Same as `λ` in the canonical version
Attributes
Public Class Methods
Returns a new `Statistical::Distribution::Uniform` instance
@param [Numeric] rate Rate parameter of the exponential distribution.
Same as `λ` in the canonical version
@return `Statistical::Distribution::Exponential` instance
# File lib/statistical/distribution/exponential.rb, line 19 def initialize(rate = 1) @rate = rate @support = Domain[0.0, Float::INFINITY, :right_open] end
Public Instance Methods
Returns value of cumulative density function at a point.
@param [Numeric] x A real valued point @return [Float] Probability mass function evaluated at x
# File lib/statistical/distribution/exponential.rb, line 36 def cdf(x) return [1 - Math.exp(-@rate * x), 1.0, 0.0][@support <=> x] end
Returns the mean value for the calling instance. Calculated mean, and
not inferred from simulations
@return Mean of the distribution
# File lib/statistical/distribution/exponential.rb, line 56 def mean return 1.0 / @rate end
Returns value of probability density function at a point.
@param [Numeric] x A real valued point @return [Float] Probility density function evaluated at x
# File lib/statistical/distribution/exponential.rb, line 28 def pdf(x) return [@rate * Math.exp(-@rate * x), 0.0, 0.0][@support <=> x] end
Returns value of inverse CDF for a given probability
@see p_value
@param [Float] p a value within [0, 1] @return Inverse CDF for valid p @raise [RangeError] if p > 1 or p < 0
# 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
Returns the expected value of variance for the calling instance.
@return Variance of the distribution
# File lib/statistical/distribution/exponential.rb, line 63 def variance return (1.0 / @rate)**2 end
Private Instance Methods
Compares two distribution instances and returns a boolean outcome
Available publicly as #==
@private
@param other A distribution object (preferred) @return [Boolean] true if-and-only-if two instances are of the same
class and have the same parameters.
# File lib/statistical/distribution/exponential.rb, line 75 def eql?(other) return other.is_a?(self.class) && @rate == other.rate end