1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
{-# LANGUAGE DeriveDataTypeable #-}
-- |
-- Module : Statistics.Distribution.CauchyLorentz
-- Copyright : (c) 2011 Aleksey Khudyakov
-- License : BSD3
--
-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : portable
--
-- The Cauchy-Lorentz distribution. It's also known as Lorentz
-- distribution or Breit–Wigner distribution.
--
-- It doesn't have mean and variance.
module Statistics.Distribution.CauchyLorentz (
CauchyDistribution
, cauchyDistribMedian
, cauchyDistribScale
-- * Constructors
, cauchyDistribution
, standardCauchy
) where
import Data.Typeable (Typeable)
import qualified Statistics.Distribution as D
-- | Cauchy-Lorentz distribution.
data CauchyDistribution = CD {
-- | Central value of Cauchy-Lorentz distribution which is its
-- mode and median. Distribution doesn't have mean so function
-- is named after median.
cauchyDistribMedian :: {-# UNPACK #-} !Double
-- | Scale parameter of Cauchy-Lorentz distribution. It's
-- different from variance and specify half width at half
-- maximum (HWHM).
, cauchyDistribScale :: {-# UNPACK #-} !Double
}
deriving (Eq,Show,Read,Typeable)
-- | Cauchy distribution
cauchyDistribution :: Double -- ^ Central point
-> Double -- ^ Scale parameter (FWHM)
-> CauchyDistribution
cauchyDistribution m s
| s > 0 = CD m s
| otherwise =
error $ "Statistics.Distribution.CauchyLorentz.cauchyDistribution: FWHM must be positive. Got " ++ show s
standardCauchy :: CauchyDistribution
standardCauchy = CD 0 1
instance D.Distribution CauchyDistribution where
cumulative (CD m s) x = 0.5 + atan( (x - m) / s ) / pi
instance D.ContDistr CauchyDistribution where
density (CD m s) x = (1 / pi) / (s * (1 + y*y))
where y = (x - m) / s
quantile (CD m s) p
| p > 0 && p < 1 = m + s * tan( pi * (p - 0.5) )
| p == 0 = -1 / 0
| p == 1 = 1 / 0
| otherwise =
error $ "Statistics.Distribution.CauchyLorentz..quantile: p must be in [0,1] range. Got: "++show p
|