{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
-- |
-- 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
  , cauchyDistributionE
  , standardCauchy
  ) where

import Control.Applicative
import Data.Aeson             (FromJSON(..), ToJSON, Value(..), (.:))
import Data.Binary            (Binary(..))
import Data.Maybe             (fromMaybe)
import Data.Data              (Data, Typeable)
import GHC.Generics           (Generic)
import qualified Statistics.Distribution as D
import Statistics.Internal

-- | 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.
    CauchyDistribution -> Double
cauchyDistribMedian :: {-# UNPACK #-} !Double
    -- | Scale parameter of Cauchy-Lorentz distribution. It's
    --   different from variance and specify half width at half
    --   maximum (HWHM).
  , CauchyDistribution -> Double
cauchyDistribScale  :: {-# UNPACK #-} !Double
  }
  deriving (CauchyDistribution -> CauchyDistribution -> Bool
(CauchyDistribution -> CauchyDistribution -> Bool)
-> (CauchyDistribution -> CauchyDistribution -> Bool)
-> Eq CauchyDistribution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CauchyDistribution -> CauchyDistribution -> Bool
== :: CauchyDistribution -> CauchyDistribution -> Bool
$c/= :: CauchyDistribution -> CauchyDistribution -> Bool
/= :: CauchyDistribution -> CauchyDistribution -> Bool
Eq, Typeable, Typeable CauchyDistribution
Typeable CauchyDistribution =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g)
 -> CauchyDistribution
 -> c CauchyDistribution)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CauchyDistribution)
-> (CauchyDistribution -> Constr)
-> (CauchyDistribution -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CauchyDistribution))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CauchyDistribution))
-> ((forall b. Data b => b -> b)
    -> CauchyDistribution -> CauchyDistribution)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> CauchyDistribution -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CauchyDistribution -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> CauchyDistribution -> m CauchyDistribution)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> CauchyDistribution -> m CauchyDistribution)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> CauchyDistribution -> m CauchyDistribution)
-> Data CauchyDistribution
CauchyDistribution -> Constr
CauchyDistribution -> DataType
(forall b. Data b => b -> b)
-> CauchyDistribution -> CauchyDistribution
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> CauchyDistribution -> u
forall u. (forall d. Data d => d -> u) -> CauchyDistribution -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CauchyDistribution
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CauchyDistribution
-> c CauchyDistribution
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CauchyDistribution)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CauchyDistribution)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CauchyDistribution
-> c CauchyDistribution
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> CauchyDistribution
-> c CauchyDistribution
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CauchyDistribution
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CauchyDistribution
$ctoConstr :: CauchyDistribution -> Constr
toConstr :: CauchyDistribution -> Constr
$cdataTypeOf :: CauchyDistribution -> DataType
dataTypeOf :: CauchyDistribution -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CauchyDistribution)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CauchyDistribution)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CauchyDistribution)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CauchyDistribution)
$cgmapT :: (forall b. Data b => b -> b)
-> CauchyDistribution -> CauchyDistribution
gmapT :: (forall b. Data b => b -> b)
-> CauchyDistribution -> CauchyDistribution
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CauchyDistribution -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CauchyDistribution -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CauchyDistribution -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> CauchyDistribution -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> CauchyDistribution -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CauchyDistribution -> m CauchyDistribution
Data, (forall x. CauchyDistribution -> Rep CauchyDistribution x)
-> (forall x. Rep CauchyDistribution x -> CauchyDistribution)
-> Generic CauchyDistribution
forall x. Rep CauchyDistribution x -> CauchyDistribution
forall x. CauchyDistribution -> Rep CauchyDistribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CauchyDistribution -> Rep CauchyDistribution x
from :: forall x. CauchyDistribution -> Rep CauchyDistribution x
$cto :: forall x. Rep CauchyDistribution x -> CauchyDistribution
to :: forall x. Rep CauchyDistribution x -> CauchyDistribution
Generic)

instance Show CauchyDistribution where
  showsPrec :: Int -> CauchyDistribution -> ShowS
showsPrec Int
i (CD Double
m Double
s) = [Char] -> Double -> Double -> Int -> ShowS
forall a b. (Show a, Show b) => [Char] -> a -> b -> Int -> ShowS
defaultShow2 [Char]
"cauchyDistribution" Double
m Double
s Int
i
instance Read CauchyDistribution where
  readPrec :: ReadPrec CauchyDistribution
readPrec = [Char]
-> (Double -> Double -> Maybe CauchyDistribution)
-> ReadPrec CauchyDistribution
forall a b r.
(Read a, Read b) =>
[Char] -> (a -> b -> Maybe r) -> ReadPrec r
defaultReadPrecM2 [Char]
"cauchyDistribution" Double -> Double -> Maybe CauchyDistribution
cauchyDistributionE

instance ToJSON   CauchyDistribution
instance FromJSON CauchyDistribution where
  parseJSON :: Value -> Parser CauchyDistribution
parseJSON (Object Object
v) = do
    Double
m <- Object
v Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cauchyDistribMedian"
    Double
s <- Object
v Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cauchyDistribScale"
    Parser CauchyDistribution
-> (CauchyDistribution -> Parser CauchyDistribution)
-> Maybe CauchyDistribution
-> Parser CauchyDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Parser CauchyDistribution
forall a. [Char] -> Parser a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> Parser CauchyDistribution)
-> [Char] -> Parser CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> [Char]
errMsg Double
m Double
s) CauchyDistribution -> Parser CauchyDistribution
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CauchyDistribution -> Parser CauchyDistribution)
-> Maybe CauchyDistribution -> Parser CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe CauchyDistribution
cauchyDistributionE Double
m Double
s
  parseJSON Value
_ = Parser CauchyDistribution
forall a. Parser a
forall (f :: * -> *) a. Alternative f => f a
empty

instance Binary CauchyDistribution where
    put :: CauchyDistribution -> Put
put (CD Double
m Double
s) = Double -> Put
forall t. Binary t => t -> Put
put Double
m Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Double -> Put
forall t. Binary t => t -> Put
put Double
s
    get :: Get CauchyDistribution
get = do
      Double
m <- Get Double
forall t. Binary t => Get t
get
      Double
s <- Get Double
forall t. Binary t => Get t
get
      Get CauchyDistribution
-> (CauchyDistribution -> Get CauchyDistribution)
-> Maybe CauchyDistribution
-> Get CauchyDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Get CauchyDistribution
forall a. HasCallStack => [Char] -> a
error ([Char] -> Get CauchyDistribution)
-> [Char] -> Get CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> [Char]
errMsg Double
m Double
s) CauchyDistribution -> Get CauchyDistribution
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CauchyDistribution -> Get CauchyDistribution)
-> Maybe CauchyDistribution -> Get CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe CauchyDistribution
cauchyDistributionE Double
m Double
s


-- | Cauchy distribution
cauchyDistribution :: Double    -- ^ Central point
                   -> Double    -- ^ Scale parameter (FWHM)
                   -> CauchyDistribution
cauchyDistribution :: Double -> Double -> CauchyDistribution
cauchyDistribution Double
m Double
s
  = CauchyDistribution
-> Maybe CauchyDistribution -> CauchyDistribution
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> CauchyDistribution
forall a. HasCallStack => [Char] -> a
error ([Char] -> CauchyDistribution) -> [Char] -> CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> [Char]
errMsg Double
m Double
s)
  (Maybe CauchyDistribution -> CauchyDistribution)
-> Maybe CauchyDistribution -> CauchyDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe CauchyDistribution
cauchyDistributionE Double
m Double
s


-- | Cauchy distribution
cauchyDistributionE :: Double    -- ^ Central point
                    -> Double    -- ^ Scale parameter (FWHM)
                    -> Maybe CauchyDistribution
cauchyDistributionE :: Double -> Double -> Maybe CauchyDistribution
cauchyDistributionE Double
m Double
s
  | Double
s Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0     = CauchyDistribution -> Maybe CauchyDistribution
forall a. a -> Maybe a
Just (Double -> Double -> CauchyDistribution
CD Double
m Double
s)
  | Bool
otherwise = Maybe CauchyDistribution
forall a. Maybe a
Nothing

errMsg :: Double -> Double -> String
errMsg :: Double -> Double -> [Char]
errMsg Double
_ Double
s
  = [Char]
"Statistics.Distribution.CauchyLorentz.cauchyDistribution: FWHM must be positive. Got "
  [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Double -> [Char]
forall a. Show a => a -> [Char]
show Double
s

-- | Standard Cauchy distribution. It's centered at 0 and have 1 FWHM
standardCauchy :: CauchyDistribution
standardCauchy :: CauchyDistribution
standardCauchy = Double -> Double -> CauchyDistribution
CD Double
0 Double
1


instance D.Distribution CauchyDistribution where
  cumulative :: CauchyDistribution -> Double -> Double
cumulative (CD Double
m Double
s) Double
x
    | Double
y Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< -Double
1    = Double -> Double
forall a. Floating a => a -> a
atan (-Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
y) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
forall a. Floating a => a
pi
    | Bool
otherwise = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
atan Double
y Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
forall a. Floating a => a
pi
    where
       y :: Double
y = (Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
m) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
s
  complCumulative :: CauchyDistribution -> Double -> Double
complCumulative (CD Double
m Double
s) Double
x
    | Double
y Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
1     = Double -> Double
forall a. Floating a => a -> a
atan (Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
y) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
forall a. Floating a => a
pi
    | Bool
otherwise = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double
forall a. Floating a => a -> a
atan Double
y Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
forall a. Floating a => a
pi
    where
       y :: Double
y = (Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
m) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
s

instance D.ContDistr CauchyDistribution where
  density :: CauchyDistribution -> Double -> Double
density (CD Double
m Double
s) Double
x = (Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
forall a. Floating a => a
pi) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
s Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
yDouble -> Double -> Double
forall a. Num a => a -> a -> a
*Double
y))
    where y :: Double
y = (Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
m) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
s
  quantile :: CauchyDistribution -> Double -> Double
quantile (CD Double
m Double
s) Double
p
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0    = -Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
1    =  Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0.5  = Double
m
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
0     = Double
forall {a}. a
err
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
0.5   = Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
tan( Double
forall a. Floating a => a
pi Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
p )
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
1     = Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
tan( Double
forall a. Floating a => a
pi Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
p) )
    | Bool
otherwise = Double
forall {a}. a
err
    where
      err :: a
err = [Char] -> a
forall a. HasCallStack => [Char] -> a
error
          ([Char] -> a) -> [Char] -> a
forall a b. (a -> b) -> a -> b
$ [Char]
"Statistics.Distribution.CauchyLorentz.quantile: p must be in [0,1] range. Got: "[Char] -> ShowS
forall a. [a] -> [a] -> [a]
++Double -> [Char]
forall a. Show a => a -> [Char]
show Double
p
  complQuantile :: CauchyDistribution -> Double -> Double
complQuantile (CD Double
m Double
s) Double
p
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0    =  Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
1    = -Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0
    | Double
p Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0.5  = Double
m
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
0     = Double
forall {a}. a
err
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
0.5   = Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
tan( Double
forall a. Floating a => a
pi Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
p )
    | Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
1     = Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
tan( Double
forall a. Floating a => a
pi Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
p) )
    | Bool
otherwise = Double
forall {a}. a
err
    where
      err :: a
err = [Char] -> a
forall a. HasCallStack => [Char] -> a
error
          ([Char] -> a) -> [Char] -> a
forall a b. (a -> b) -> a -> b
$ [Char]
"Statistics.Distribution.CauchyLorentz.quantile: p must be in [0,1] range. Got: "[Char] -> ShowS
forall a. [a] -> [a] -> [a]
++Double -> [Char]
forall a. Show a => a -> [Char]
show Double
p


instance D.ContGen CauchyDistribution where
  genContVar :: forall g (m :: * -> *).
StatefulGen g m =>
CauchyDistribution -> g -> m Double
genContVar = CauchyDistribution -> g -> m Double
forall d g (m :: * -> *).
(ContDistr d, StatefulGen g m) =>
d -> g -> m Double
D.genContinuous

instance D.Entropy CauchyDistribution where
  entropy :: CauchyDistribution -> Double
entropy (CD Double
_ Double
s) = Double -> Double
forall a. Floating a => a -> a
log Double
s Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
log (Double
4Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
forall a. Floating a => a
pi)

instance D.MaybeEntropy CauchyDistribution where
  maybeEntropy :: CauchyDistribution -> Maybe Double
maybeEntropy = Double -> Maybe Double
forall a. a -> Maybe a
Just (Double -> Maybe Double)
-> (CauchyDistribution -> Double)
-> CauchyDistribution
-> Maybe Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CauchyDistribution -> Double
forall d. Entropy d => d -> Double
D.entropy