changed indent method according to ghc standard
This commit is contained in:
20
DataModel.hs
20
DataModel.hs
@@ -8,31 +8,35 @@ type Frequency = Double
|
||||
type Confidence = Double
|
||||
|
||||
class Freq a where
|
||||
frequency :: [ItemSet] -> a -> Frequency
|
||||
frequency :: [ItemSet] -> a -> Frequency
|
||||
|
||||
data Item = Item String deriving (Eq, Ord)
|
||||
instance Show Item where
|
||||
show (Item s) = s --"Item " ++ s
|
||||
show (Item s) = s --"Item " ++ s
|
||||
|
||||
data ItemSet = ItemSet (Set Item) deriving (Eq, Ord)
|
||||
|
||||
instance Show ItemSet where
|
||||
show (ItemSet x) = foldr ((\y old -> y ++ " " ++ old).show) "" (Set.toList x)
|
||||
show (ItemSet x) =
|
||||
foldr ((\y old -> y ++ " " ++ old).show) "" (Set.toList x)
|
||||
|
||||
instance Freq ItemSet where
|
||||
frequency table (ItemSet set) = setCount / fromIntegral (length table) where
|
||||
setCount = fromIntegral $ count table (ItemSet set)
|
||||
frequency table (ItemSet set) =
|
||||
setCount / fromIntegral (length table) where
|
||||
setCount = fromIntegral $ count table (ItemSet set)
|
||||
|
||||
count :: [ItemSet] -> ItemSet -> Count
|
||||
count table (ItemSet set) = length (filter (\(ItemSet row) -> set `Set.isSubsetOf` row) table)
|
||||
count table (ItemSet set) =
|
||||
length (filter isSuperSet table) where
|
||||
isSuperset (ItemSet row) = set `Set.isSubsetOf` row
|
||||
|
||||
data Rule = Rule ItemSet ItemSet deriving (Eq)
|
||||
|
||||
instance Show Rule where
|
||||
show (Rule a b) = show a ++ "-> " ++ show b
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user