probability-polynomial-1.0.0.0: Probability distributions via piecewise polynomials
CopyrightPredictable Network Solutions Ltd. 2020-2024
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Numeric.Measure.Probability

Description

 
Synopsis

Type

data Prob a Source #

A probability measure on the number line.

A probability measure is a Measure whose total is 1.

Instances

Instances details
Show a => Show (Prob a) Source # 
Instance details

Defined in Numeric.Measure.Probability

Methods

showsPrec :: Int -> Prob a -> ShowS #

show :: Prob a -> String #

showList :: [Prob a] -> ShowS #

NFData a => NFData (Prob a) Source # 
Instance details

Defined in Numeric.Measure.Probability

Methods

rnf :: Prob a -> () #

(Ord a, Num a) => Eq (Prob a) Source #

Two probability measures are equal if they have the same cumulative distribution functions.

px == py
  implies
  forall t. eval (distribution px) t = eval (distribution py) t
Instance details

Defined in Numeric.Measure.Probability

Methods

(==) :: Prob a -> Prob a -> Bool #

(/=) :: Prob a -> Prob a -> Bool #

dirac :: (Ord a, Num a) => a -> Prob a Source #

A Dirac measure at the given point x.

dirac x is the probability distribution where x occurs with certainty.

uniform :: (Ord a, Num a, Fractional a) => a -> a -> Prob a Source #

The uniform probability distribution on the interval \( [x,y) \).

distribution :: (Ord a, Num a) => Prob a -> Piecewise (Poly a) Source #

eval (distribution m) x is the probability of picking a number <= x.

This is known as the cumulative distribution function.

fromDistribution :: (Ord a, Num a, Fractional a) => Piecewise (Poly a) -> Maybe (Prob a) Source #

Construct a probability distribution from its cumulative distribution function.

Return Nothing if * the cumulative distribution function is not monotonicall increasing * the last piece of the piecewise function is not a constant equal to 1.

measure :: (Ord a, Num a) => Prob a -> Measure a Source #

View the probability measure as a Measure.

fromMeasure :: (Ord a, Num a, Fractional a) => Measure a -> Maybe (Prob a) Source #

View a Measure as a probability distribution.

The measure m must be positive, with total weight 1, that is

isPositive m == True
total m == 1

These preconditions are checked and the function returns Nothing if they fail.

unsafeFromMeasure :: Measure a -> Prob a Source #

View a Measure as a probability distribution.

Variant of fromMeasure where the precondition are not checked!

Observations

support :: (Ord a, Num a) => Prob a -> Maybe (a, a) Source #

The support is the smallest closed, contiguous interval \( [x,y] \) outside of which the probability is zero.

Returns Nothing if the interval is empty.

expectation :: (Ord a, Num a, Fractional a) => Poly a -> Prob a -> a Source #

Compute the expected value of a polynomial f with respect to the given probability distribution, \( E[f(X)] \).

moments :: (Ord a, Num a, Fractional a) => Prob a -> Moments a Source #

Compute the first four commonly used moments of a probability distribution.

Operations, numerical

choice :: (Ord a, Num a, Fractional a) => a -> Prob a -> Prob a -> Prob a Source #

Left-biased random choice.

choice p is a probability distribution where events from the left argument are chosen with probablity p and events from the right argument are chosen with probability (1-p).

eval (distribution (choice p mx my)) z
   = p * eval (distribution mx) z + (1-p) * eval (distribution my) z

translate :: (Ord a, Num a, Fractional a) => a -> Prob a -> Prob a Source #

Translate a probability distribution along the number line.

eval (distribution (translate y m)) x
   = eval (distribution m) (x - y)

convolve :: (Ord a, Num a, Fractional a) => Prob a -> Prob a -> Prob a Source #

Additive convolution of two probability measures.

Properties:

convolve (dirac x) (dirac y) = dirac (x + y)

convolve mx my               =  convolve my mx
translate z (convolve mx my) =  convolve (translate z mx) my