-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStatisticsSpec.hs
More file actions
71 lines (68 loc) · 2.54 KB
/
StatisticsSpec.hs
File metadata and controls
71 lines (68 loc) · 2.54 KB
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
66
67
68
69
70
71
{-# LANGUAGE TypeApplications #-}
module ArrayFire.StatisticsSpec where
import ArrayFire hiding (not)
import Data.Complex
import Test.Hspec
spec :: Spec
spec =
describe "Statistics spec" $ do
it "Should find the mean" $ do
mean (vector @Double 10 [1..]) 0
`shouldBe`
5.5
it "Should find the weighted-mean" $ do
meanWeighted (vector @Double 10 [1..]) (vector @Double 10 [1..]) 0
`shouldBe`
7.0
it "Should find the variance" $ do
var (vector @Double 8 [1..8]) False 0
`shouldBe`
5.25
it "Should find the weighted variance" $ do
varWeighted (vector @Double 8 [1..]) (vector @Double 8 (repeat 1)) 0
`shouldBe`
5.25
it "Should find the standard deviation" $ do
stdev (vector @Double 10 (cycle [1,-1])) 0
`shouldBe`
1.0
it "Should find the covariance" $ do
cov (vector @Double 10 (repeat 1)) (vector @Double 10 (repeat 1)) False
`shouldBe`
0.0
it "Should find the median" $ do
median (vector @Double 10 [1..]) 0
`shouldBe`
5.5
it "Should find the mean of all elements across all dimensions" $ do
fst (meanAll (matrix @Double (2,2) [[10,10],[10,10]]))
`shouldBe`
10
it "Should find the weighted mean of all elements across all dimensions" $ do
fst (meanAllWeighted (matrix @Double (2,2) [[10,10],[10,10]]) (matrix @Double (2,2) [[10,10],[10,10]]))
`shouldBe`
10
it "Should find the variance of all elements across all dimensions" $ do
fst (varAll (vector @Double 10 (repeat 10)) False)
`shouldBe`
0
it "Should find the weighted variance of all elements across all dimensions" $ do
fst (varAllWeighted (vector @Double 10 (repeat 10)) (vector @Double 10 (repeat 10)))
`shouldBe`
0
it "Should find the stdev of all elements across all dimensions" $ do
fst (stdevAll (vector @Double 10 (repeat 10)))
`shouldBe`
0
it "Should find the median of all elements across all dimensions" $ do
fst (medianAll (vector @Double 10 [1..]))
`shouldBe`
5.5
it "Should find the correlation coefficient" $ do
fst (corrCoef (vector @Int 10 [1..] ) ( vector @Int 10 [10,9..] ))
`shouldBe`
(-1.0)
it "Should find the top k elements" $ do
let (vals,indexes) = topk ( vector @Double 10 [1..] ) 3 TopKDefault
vals `shouldBe` vector @Double 3 [10,9,8]
indexes `shouldBe` vector @Double 3 [9,8,7]