-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMinerMatch.metta
39 lines (32 loc) · 1.44 KB
/
MinerMatch.metta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;; MeTTa port of pattern miner, using match.
;; Given a collection of data trees db, a minimum support ms and an
;; initial collection of patterns Candidate (containing at least the identity
;; pattern), the pattern mining algorithm works as follows
;; 1. Select a pattern P from C
;; 2. Extract the valuation set of P over db, called V
;; 3. Determine the shallow abstractions of V, called A
;; 4. Specialize P by composing it with elements in A
;; 5. Add the resulting specializations with enough support in C,
;; discard the others
;; 6. Repeat till termination
;; Import utils
; !(import! &self ../utils/MinerUtils.metta)
;; Get candidate patterns depth zero
(= (get-candidate Z $linkType $ms)
(let $sp (specialize $linkType)
(support $sp $ms)))
;; Get candidate patterns depth n. (maximum is three)
(= (get-candidate (S $k) $linkType $ms)
(let $comb (, (get-pattern (get-candidate $k $linkType $ms))
(get-pattern (get-candidate Z $linkType $ms)))
(support (flatten $comb) $ms)))
;; Frequent patterns Miner
(= (miner $db $ms $depth)
(superpose ((init-miner $db $ms $highsurp)
(let $link (get-links)
(get-candidate $depth $link $ms)))))
;; Surprising patterns miner
(= (miner-surprising $db $ms $depth $highsurp)
(let* (($cptrn (miner $db $ms $depth))
($isurp (iSurprisingness $cptrn)))
(if (> $isurp $highsurp) (surp (get-pattern $cptrn) $isurp) (superpose ()))))