Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sharma53
post_silicon_protocol_lts
Commits
72cec316
Commit
72cec316
authored
Sep 21, 2016
by
Debjit Pal
Browse files
Adding changes to include time of occurence of the events
parent
102e64fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
dpcode/Seq_Patt_Mining/Item.py
View file @
72cec316
...
...
@@ -11,8 +11,8 @@ class Item():
'''
def
__init__
(
self
,
Item
,
Name
,
Time
):
self
.
Item
=
Item
self
.
Name
=
Name
self
.
Time
=
Time
dpcode/Seq_Patt_Mining/ReadData.py
View file @
72cec316
...
...
@@ -6,6 +6,7 @@ Paper: PrefixSpan: Mining Sequential Patterns Efficiently by Prefix-Projected Pa
'''
from
Constraints
import
*
from
Item
import
*
class
ReadData
():
def
__init__
(
...
...
@@ -26,7 +27,10 @@ class ReadData():
elements
=
line
.
lstrip
().
rstrip
().
split
(
','
)
itemSet
=
[]
for
e
in
elements
:
itemSet
.
append
(
e
.
split
())
Items_
=
e
.
split
()
for
Item__
in
Items_
:
splits
=
Item__
.
split
(
'@'
)
itemSet
.
append
(
Item
(
splits
[
0
],
splits
[
1
]))
SDB
[
SID
]
=
itemSet
SID
=
SID
+
1
return
SDB
...
...
dpcode/Seq_Patt_Mining/SDB_Data_1.dat
View file @
72cec316
a
,a b c,a c,d,c f
a
d,c,b c,a e
e
f,a b,d f,c,b
e
,g,a f,c,b,c
a
@1,a@2 b@2 c@2,a@3 c@3,d@4,c@5 f@5
a
@1 d@1,c@2,b@3 c@3,a@4 e@4
e
@1 f@1,a@2 b@2,d@3 f@3,c@4,b@5
e
@1,g@2,a@3 f@3,c@4,b@4,c@5
dpcode/Seq_Patt_Mining/prefix_span.py
View file @
72cec316
...
...
@@ -52,14 +52,15 @@ if __name__ == "__main__":
for
key
in
SDB
.
keys
():
SDB_
.
append
(
SDB
[
key
])
print
SDB_
# Algorithm 1 of Prefix Span Paper. Call PrefixSpan with Empty Sequence
# AllPatterns stores all Sequential Pattern with their support
AllPatterns
=
[]
if
constraints_file
is
not
None
:
AllPatterns
=
PrefixSpan
.
PrefixSpanWithConstraints
(
SeqPattern
([],
sys
.
maxint
),
SDB_
,
min_sup
,
Constraints
)
else
:
AllPatterns
=
PrefixSpan
.
PrefixSpan
(
SeqPattern
([],
sys
.
maxint
),
SDB_
,
min_sup
)
##
AllPatterns = []
##
if constraints_file is not None:
##
AllPatterns = PrefixSpan.PrefixSpanWithConstraints(SeqPattern([], sys.maxint), SDB_, min_sup, Constraints)
##
else:
##
AllPatterns = PrefixSpan.PrefixSpan(SeqPattern([], sys.maxint), SDB_, min_sup)
# Used sorting help from here: https://wiki.python.org/moin/HowTo/Sorting
AllPatternsSorted
=
sorted
(
AllPatterns
,
key
=
lambda
Pattern
:
Pattern
.
Support
,
reverse
=
True
)
for
Pattern_
in
AllPatternsSorted
:
print
ReadData
.
PrintPatternInStringFormat
(
Pattern_
.
Sequence
,
1
)
+
' :: Support : '
+
str
(
Pattern_
.
Support
)
+
' :: Length : '
+
str
(
Pattern_
.
Length
)
##
AllPatternsSorted = sorted(AllPatterns, key=lambda Pattern: Pattern.Support, reverse=True)
##
for Pattern_ in AllPatternsSorted:
##
print ReadData.PrintPatternInStringFormat(Pattern_.Sequence, 1) + ' :: Support : ' + str(Pattern_.Support) + ' :: Length : ' + str(Pattern_.Length)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment