Portability | portable |
---|---|
Stability | experimental |
Maintainer | bos@serpentine.com |
Types classes for probability distrubutions
- class Distribution d where
- cumulative :: d -> Double -> Double
- complCumulative :: d -> Double -> Double
- class Distribution d => DiscreteDistr d where
- probability :: d -> Int -> Double
- class Distribution d => ContDistr d where
- class Distribution d => MaybeMean d where
- class MaybeMean d => Mean d where
- class MaybeMean d => MaybeVariance d where
- maybeVariance :: d -> Maybe Double
- maybeStdDev :: d -> Maybe Double
- class (Mean d, MaybeVariance d) => Variance d where
- findRoot :: ContDistr d => d -> Double -> Double -> Double -> Double -> Double
- sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> Double
Type classes
class Distribution d whereSource
Type class common to all distributions. Only c.d.f. could be defined for both discrete and continous distributions.
cumulative :: d -> Double -> DoubleSource
Cumulative distribution function. The probability that a random variable X is less or equal than x, i.e. P(X≤x).
complCumulative :: d -> Double -> DoubleSource
One's complement of cumulative distibution:
complCumulative d x = 1 - cumulative d x
It's useful when one is interested in P(X≥x) and expression on the right side begin to lose precision. This function have default implementation but implementors are encouraged to provide more precise implementation
class Distribution d => DiscreteDistr d whereSource
Discrete probability distribution.
probability :: d -> Int -> DoubleSource
Probability of n-th outcome.
class Distribution d => ContDistr d whereSource
Continuous probability distributuion
density :: d -> Double -> DoubleSource
Probability density function. Probability that random variable X lies in the infinitesimal interval [x,x+δx) equal to density(x)⋅δx
quantile :: d -> Double -> DoubleSource
Inverse of the cumulative distribution function. The value
x for which P(X≤x) = p. If probability is outside
of [0,1] range function should call error
Distribution statistics
class Distribution d => MaybeMean d whereSource
Type class for distributions with mean. maybeMean
should return
Nothing
if it's undefined for current value of data
class MaybeMean d => Mean d whereSource
Type class for distributions with mean. If distribution have finite mean for all valid values of parameters it should be instance of this type class.
class MaybeMean d => MaybeVariance d whereSource
Type class for distributions with variance. If variance is
undefined for some parameter values both maybeVariance
and
maybeStdDev
should return Nothing.
Minimal complete definition is maybeVariance
or maybeStdDev
maybeVariance :: d -> Maybe DoubleSource
maybeStdDev :: d -> Maybe DoubleSource
class (Mean d, MaybeVariance d) => Variance d whereSource
Type class for distributions with variance. If distibution have finite variance for all valid parameter values it should be instance of this type class.
Helper functions
:: ContDistr d | |
=> d | Distribution |
-> Double | Probability p |
-> Double | Initial guess |
-> Double | Lower bound on interval |
-> Double | Upper bound on interval |
-> Double |
Approximate the value of X for which P(x>X)=p.
This method uses a combination of Newton-Raphson iteration and bisection with the given guess as a starting point. The upper and lower bounds specify the interval in which the probability distribution reaches the value p.
sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> DoubleSource
Sum probabilities in inclusive interval.