{-# LANGUAGE FlexibleContexts #-}
module Statistics.Sample
(
Sample
, WeightedSample
, range
, mean
, welfordMean
, meanWeighted
, harmonicMean
, geometricMean
, centralMoment
, centralMoments
, skewness
, kurtosis
, variance
, varianceUnbiased
, meanVariance
, meanVarianceUnb
, stdDev
, varianceWeighted
, stdErrMean
, fastVariance
, fastVarianceUnbiased
, fastStdDev
, covariance
, correlation
, pair
) where
import Statistics.Function (minMax)
import Statistics.Sample.Internal (robustSumVar, sum)
import Statistics.Types.Internal (Sample,WeightedSample)
import qualified Data.Vector as V
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed as U
import Prelude hiding ((^), sum)
range :: (G.Vector v Double) => v Double -> Double
range :: forall (v :: * -> *). Vector v Double => v Double -> Double
range v Double
s = Double
hi forall a. Num a => a -> a -> a
- Double
lo
where (Double
lo , Double
hi) = forall (v :: * -> *).
Vector v Double =>
v Double -> (Double, Double)
minMax v Double
s
{-# INLINE range #-}
mean :: (G.Vector v Double) => v Double -> Double
mean :: forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
xs = forall (v :: * -> *). Vector v Double => v Double -> Double
sum v Double
xs forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
xs)
{-# SPECIALIZE mean :: U.Vector Double -> Double #-}
{-# SPECIALIZE mean :: V.Vector Double -> Double #-}
welfordMean :: (G.Vector v Double) => v Double -> Double
welfordMean :: forall (v :: * -> *). Vector v Double => v Double -> Double
welfordMean = T -> Double
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' T -> Double -> T
go (Double -> Int -> T
T Double
0 Int
0)
where
fini :: T -> Double
fini (T Double
a Int
_) = Double
a
go :: T -> Double -> T
go (T Double
m Int
n) Double
x = Double -> Int -> T
T Double
m' Int
n'
where m' :: Double
m' = Double
m forall a. Num a => a -> a -> a
+ (Double
x forall a. Num a => a -> a -> a
- Double
m) forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n'
n' :: Int
n' = Int
n forall a. Num a => a -> a -> a
+ Int
1
{-# SPECIALIZE welfordMean :: U.Vector Double -> Double #-}
{-# SPECIALIZE welfordMean :: V.Vector Double -> Double #-}
meanWeighted :: (G.Vector v (Double,Double)) => v (Double,Double) -> Double
meanWeighted :: forall (v :: * -> *).
Vector v (Double, Double) =>
v (Double, Double) -> Double
meanWeighted = V -> Double
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' V -> (Double, Double) -> V
go (Double -> Double -> V
V Double
0 Double
0)
where
fini :: V -> Double
fini (V Double
a Double
_) = Double
a
go :: V -> (Double, Double) -> V
go (V Double
m Double
w) (Double
x,Double
xw) = Double -> Double -> V
V Double
m' Double
w'
where m' :: Double
m' | Double
w' forall a. Eq a => a -> a -> Bool
== Double
0 = Double
0
| Bool
otherwise = Double
m forall a. Num a => a -> a -> a
+ Double
xw forall a. Num a => a -> a -> a
* (Double
x forall a. Num a => a -> a -> a
- Double
m) forall a. Fractional a => a -> a -> a
/ Double
w'
w' :: Double
w' = Double
w forall a. Num a => a -> a -> a
+ Double
xw
{-# INLINE meanWeighted #-}
harmonicMean :: (G.Vector v Double) => v Double -> Double
harmonicMean :: forall (v :: * -> *). Vector v Double => v Double -> Double
harmonicMean = T -> Double
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' T -> Double -> T
go (Double -> Int -> T
T Double
0 Int
0)
where
fini :: T -> Double
fini (T Double
b Int
a) = forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a forall a. Fractional a => a -> a -> a
/ Double
b
go :: T -> Double -> T
go (T Double
x Int
y) Double
n = Double -> Int -> T
T (Double
x forall a. Num a => a -> a -> a
+ (Double
1forall a. Fractional a => a -> a -> a
/Double
n)) (Int
yforall a. Num a => a -> a -> a
+Int
1)
{-# INLINE harmonicMean #-}
geometricMean :: (G.Vector v Double) => v Double -> Double
geometricMean :: forall (v :: * -> *). Vector v Double => v Double -> Double
geometricMean = forall a. Floating a => a -> a
exp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *). Vector v Double => v Double -> Double
mean forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map forall a. Floating a => a -> a
log
{-# INLINE geometricMean #-}
centralMoment :: (G.Vector v Double) => Int -> v Double -> Double
centralMoment :: forall (v :: * -> *). Vector v Double => Int -> v Double -> Double
centralMoment Int
a v Double
xs
| Int
a forall a. Ord a => a -> a -> Bool
< Int
0 = forall a. HasCallStack => [Char] -> a
error [Char]
"Statistics.Sample.centralMoment: negative input"
| Int
a forall a. Eq a => a -> a -> Bool
== Int
0 = Double
1
| Int
a forall a. Eq a => a -> a -> Bool
== Int
1 = Double
0
| Bool
otherwise = forall (v :: * -> *). Vector v Double => v Double -> Double
sum (forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map Double -> Double
go v Double
xs) forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
xs)
where
go :: Double -> Double
go Double
x = (Double
xforall a. Num a => a -> a -> a
-Double
m) Double -> Int -> Double
^ Int
a
m :: Double
m = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
xs
{-# SPECIALIZE centralMoment :: Int -> U.Vector Double -> Double #-}
{-# SPECIALIZE centralMoment :: Int -> V.Vector Double -> Double #-}
centralMoments :: (G.Vector v Double) => Int -> Int -> v Double -> (Double, Double)
centralMoments :: forall (v :: * -> *).
Vector v Double =>
Int -> Int -> v Double -> (Double, Double)
centralMoments Int
a Int
b v Double
xs
| Int
a forall a. Ord a => a -> a -> Bool
< Int
2 Bool -> Bool -> Bool
|| Int
b forall a. Ord a => a -> a -> Bool
< Int
2 = (forall (v :: * -> *). Vector v Double => Int -> v Double -> Double
centralMoment Int
a v Double
xs , forall (v :: * -> *). Vector v Double => Int -> v Double -> Double
centralMoment Int
b v Double
xs)
| Bool
otherwise = V -> (Double, Double)
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' V -> Double -> V
go (Double -> Double -> V
V Double
0 Double
0) forall a b. (a -> b) -> a -> b
$ v Double
xs
where go :: V -> Double -> V
go (V Double
i Double
j) Double
x = Double -> Double -> V
V (Double
i forall a. Num a => a -> a -> a
+ Double
dDouble -> Int -> Double
^Int
a) (Double
j forall a. Num a => a -> a -> a
+ Double
dDouble -> Int -> Double
^Int
b)
where d :: Double
d = Double
x forall a. Num a => a -> a -> a
- Double
m
fini :: V -> (Double, Double)
fini (V Double
i Double
j) = (Double
i forall a. Fractional a => a -> a -> a
/ Double
n , Double
j forall a. Fractional a => a -> a -> a
/ Double
n)
m :: Double
m = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
xs
n :: Double
n = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
xs)
{-# SPECIALIZE
centralMoments :: Int -> Int -> U.Vector Double -> (Double, Double) #-}
{-# SPECIALIZE
centralMoments :: Int -> Int -> V.Vector Double -> (Double, Double) #-}
skewness :: (G.Vector v Double) => v Double -> Double
skewness :: forall (v :: * -> *). Vector v Double => v Double -> Double
skewness v Double
xs = Double
c3 forall a. Num a => a -> a -> a
* Double
c2 forall a. Floating a => a -> a -> a
** (-Double
1.5)
where (Double
c3 , Double
c2) = forall (v :: * -> *).
Vector v Double =>
Int -> Int -> v Double -> (Double, Double)
centralMoments Int
3 Int
2 v Double
xs
{-# SPECIALIZE skewness :: U.Vector Double -> Double #-}
{-# SPECIALIZE skewness :: V.Vector Double -> Double #-}
kurtosis :: (G.Vector v Double) => v Double -> Double
kurtosis :: forall (v :: * -> *). Vector v Double => v Double -> Double
kurtosis v Double
xs = Double
c4 forall a. Fractional a => a -> a -> a
/ (Double
c2 forall a. Num a => a -> a -> a
* Double
c2) forall a. Num a => a -> a -> a
- Double
3
where (Double
c4 , Double
c2) = forall (v :: * -> *).
Vector v Double =>
Int -> Int -> v Double -> (Double, Double)
centralMoments Int
4 Int
2 v Double
xs
{-# SPECIALIZE kurtosis :: U.Vector Double -> Double #-}
{-# SPECIALIZE kurtosis :: V.Vector Double -> Double #-}
data V = V {-# UNPACK #-} !Double {-# UNPACK #-} !Double
variance :: (G.Vector v Double) => v Double -> Double
variance :: forall (v :: * -> *). Vector v Double => v Double -> Double
variance v Double
samp
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = forall (v :: * -> *).
Vector v Double =>
Double -> v Double -> Double
robustSumVar (forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
samp) v Double
samp forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
| Bool
otherwise = Double
0
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
samp
{-# SPECIALIZE variance :: U.Vector Double -> Double #-}
{-# SPECIALIZE variance :: V.Vector Double -> Double #-}
varianceUnbiased :: (G.Vector v Double) => v Double -> Double
varianceUnbiased :: forall (v :: * -> *). Vector v Double => v Double -> Double
varianceUnbiased v Double
samp
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = forall (v :: * -> *).
Vector v Double =>
Double -> v Double -> Double
robustSumVar (forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
samp) v Double
samp forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
nforall a. Num a => a -> a -> a
-Int
1)
| Bool
otherwise = Double
0
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
samp
{-# SPECIALIZE varianceUnbiased :: U.Vector Double -> Double #-}
{-# SPECIALIZE varianceUnbiased :: V.Vector Double -> Double #-}
meanVariance :: (G.Vector v Double) => v Double -> (Double,Double)
meanVariance :: forall (v :: * -> *).
Vector v Double =>
v Double -> (Double, Double)
meanVariance v Double
samp
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = (Double
m, forall (v :: * -> *).
Vector v Double =>
Double -> v Double -> Double
robustSumVar Double
m v Double
samp forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
| Bool
otherwise = (Double
m, Double
0)
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
samp
m :: Double
m = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
samp
{-# SPECIALIZE meanVariance :: U.Vector Double -> (Double,Double) #-}
{-# SPECIALIZE meanVariance :: V.Vector Double -> (Double,Double) #-}
meanVarianceUnb :: (G.Vector v Double) => v Double -> (Double,Double)
meanVarianceUnb :: forall (v :: * -> *).
Vector v Double =>
v Double -> (Double, Double)
meanVarianceUnb v Double
samp
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = (Double
m, forall (v :: * -> *).
Vector v Double =>
Double -> v Double -> Double
robustSumVar Double
m v Double
samp forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
nforall a. Num a => a -> a -> a
-Int
1))
| Bool
otherwise = (Double
m, Double
0)
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v Double
samp
m :: Double
m = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
samp
{-# SPECIALIZE meanVarianceUnb :: U.Vector Double -> (Double,Double) #-}
{-# SPECIALIZE meanVarianceUnb :: V.Vector Double -> (Double,Double) #-}
stdDev :: (G.Vector v Double) => v Double -> Double
stdDev :: forall (v :: * -> *). Vector v Double => v Double -> Double
stdDev = forall a. Floating a => a -> a
sqrt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *). Vector v Double => v Double -> Double
varianceUnbiased
{-# SPECIALIZE stdDev :: U.Vector Double -> Double #-}
{-# SPECIALIZE stdDev :: V.Vector Double -> Double #-}
stdErrMean :: (G.Vector v Double) => v Double -> Double
stdErrMean :: forall (v :: * -> *). Vector v Double => v Double -> Double
stdErrMean v Double
samp = forall (v :: * -> *). Vector v Double => v Double -> Double
stdDev v Double
samp forall a. Fractional a => a -> a -> a
/ (forall a. Floating a => a -> a
sqrt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a. Vector v a => v a -> Int
G.length) v Double
samp
{-# SPECIALIZE stdErrMean :: U.Vector Double -> Double #-}
{-# SPECIALIZE stdErrMean :: V.Vector Double -> Double #-}
robustSumVarWeighted :: (G.Vector v (Double,Double)) => v (Double,Double) -> V
robustSumVarWeighted :: forall (v :: * -> *).
Vector v (Double, Double) =>
v (Double, Double) -> V
robustSumVarWeighted v (Double, Double)
samp = forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' V -> (Double, Double) -> V
go (Double -> Double -> V
V Double
0 Double
0) v (Double, Double)
samp
where
go :: V -> (Double, Double) -> V
go (V Double
s Double
w) (Double
x,Double
xw) = Double -> Double -> V
V (Double
s forall a. Num a => a -> a -> a
+ Double
xwforall a. Num a => a -> a -> a
*Double
dforall a. Num a => a -> a -> a
*Double
d) (Double
w forall a. Num a => a -> a -> a
+ Double
xw)
where d :: Double
d = Double
x forall a. Num a => a -> a -> a
- Double
m
m :: Double
m = forall (v :: * -> *).
Vector v (Double, Double) =>
v (Double, Double) -> Double
meanWeighted v (Double, Double)
samp
{-# INLINE robustSumVarWeighted #-}
varianceWeighted :: (G.Vector v (Double,Double)) => v (Double,Double) -> Double
varianceWeighted :: forall (v :: * -> *).
Vector v (Double, Double) =>
v (Double, Double) -> Double
varianceWeighted v (Double, Double)
samp
| forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v (Double, Double)
samp forall a. Ord a => a -> a -> Bool
> Int
1 = V -> Double
fini forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *).
Vector v (Double, Double) =>
v (Double, Double) -> V
robustSumVarWeighted v (Double, Double)
samp
| Bool
otherwise = Double
0
where
fini :: V -> Double
fini (V Double
s Double
w) = Double
s forall a. Fractional a => a -> a -> a
/ Double
w
{-# SPECIALIZE varianceWeighted :: U.Vector (Double,Double) -> Double #-}
{-# SPECIALIZE varianceWeighted :: V.Vector (Double,Double) -> Double #-}
fastVar :: (G.Vector v Double) => v Double -> T1
fastVar :: forall (v :: * -> *). Vector v Double => v Double -> T1
fastVar = forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
G.foldl' T1 -> Double -> T1
go (Int -> Double -> Double -> T1
T1 Int
0 Double
0 Double
0)
where
go :: T1 -> Double -> T1
go (T1 Int
n Double
m Double
s) Double
x = Int -> Double -> Double -> T1
T1 Int
n' Double
m' Double
s'
where n' :: Int
n' = Int
n forall a. Num a => a -> a -> a
+ Int
1
m' :: Double
m' = Double
m forall a. Num a => a -> a -> a
+ Double
d forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n'
s' :: Double
s' = Double
s forall a. Num a => a -> a -> a
+ Double
d forall a. Num a => a -> a -> a
* (Double
x forall a. Num a => a -> a -> a
- Double
m')
d :: Double
d = Double
x forall a. Num a => a -> a -> a
- Double
m
fastVariance :: (G.Vector v Double) => v Double -> Double
fastVariance :: forall (v :: * -> *). Vector v Double => v Double -> Double
fastVariance = T1 -> Double
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *). Vector v Double => v Double -> T1
fastVar
where fini :: T1 -> Double
fini (T1 Int
n Double
_m Double
s)
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = Double
s forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
| Bool
otherwise = Double
0
{-# INLINE fastVariance #-}
fastVarianceUnbiased :: (G.Vector v Double) => v Double -> Double
fastVarianceUnbiased :: forall (v :: * -> *). Vector v Double => v Double -> Double
fastVarianceUnbiased = T1 -> Double
fini forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *). Vector v Double => v Double -> T1
fastVar
where fini :: T1 -> Double
fini (T1 Int
n Double
_m Double
s)
| Int
n forall a. Ord a => a -> a -> Bool
> Int
1 = Double
s forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
n forall a. Num a => a -> a -> a
- Int
1)
| Bool
otherwise = Double
0
{-# INLINE fastVarianceUnbiased #-}
fastStdDev :: (G.Vector v Double) => v Double -> Double
fastStdDev :: forall (v :: * -> *). Vector v Double => v Double -> Double
fastStdDev = forall a. Floating a => a -> a
sqrt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *). Vector v Double => v Double -> Double
fastVariance
{-# INLINE fastStdDev #-}
covariance :: (G.Vector v (Double,Double), G.Vector v Double)
=> v (Double,Double)
-> Double
covariance :: forall (v :: * -> *).
(Vector v (Double, Double), Vector v Double) =>
v (Double, Double) -> Double
covariance v (Double, Double)
xy
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 = Double
0
| Bool
otherwise = forall (v :: * -> *). Vector v Double => v Double -> Double
mean forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
G.zipWith forall a. Num a => a -> a -> a
(*)
(forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map (\Double
x -> Double
x forall a. Num a => a -> a -> a
- Double
muX) v Double
xs)
(forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map (\Double
y -> Double
y forall a. Num a => a -> a -> a
- Double
muY) v Double
ys)
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v (Double, Double)
xy
(v Double
xs,v Double
ys) = forall (v :: * -> *) a b.
(Vector v a, Vector v b, Vector v (a, b)) =>
v (a, b) -> (v a, v b)
G.unzip v (Double, Double)
xy
muX :: Double
muX = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
xs
muY :: Double
muY = forall (v :: * -> *). Vector v Double => v Double -> Double
mean v Double
ys
{-# SPECIALIZE covariance :: U.Vector (Double,Double) -> Double #-}
{-# SPECIALIZE covariance :: V.Vector (Double,Double) -> Double #-}
correlation :: (G.Vector v (Double,Double), G.Vector v Double)
=> v (Double,Double)
-> Double
correlation :: forall (v :: * -> *).
(Vector v (Double, Double), Vector v Double) =>
v (Double, Double) -> Double
correlation v (Double, Double)
xy
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 = Double
0
| Bool
otherwise = Double
cov forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sqrt (Double
varX forall a. Num a => a -> a -> a
* Double
varY)
where
n :: Int
n = forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v (Double, Double)
xy
(v Double
xs,v Double
ys) = forall (v :: * -> *) a b.
(Vector v a, Vector v b, Vector v (a, b)) =>
v (a, b) -> (v a, v b)
G.unzip v (Double, Double)
xy
(Double
muX,Double
varX) = forall (v :: * -> *).
Vector v Double =>
v Double -> (Double, Double)
meanVariance v Double
xs
(Double
muY,Double
varY) = forall (v :: * -> *).
Vector v Double =>
v Double -> (Double, Double)
meanVariance v Double
ys
cov :: Double
cov = forall (v :: * -> *). Vector v Double => v Double -> Double
mean forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
G.zipWith forall a. Num a => a -> a -> a
(*)
(forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map (\Double
x -> Double
x forall a. Num a => a -> a -> a
- Double
muX) v Double
xs)
(forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
G.map (\Double
y -> Double
y forall a. Num a => a -> a -> a
- Double
muY) v Double
ys)
{-# SPECIALIZE correlation :: U.Vector (Double,Double) -> Double #-}
{-# SPECIALIZE correlation :: V.Vector (Double,Double) -> Double #-}
pair :: (G.Vector v a, G.Vector v b, G.Vector v (a,b)) => v a -> v b -> v (a,b)
pair :: forall (v :: * -> *) a b.
(Vector v a, Vector v b, Vector v (a, b)) =>
v a -> v b -> v (a, b)
pair v a
va v b
vb
| forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v a
va forall a. Eq a => a -> a -> Bool
== forall (v :: * -> *) a. Vector v a => v a -> Int
G.length v b
vb = forall (v :: * -> *) a b.
(Vector v a, Vector v b, Vector v (a, b)) =>
v a -> v b -> v (a, b)
G.zip v a
va v b
vb
| Bool
otherwise = forall a. HasCallStack => [Char] -> a
error [Char]
"Statistics.Sample.pair: vector must have same length"
{-# INLINE pair #-}
(^) :: Double -> Int -> Double
Double
x ^ :: Double -> Int -> Double
^ Int
1 = Double
x
Double
x ^ Int
n = Double
x forall a. Num a => a -> a -> a
* (Double
x Double -> Int -> Double
^ (Int
nforall a. Num a => a -> a -> a
-Int
1))
{-# INLINE (^) #-}
data T = T {-# UNPACK #-}!Double {-# UNPACK #-}!Int
data T1 = T1 {-# UNPACK #-}!Int {-# UNPACK #-}!Double {-# UNPACK #-}!Double