8
8
# **Importing this algorithm into a python program**
9
9
# --------------------------------------------------------
10
10
#
11
- # from PAMI.localPeriodicPattern.basic import LPPGrowth as alg
11
+ # from PAMI.localPeriodicPattern.basic import LPPGrowth as alg
12
12
#
13
- # obj = alg.LPPGrowth(iFile, maxPer, maxSoPer, minDur)
13
+ # obj = alg.LPPGrowth(iFile, maxPer, maxSoPer, minDur)
14
14
#
15
- # obj.startMine ()
15
+ # obj.mine ()
16
16
#
17
- # localPeriodicPatterns = obj.getPatterns()
17
+ # localPeriodicPatterns = obj.getPatterns()
18
18
#
19
- # print(f'Total number of local periodic patterns: {len(localPeriodicPatterns)}')
19
+ # print(f'Total number of local periodic patterns: {len(localPeriodicPatterns)}')
20
20
#
21
- # obj.save(oFile)
21
+ # obj.save(oFile)
22
22
#
23
- # Df = obj.getPatternsAsDataFrame()
23
+ # Df = obj.getPatternsAsDataFrame()
24
24
#
25
- # memUSS = obj.getMemoryUSS()
25
+ # memUSS = obj.getMemoryUSS()
26
26
#
27
- # print(f'Total memory in USS: {memUSS}')
27
+ # print(f'Total memory in USS: {memUSS}')
28
28
#
29
- # memRSS = obj.getMemoryRSS()
29
+ # memRSS = obj.getMemoryRSS()
30
30
#
31
- # print(f'Total memory in RSS: {memRSS}')
31
+ # print(f'Total memory in RSS: {memRSS}')
32
32
#
33
- # runtime = obj.getRuntime()
34
- #
35
- # print(f'Total execution time in seconds: {runtime})
33
+ # runtime = obj.getRuntime()
36
34
#
35
+ # print(f'Total execution time in seconds: {runtime})
37
36
#
38
37
39
38
39
+
40
+
41
+
40
42
__copyright__ = """
41
- Copyright (C) 2021 Rage Uday Kiran
43
+ Copyright (C) 2021 Rage Uday Kiran
42
44
43
45
This program is free software: you can redistribute it and/or modify
44
46
it under the terms of the GNU General Public License as published by
60
62
61
63
from PAMI .localPeriodicPattern .basic import abstract as _ab
62
64
from typing import List , Dict , Tuple , Set , Union , Any , Generator
65
+ from deprecated import deprecated
63
66
64
67
class Node :
65
68
"""
@@ -94,8 +97,14 @@ def __init__(self) -> None:
94
97
def getChild (self , item : int ) -> 'Node' :
95
98
"""
96
99
This function is used to get child node from the parent node
97
- :param item:
100
+
101
+ :param item: item of the parent node
102
+
103
+ :type item: int
104
+
98
105
:return: if node have node of item, then return it. if node don't have return []
106
+
107
+ :rtype: Node
99
108
"""
100
109
for child in self .child :
101
110
if child .item == item :
@@ -141,6 +150,7 @@ def addTransaction(self, transaction: List[int], tid: int) -> None:
141
150
:type transaction: list
142
151
:param tid: represents the timestamp of transaction
143
152
:type tid: list or int
153
+ :return: None
144
154
"""
145
155
current = self .root
146
156
for item in transaction :
@@ -164,6 +174,7 @@ def fixNodeLinks(self, item: int, newNode: 'Node') -> None:
164
174
:type item: string
165
175
:param newNode: it represents node which is added
166
176
:type newNode: Node
177
+ :return: None
167
178
"""
168
179
if item in self .nodeLinks :
169
180
lastNode = self .nodeLinks [item ]
@@ -178,6 +189,7 @@ def deleteNode(self, item: int) -> None:
178
189
179
190
:param item: it represents the item name of node
180
191
:type item: str
192
+ :return: None
181
193
"""
182
194
deleteNode = self .firstNodeLink [item ]
183
195
parentNode = deleteNode .parent
@@ -203,6 +215,7 @@ def createPrefixTree(self, path: List[int], tidList: List[int]) -> None:
203
215
:type path: list
204
216
:param tidList: it represents tid of each item
205
217
:type tidList: list
218
+ :return: None
206
219
"""
207
220
currentNode = self .root
208
221
for item in path :
@@ -235,9 +248,9 @@ class LPPGrowth(_ab._localPeriodicPatterns):
235
248
a Discrete Sequence. Information Sciences, Elsevier, to appear. [ppt] DOI: 10.1016/j.ins.2020.09.044
236
249
237
250
:param iFile: str :
238
- Name of the Input file to mine complete set of frequent pattern's
251
+ Name of the Input file to mine complete set of local periodic pattern's
239
252
:param oFile: str :
240
- Name of the output file to store complete set of frequent patterns
253
+ Name of the output file to store complete set of local periodic patterns
241
254
:param minDur: str:
242
255
Minimal duration in seconds between consecutive periods of time-intervals where a pattern is continuously periodic.
243
256
:param maxPer: float:
@@ -299,7 +312,7 @@ class LPPGrowth(_ab._localPeriodicPatterns):
299
312
Calculate PTL from input tsList as integer list.
300
313
calculatePTLbit(tsList)
301
314
Calculate PTL from input tsList as bit vector.
302
- startMine ()
315
+ mine ()
303
316
Mining process will start from here.
304
317
getMemoryUSS()
305
318
Total amount of USS memory consumed by the mining process will be retrieved from this function.
@@ -315,12 +328,19 @@ class LPPGrowth(_ab._localPeriodicPatterns):
315
328
Complete set of local periodic patterns will be loaded in to a dataframe.
316
329
317
330
**Executing the code on terminal:**
318
- -------------------------------------
319
- Format:
320
- >>> python3 LPPMGrowth.py <inputFile> <outputFile> <maxPer> <minSoPer> <minDur>
331
+ ---------------------------------------
332
+
333
+ .. code-block:: console
334
+
335
+ Format:
321
336
322
- Examples:
323
- >>> python3 LPPMGrowth.py sampleDB.txt patterns.txt 0.3 0.4 0.5
337
+ (.venv) $ python3 LPPMGrowth.py <inputFile> <outputFile> <maxPer> <minSoPer> <minDur>
338
+
339
+ Example Usage:
340
+
341
+ (.venv) $ python3 LPPMGrowth.py sampleDB.txt patterns.txt 0.3 0.4 0.5
342
+
343
+ .. note: minDur will be considered as time interval between two consecutive periods
324
344
325
345
326
346
**Sample run of importing the code:**
@@ -331,7 +351,7 @@ class LPPGrowth(_ab._localPeriodicPatterns):
331
351
332
352
obj = alg.LPPGrowth(iFile, maxPer, maxSoPer, minDur)
333
353
334
- obj.startMine ()
354
+ obj.mine ()
335
355
336
356
localPeriodicPatterns = obj.getPatterns()
337
357
@@ -585,6 +605,7 @@ def __patternGrowth(self, tree: 'Tree', prefix: List[int], prefixPFList: Dict[An
585
605
:type prefix: list
586
606
:param prefixPFList: tsList of prefix patterns.
587
607
:type prefixPFList: dict or list
608
+ :return: None
588
609
"""
589
610
items = list (prefixPFList )
590
611
if not prefix :
@@ -641,6 +662,7 @@ def __calculatePTL(self, tsList: List[int]) -> set:
641
662
:param tsList: It is tsList which store time stamp as integer.
642
663
:type tsList: list
643
664
:return: PTL
665
+ :rtype: set
644
666
"""
645
667
start = - 1
646
668
PTL = set ()
@@ -674,6 +696,7 @@ def __calculatePTLbit(self, tsList: List[int]) -> set:
674
696
:param tsList: It is tsList which store time stamp as bit vector.
675
697
:type tsList: list
676
698
:return: PTL
699
+ :rtype: set
677
700
"""
678
701
tsList = list (bin (tsList ))
679
702
tsList = tsList [2 :]
@@ -720,7 +743,9 @@ def __convert(self, value: Any) -> float:
720
743
to convert the type of user specified minSup value
721
744
722
745
:param value: user specified minSup value
746
+ :type value: int or float or str
723
747
:return: converted type
748
+ :rtype: float
724
749
"""
725
750
if type (value ) is int :
726
751
value = int (value )
@@ -734,6 +759,7 @@ def __convert(self, value: Any) -> float:
734
759
value = int (value )
735
760
return value
736
761
762
+ @deprecated ("It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated." )
737
763
def startMine (self ) -> None :
738
764
"""
739
765
Mining process start from here.
@@ -755,8 +781,30 @@ def startMine(self) -> None:
755
781
self ._localPeriodicPatterns__memoryUSS = process .memory_full_info ().uss
756
782
self ._localPeriodicPatterns__memoryRSS = process .memory_info ().rss
757
783
784
+ def mine (self ) -> None :
785
+ """
786
+ Mining process start from here.
787
+ """
788
+ self ._localPeriodicPatterns__startTime = _ab ._time .time ()
789
+ self ._localPeriodicPatterns__finalPatterns = {}
790
+ self .__creatingItemSets ()
791
+ self ._localPeriodicPatterns__maxPer = self .__convert (self ._localPeriodicPatterns__maxPer )
792
+ self ._localPeriodicPatterns__maxSoPer = self .__convert (self ._localPeriodicPatterns__maxSoPer )
793
+ self ._localPeriodicPatterns__minDur = self .__convert (self ._localPeriodicPatterns__minDur )
794
+ self .__createTSList ()
795
+ self .__generateLPP ()
796
+ self .__createLPPTree ()
797
+ self .__patternGrowth (self .__root , [], self .__items )
798
+ self ._localPeriodicPatterns__endTime = _ab ._time .time ()
799
+ process = _ab ._psutil .Process (_ab ._os .getpid ())
800
+ self ._localPeriodicPatterns__memoryUSS = float ()
801
+ self ._localPeriodicPatterns__memoryRSS = float ()
802
+ self ._localPeriodicPatterns__memoryUSS = process .memory_full_info ().uss
803
+ self ._localPeriodicPatterns__memoryRSS = process .memory_info ().rss
804
+
758
805
def getMemoryUSS (self ) -> float :
759
- """Total amount of USS memory consumed by the mining process will be retrieved from this function
806
+ """
807
+ Total amount of USS memory consumed by the mining process will be retrieved from this function
760
808
761
809
:return: returning USS memory consumed by the mining process
762
810
:rtype: float
@@ -765,7 +813,8 @@ def getMemoryUSS(self) -> float:
765
813
return self ._localPeriodicPatterns__memoryUSS
766
814
767
815
def getMemoryRSS (self ) -> float :
768
- """Total amount of RSS memory consumed by the mining process will be retrieved from this function
816
+ """
817
+ Total amount of RSS memory consumed by the mining process will be retrieved from this function
769
818
770
819
:return: returning RSS memory consumed by the mining process
771
820
:rtype: float
@@ -774,7 +823,8 @@ def getMemoryRSS(self) -> float:
774
823
return self ._localPeriodicPatterns__memoryRSS
775
824
776
825
def getRuntime (self ) -> float :
777
- """Calculating the total amount of runtime taken by the mining process
826
+ """
827
+ Calculating the total amount of runtime taken by the mining process
778
828
779
829
:return: returning total amount of runtime taken by the mining process
780
830
:rtype: float
@@ -783,7 +833,8 @@ def getRuntime(self) -> float:
783
833
return self ._localPeriodicPatterns__endTime - self ._localPeriodicPatterns__startTime
784
834
785
835
def getPatternsAsDataFrame (self ) -> '_ab._pd.DataFrame' :
786
- """Storing final local periodic patterns in a dataframe
836
+ """
837
+ Storing final local periodic patterns in a dataframe
787
838
788
839
:return: returning local periodic patterns in a dataframe
789
840
:rtype: pd.DataFrame
@@ -805,6 +856,7 @@ def save(self, outFile: str) -> None:
805
856
806
857
:param outFile: name of the output file
807
858
:type outFile: csv file
859
+ :return: None
808
860
"""
809
861
self ._localPeriodicPatterns__oFile = outFile
810
862
writer = open (self ._localPeriodicPatterns__oFile , 'w+' )
@@ -819,7 +871,8 @@ def save(self, outFile: str) -> None:
819
871
writer .write ("%s \n " % patternsAndPTL )
820
872
821
873
def getPatterns (self ) -> Dict :
822
- """ Function to send the set of local periodic patterns after completion of the mining process
874
+ """
875
+ Function to send the set of local periodic patterns after completion of the mining process
823
876
824
877
:return: returning frequent patterns
825
878
:rtype: dict
@@ -844,6 +897,7 @@ def printResults(self) -> None:
844
897
if len (_ab ._sys .argv ) == 5 :
845
898
_ap = LPPGrowth (_ab ._sys .argv [1 ], _ab ._sys .argv [3 ], float (_ab ._sys .argv [4 ]))
846
899
_ap .startMine ()
900
+ _ap .mine ()
847
901
print ("Total number of Local Periodic Patterns:" , len (_ap .getPatterns ()))
848
902
_ap .save (_ab ._sys .argv [2 ])
849
903
print ("Total Memory in USS:" , _ap .getMemoryUSS ())
0 commit comments