{-# LANGUAGE OverloadedLists #-} module Clustering.FrequentItemSet.BruteForceSpec where import Data.Either (fromRight) import Data.Function (($)) import Data.Functor ((<$>)) import Data.Int (Int) import Data.Ord (Ord) import Data.Ratio ((%)) import Logic import Logic.Theory.Arithmetic import Logic.Theory.Ord import Numeric.Probability (probability) import Test.Syd import Prelude (Num, undefined) import Clustering.FrequentItemSet.BruteForce exampleTakeakiUnoDB :: Ord item => Num item => Transactions item exampleTakeakiUnoDB = [ [1, 2, 5, 6, 7] , [2, 3, 4, 5] , [1, 2, 7, 8, 9] , [1, 7, 9] , [2, 7, 9] , [2, 7, 9] -- Copy-paste typo on the original example , [1, 9] -- Add this to increase the support of [1,9] because the original example is wrong… , [2] ] spec :: Spec spec = do describe "frequentItemSets" do it "computes Takeaki Uno's example" $ -- From https://research.nii.ac.jp/~uno/code/lcm.html#IntroductionstoFrequentItemsetMining letName 3 \(\x -> x / fromRight undefined (prove (x > zero)) -> minSupp) -> -- Alas, this is not a zero-cost `coerce` unName <$> allFrequentItemSets @Int (nameless exampleTakeakiUnoDB) minSupp `shouldBe` [ [] , [1] , [1, 7] , [1, 9] , [2] , [2, 7] , [2, 7, 9] , [2, 9] , [7] , [7, 9] , [9] ] describe "associationRules" do proba75 <- liftIO (probability (75 % 100)) it "computes Takeaki Uno's example" do let db = nameless exampleTakeakiUnoDB let minSupp = let x = nameless 2 in x / fromRight undefined (prove (x > zero)) goldenPrettyShowInstance "tests/Clustering/FrequentItemSet/BruteForce/associationRules/TakeakiUno.golden" [ associationRules fis db (nameless proba75) | fis <- allFrequentItemSets @Int db minSupp ]