]> Git — Sourcephile - literate-phylomemy.git/blob - tests/Clustering/FrequentItemSet/BruteForceSpec.hs
init
[literate-phylomemy.git] / tests / Clustering / FrequentItemSet / BruteForceSpec.hs
1 {-# LANGUAGE OverloadedLists #-}
2 {-# LANGUAGE OverloadedStrings #-}
3
4 module Clustering.FrequentItemSet.BruteForceSpec where
5
6 import Control.Monad (forM_, return)
7 import Data.Function (on, ($), (&), (.))
8 import Data.Functor ((<$>), (<&>))
9 import Data.Int (Int)
10 import Data.List qualified as List
11 import Data.Ord (Ord (..))
12 import Data.Ratio (Rational, (%))
13 import Data.Semigroup (Semigroup (..))
14 import Data.Sequence qualified as Seq
15 import Data.Set qualified as Set
16 import Data.Text.Short qualified as TextS
17 import GHC.IsList (toList)
18 import Logic
19 import Numeric.Probability (assertProbability)
20 import System.FilePath ((<.>))
21 import Test.Syd
22 import Text.Show (Show (..))
23 import Prelude (Num)
24
25 import Clustering.FrequentItemSet.BruteForce
26 import Utils
27
28 -- | From https://research.nii.ac.jp/~uno/code/lcm.html#IntroductionstoFrequentItemsetMining
29 databaseTakeakiUno :: Ord item => Num item => [Transaction item ()]
30 databaseTakeakiUno =
31 Transaction ()
32 <$> [ [1, 2, 5, 6, 7]
33 , [2, 3, 4, 5]
34 , [1, 2, 7, 8, 9]
35 , [1, 7, 9]
36 , [2, 7, 9]
37 , [2, 7, 9] -- Copy-paste typo on the original example
38 , [1, 9] -- Add this to increase the support of [1,9] because the original example is wrong…
39 , [2]
40 ]
41
42 -- | From https://hal.science/hal-03500847
43 databaseHAL03500847T2 :: Ord item => Num item => [Transaction item ()]
44 databaseHAL03500847T2 =
45 Transaction ()
46 <$> [ [1, 3, 7, 6]
47 , [1, 2, 7]
48 , [2, 8, 9, 10]
49 , [5, 11]
50 ]
51
52 database1 :: [Transaction TextS.ShortText ()]
53 database1 =
54 Transaction ()
55 <$> [["a", "b"]]
56
57 spec :: Spec
58 spec = do
59 {-
60 describe "allFrequentItemSets" do
61 forM_ ([2 .. 3] :: [Int]) \minSupp ->
62 goldenShow ("db=TakeakiUno" <.> "minSupp=" <> show minSupp) $
63 allFrequentItemSets @Int
64 (unitName databaseTakeakiUno)
65 (assertStrictlyPositive minSupp)
66 forM_ ([2 .. 3] :: [Int]) \minSupp ->
67 goldenShow ("db=HAL03500847T2" <.> "minSupp=" <> show minSupp) $
68 allFrequentItemSets @Int
69 (unitName databaseHAL03500847T2)
70 (assertStrictlyPositive minSupp)
71
72 describe "associationRules" do
73 forM_ ([2 .. 3] :: [Int]) \minSupp ->
74 forM_ ([(75 % 100)] :: [Rational]) \minConf ->
75 goldenShow
76 ("db=TakeakiUno" <.> "minSupp=" <> show minSupp <.> "minConf=75%")
77 [ associationRules
78 fis
79 (unitName databaseTakeakiUno)
80 (unitName (assertProbability minConf))
81 | fis <-
82 allFrequentItemSets @Int
83 (unitName databaseTakeakiUno)
84 (assertStrictlyPositive minSupp)
85 ]
86 describe "allClosedFrequentItemSets" do
87 forM_ ([2 .. 3] :: [Int]) \minSupp ->
88 forM_ ([2 .. 3] :: [Int]) \minSize ->
89 goldenShow ("db=TakeakiUno" <.> "minSupp=" <> show minSupp <.> "minSize=" <> show minSize) $
90 allClosedFrequentItemSets @Int
91 (assertStrictlyPositive minSupp)
92 (assertStrictlyPositive minSize)
93 (unitName (databaseTakeakiUno @Int))
94 & unName
95 forM_ ([1 .. 3] :: [Int]) \minSupp ->
96 forM_ ([2 .. 4] :: [Int]) \minSize ->
97 goldenShow ("db=HAL03500847T2" <.> "minSupp=" <> show minSupp <.> "minSize=" <> show minSize) $
98 allClosedFrequentItemSets @Int
99 (assertStrictlyPositive minSupp)
100 (assertStrictlyPositive minSize)
101 (unitName (databaseHAL03500847T2 @Int))
102 & unName
103 describe "allClosedFrequentItemSets" do
104 forM_ ([1 .. 1] :: [Int]) \minSupp ->
105 forM_ ([1 .. 1] :: [Int]) \minSize ->
106 goldenShow ("db=1" <.> "minSupp=" <> show minSupp <.> "minSize=" <> show minSize) $
107 allClosedFrequentItemSets @TextS.ShortText
108 (assertStrictlyPositive minSupp)
109 (assertStrictlyPositive minSize)
110 (unitName database1)
111 & unName
112 -}
113 return ()