1 {-# LANGUAGE OverloadedLists #-}
2 {-# LANGUAGE OverloadedStrings #-}
4 module Clustering.FrequentItemSet.BruteForceSpec where
6 import Control.Monad (forM_, return)
7 import Data.Function (on, ($), (&), (.))
8 import Data.Functor ((<$>), (<&>))
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)
19 import Numeric.Probability (assertProbability)
20 import System.FilePath ((<.>))
22 import Text.Show (Show (..))
25 import Clustering.FrequentItemSet.BruteForce
28 -- | From https://research.nii.ac.jp/~uno/code/lcm.html#IntroductionstoFrequentItemsetMining
29 databaseTakeakiUno :: Ord item => Num item => [Transaction item ()]
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…
42 -- | From https://hal.science/hal-03500847
43 databaseHAL03500847T2 :: Ord item => Num item => [Transaction item ()]
44 databaseHAL03500847T2 =
52 database1 :: [Transaction TextS.ShortText ()]
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)
72 describe "associationRules" do
73 forM_ ([2 .. 3] :: [Int]) \minSupp ->
74 forM_ ([(75 % 100)] :: [Rational]) \minConf ->
76 ("db=TakeakiUno" <.> "minSupp=" <> show minSupp <.> "minConf=75%")
79 (unitName databaseTakeakiUno)
80 (unitName (assertProbability minConf))
82 allFrequentItemSets @Int
83 (unitName databaseTakeakiUno)
84 (assertStrictlyPositive minSupp)
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))
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))
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)