implemented phase 2

This commit is contained in:
IGI-111
2015-04-05 17:55:16 +02:00
parent 32309510a8
commit c108e32c89
5 changed files with 83 additions and 17 deletions

View File

@@ -11,8 +11,9 @@ class Freq a where
frequency :: [ItemSet] -> a -> Frequency
data Item = Item String deriving (Eq, Ord)
instance Show Item where
show (Item s) = s --"Item " ++ s
show (Item a) = show a
data ItemSet = ItemSet (Set Item) deriving (Eq, Ord)
@@ -27,16 +28,23 @@ instance Freq ItemSet where
count :: [ItemSet] -> ItemSet -> Count
count table (ItemSet set) =
length (filter isSuperSet table) where
length (filter isSuperset table) where
isSuperset (ItemSet row) = set `Set.isSubsetOf` row
difference :: ItemSet -> ItemSet -> ItemSet
difference (ItemSet set1) (ItemSet set2) = ItemSet (Set.difference set1 set2)
empty :: ItemSet
empty = ItemSet (Set.fromList [])
data Rule = Rule ItemSet ItemSet deriving (Eq)
instance Show Rule where
show (Rule a b) = show a ++ "-> " ++ show b
instance Freq Rule where
frequency table (Rule (ItemSet set1) (ItemSet set2)) = frequency table $ ItemSet (set1 `Set.union` set2)
frequency table (Rule (ItemSet set1) (ItemSet set2)) = frequency table $
ItemSet (set1 `Set.union` set2)
confidence :: [ItemSet] -> Rule -> Confidence
confidence table (Rule x y) = frequency table (Rule x y) / frequency table x