Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created January 20, 2019 19:43
Show Gist options
  • Save rayfix/38fd6564e5e7b84b87b24bd4d75b1566 to your computer and use it in GitHub Desktop.
Save rayfix/38fd6564e5e7b84b87b24bd4d75b1566 to your computer and use it in GitHub Desktop.
ECLAT Frequent Pattern Matching in Swift
var accumulatedItemSets = Dictionary(uniqueKeysWithValues: database.map {
(Set([$0.key]), Set($0.value)) })
var itemSetsToEvaluate = accumulatedItemSets
while !itemSetsToEvaluate.isEmpty {
var temp: [Set<String>: Set<Int>] = [:]
itemSetsToEvaluate.pairs().forEach { a, b in
let key = a.key.union(b.key)
let value = a.value.intersection(b.value)
if value.count >= absoluteSupport {
temp[key] = value
}
}
accumulatedItemSets.merge(temp) { $1 }
itemSetsToEvaluate = temp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment