Types classes for probability distrubutions
- class Distribution d where
- class Distribution d => DiscreteDistr d where
- class Distribution d => ContDistr d where
- class Distribution d => MaybeMean d where
- class MaybeMean d => Mean d where
- class MaybeMean d => MaybeVariance d where
- class (Mean d, MaybeVariance d) => Variance d where
- class Distribution d => ContGen d where
- class (DiscreteDistr d, ContGen d) => DiscreteGen d where
- genContinous :: (ContDistr d, PrimMonad m) => d -> Gen (PrimState m) -> m Double
- findRoot :: ContDistr d => d -> Double -> Double -> Double -> Double -> Double
- sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> Double
Type class common to all distributions. Only c.d.f. could be defined for both discrete and continous distributions.
Cumulative distribution function. The probability that a random variable X is less or equal than x, i.e. P(X≤x).
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
Discrete probability distribution.
Continuous probability distributuion
Probability density function. Probability that random variable X lies in the infinitesimal interval [x,x+δx) equal to density(x)⋅δx
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
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.
Type class for distributions with variance. If distibution have finite variance for all valid parameter values it should be instance of this type class.
Random number generation
Generate discrete random variates which have given distribution.
Generate discrete random variates which have given
ContGen is superclass because it's always possible
to generate real-valued variates from integer values
Generate variates from continous distribution using inverse transform rule.
|:: ContDistr d|
Lower bound on interval
Upper bound on interval
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.