{- |
Collection of some shapes of distribution.
-}
module Numeric.Probability.Shape where

{- |
A shape is a mapping from the interval @[0,1]@ to non-negative numbers.
They need not to be normalized (sum up to 1)
because this is done by subsequent steps.
(It would also be impossible to normalize the function in a way
that each discretization is normalized as well.)
-}
type T prob = prob -> prob


linear :: Fractional prob => T prob
linear :: forall prob. Fractional prob => T prob
linear = forall a. a -> a
id

uniform :: Fractional prob => T prob
uniform :: forall prob. Fractional prob => T prob
uniform = forall a b. a -> b -> a
const prob
1

negExp :: Floating prob => T prob
negExp :: forall prob. Floating prob => T prob
negExp prob
x = forall prob. Floating prob => T prob
exp (-prob
x)

normal :: Floating prob => T prob
normal :: forall prob. Floating prob => T prob
normal = forall prob. Floating prob => prob -> prob -> prob -> prob
normalCurve prob
0.5 prob
0.5

normalCurve :: Floating prob =>
   prob -> prob -> prob -> prob
normalCurve :: forall prob. Floating prob => prob -> prob -> prob -> prob
normalCurve prob
mean prob
dev prob
x =
   let u :: prob
u = (prob
x forall a. Num a => a -> a -> a
- prob
mean) forall a. Fractional a => a -> a -> a
/ prob
dev
   in  forall prob. Floating prob => T prob
exp (-prob
1forall a. Fractional a => a -> a -> a
/prob
2 forall a. Num a => a -> a -> a
* prob
uforall a b. (Num a, Integral b) => a -> b -> a
^(Int
2::Int)) forall a. Fractional a => a -> a -> a
/ forall prob. Floating prob => T prob
sqrt (prob
2 forall a. Num a => a -> a -> a
* forall a. Floating a => a
pi)