Skip to content

Commit

Permalink
Update CFPGrowth.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Avvari1830S authored Sep 6, 2023
1 parent ba97da7 commit d7e3f19
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions PAMI/multipleMinimumSupportBasedFrequentPattern/basic/CFPGrowth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@


from PAMI.multipleMinimumSupportBasedFrequentPattern.basic import abstract as _fp
from typing import List, Dict, Tuple, Set, Union, Any, Generator
import pandas as pd

_fp._sys.setrecursionlimit(20000)
_MIS = {}
Expand Down Expand Up @@ -79,13 +81,13 @@ class _Node:
"""

def __init__(self, item, children):
def __init__(self, item: int, children: list) -> None:
self.itemId = item
self.counter = 1
self.parent = None
self.children = children

def addChild(self, node):
def addChild(self, node) -> None:
"""
Retrieving the child from the tree
Expand Down Expand Up @@ -123,12 +125,12 @@ class _Tree:
generating the patterns from fp-tree
"""

def __init__(self):
def __init__(self) -> None:
self.root = _Node(None, {})
self.summaries = {}
self.info = {}

def addTransaction(self, transaction, count):
def addTransaction(self, transaction, count) -> None:
"""adding transaction into tree
:param transaction: it represents the one transaction in database
Expand Down Expand Up @@ -156,7 +158,7 @@ def addTransaction(self, transaction, count):
currentNode = currentNode.children[transaction[i]]
currentNode.freq += count

def getFinalConditionalPatterns(self, alpha):
def getFinalConditionalPatterns(self, alpha) -> Tuple[List[List[int]], List[int], Dict[int, int]]:
"""
generates the conditional patterns for a node
Expand Down Expand Up @@ -185,7 +187,7 @@ def getFinalConditionalPatterns(self, alpha):
return finalPatterns, finalFreq, info

@staticmethod
def getConditionalTransactions(ConditionalPatterns, conditionalFreq):
def getConditionalTransactions(ConditionalPatterns, conditionalFreq) -> Tuple[List[List[int]], List[int], Dict[int, int]]:
"""
To calculate the frequency of items in conditional patterns and sorting the patterns
Parameters
Expand Down Expand Up @@ -219,7 +221,7 @@ def getConditionalTransactions(ConditionalPatterns, conditionalFreq):
count += 1
return pat, freq, up_dict

def generatePatterns(self, prefix):
def generatePatterns(self, prefix) -> Generator[Tuple[List[int], int], None, None]:
"""
To generate the frequent patterns
Parameters
Expand Down Expand Up @@ -381,10 +383,10 @@ class CFPGrowth(_fp._frequentPatterns):
__rank = {}
__rankDup = {}

def __init__(self, iFile, MIS, sep='\t'):
def __init__(self, iFile, MIS, sep='\t') -> None:
super().__init__(iFile, MIS, sep)

def __creatingItemSets(self):
def __creatingItemSets(self) -> None:
"""
Storing the complete transactions of the database/input file in a database variable
Expand Down Expand Up @@ -421,7 +423,7 @@ def __creatingItemSets(self):
print("File Not Found")
quit()

def _getMISValues(self):
def _getMISValues(self) -> None:
"""
Storing the Minimum supports given by the user for each item in the database
Expand Down Expand Up @@ -462,7 +464,7 @@ def _getMISValues(self):
print("File Not Found")
quit()

def __convert(self, value):
def __convert(self, value) -> float:
"""
to convert the type of user specified minSup value
Expand All @@ -482,7 +484,7 @@ def __convert(self, value):
value = int(value)
return value

def __frequentOneItem(self):
def __frequentOneItem(self) -> List[str]:
"""
Generating One frequent items sets
Expand All @@ -503,7 +505,7 @@ def __frequentOneItem(self):
self.__rank = dict([(index, item) for (item, index) in enumerate(genList)])
return genList

def __updateTransactions(self, itemSet):
def __updateTransactions(self, itemSet) -> List[List[int]]:
"""
Updates the items in transactions with rank of items according to their support
Expand All @@ -529,7 +531,7 @@ def __updateTransactions(self, itemSet):
return list1

@staticmethod
def __buildTree(transactions, info):
def __buildTree(transactions, info) -> _Tree:
"""
Builds the tree with updated transactions
Parameters:
Expand All @@ -548,7 +550,7 @@ def __buildTree(transactions, info):
rootNode.addTransaction(transactions[i], 1)
return rootNode

def __savePeriodic(self, itemSet):
def __savePeriodic(self, itemSet) -> str:
"""
The duplication items and their ranks
Parameters:
Expand All @@ -565,7 +567,7 @@ def __savePeriodic(self, itemSet):
temp = temp + self.__rankDup[i] + "\t"
return temp

def startMine(self):
def startMine(self) -> None:
"""
main program to start the operation
Expand Down Expand Up @@ -597,7 +599,7 @@ def startMine(self):
self.__memoryUSS = process.memory_full_info().uss
self.__memoryRSS = process.memory_info().rss

def getMemoryUSS(self):
def getMemoryUSS(self) -> float:
"""Total amount of USS memory consumed by the mining process will be retrieved from this function
:return: returning USS memory consumed by the mining process
Expand All @@ -607,7 +609,7 @@ def getMemoryUSS(self):

return self.__memoryUSS

def getMemoryRSS(self):
def getMemoryRSS(self) -> float:
"""Total amount of RSS memory consumed by the mining process will be retrieved from this function
:return: returning RSS memory consumed by the mining process
Expand All @@ -617,7 +619,7 @@ def getMemoryRSS(self):

return self.__memoryRSS

def getRuntime(self):
def getRuntime(self) -> float:
"""Calculating the total amount of runtime taken by the mining process
Expand All @@ -628,7 +630,7 @@ def getRuntime(self):

return self.__endTime - self.__startTime

def getPatternsAsDataFrame(self):
def getPatternsAsDataFrame(self) -> pd.DataFrame:
"""Storing final frequent patterns in a dataframe
:return: returning frequent patterns in a dataframe
Expand All @@ -643,7 +645,7 @@ def getPatternsAsDataFrame(self):
dataframe = _fp._pd.DataFrame(data, columns=['Patterns', 'Support'])
return dataframe

def save(self, outFile):
def save(self, outFile: str) -> None:
"""Complete set of frequent patterns will be loaded in to an output file
:param outFile: name of the output file
Expand All @@ -656,7 +658,7 @@ def save(self, outFile):
s1 = x.strip() + ":" + str(y)
writer.write("%s \n" % s1)

def getPatterns(self):
def getPatterns(self) -> Dict[str, int]:
""" Function to send the set of frequent patterns after completion of the mining process
:return: returning frequent patterns
Expand All @@ -665,7 +667,7 @@ def getPatterns(self):
"""
return self.__finalPatterns

def printResults(self):
def printResults(self) -> None:
""" this function is used to print the results
"""
print("Total number of Frequent Patterns:", len(self.getPatterns()))
Expand Down

0 comments on commit d7e3f19

Please sign in to comment.