Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Updated #403

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 70 additions & 98 deletions PAMI/correlatedPattern/basic/CoMine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
#
# from PAMI.correlatedPattern.basic import CoMine as alg
#
# iFile = 'sampleTDB.txt'
#
# minSup = 0.25 # can be specified between 0 and 1
#
# minAllConf = 0.2 # can be specified between 0 and 1
#
# obj = alg.CoMine(iFile, minSup, minAllConf, sep)
#
# obj.mine()
Expand All @@ -32,8 +37,6 @@
#




__copyright__ = """
Copyright (C) 2021 Rage Uday Kiran

Expand Down Expand Up @@ -62,24 +65,15 @@ class _Node:
"""
A class used to represent the node of correlatedPatternTree

:**Attributes**: **itemId** (*int*) -- **storing item of a node**
**counter** (*int*) -- **To maintain the support of node**
**parent** (*node*) -- **To maintain the parent of every node**
**child** (*list*) -- **To maintain the children of node**
**nodeLink** (*node*) -- **Points to the node with same itemId**

:Attributes:

itemId : int
storing item of a node
counter : int
To maintain the support of node
parent : node
To maintain the parent of every node
child : list
To maintain the children of node
nodeLink : node
Points to the node with same itemId

:Methods:

getChild(itemName)
returns the node with same itemName from correlatedPatternTree
:**Methods**:
getChild(itemName)
returns the node with same itemName from correlatedPatternTree
"""

def __init__(self) -> None:
Expand All @@ -101,24 +95,16 @@ def getChild(self, id1) -> Union[None, '_Node']:
return i
return None


class _Tree:
"""
A class used to represent the correlatedPatternGrowth tree structure

:Attributes:

headerList : list
storing the list of items in tree sorted in ascending of their supports
mapItemNodes : dictionary
storing the nodes with same item name
mapItemLastNodes : dictionary
representing the map that indicates the last node for each item
root : Node
representing the root Node in a tree
:**Attributes**: **headerList** (*list*) -- **storing the list of items in tree sorted in ascending of their supports**
**mapItemNodes** (*dictionary*) -- **storing the nodes with same item name**
**mapItemLastNodes** (*dictionary*) -- **representing the map that indicates the last node for each item**
**root** (*Node*) -- **representing the root Node in a tree**


:Methods:
:**Methods**:

createHeaderList(items,minSup)
takes items only which are greater than minSup and sort the items in ascending order
Expand All @@ -142,8 +128,8 @@ def addTransaction(self, transaction: List[int]) -> None:
"""
Adding transaction into tree

:param transaction : it represents a single transaction in a database
:type transaction : list
:param transaction: it represents a single transaction in a database
:type transaction: list
:return: None
"""

Expand All @@ -166,9 +152,9 @@ def fixNodeLinks(self, item: int, newNode: '_Node') -> None:
Fixing node link for the newNode that inserted into correlatedPatternTree

:param item: it represents the item of newNode
:type item : int
:param newNode : it represents the newNode that inserted in correlatedPatternTree
:type newNode : Node
:type item: int
:param newNode: it represents the newNode that inserted in correlatedPatternTree
:type newNode: Node
:return: None
"""
if item in self.mapItemLastNodes.keys():
Expand Down Expand Up @@ -249,51 +235,30 @@ class CoMine(_ab._correlatedPatterns):
About this algorithm
====================

:Description: CoMine is one of the fundamental algorithm to discover correlated patterns in a transactional database. It is based on the traditional FP-Growth algorithm. This algorithm uses depth-first search technique to find all correlated patterns in a transactional database.

:Reference: Lee, Y.K., Kim, W.Y., Cao, D., Han, J. (2003). CoMine: efficient mining of correlated patterns. In ICDM (pp. 581–584).

:param iFile: str :
Name of the Input file to mine complete set of correlated patterns
:param oFile: str :
Name of the output file to store complete set of correlated patterns
:param minSup: int or float or str :
The user can specify minSup either in count or proportion of database size. If the program detects the data type of minSup is integer, then it treats minSup is expressed in count.
:param minAllConf: float :
The user can specify minAllConf values within the range (0, 1).
:param sep: str :
This variable is used to distinguish items from one another in a transaction. The default seperator is tab space. However, the users can override their default separator.

:Attributes:

memoryUSS : float
To store the total amount of USS memory consumed by the program
memoryRSS : float
To store the total amount of RSS memory consumed by the program
startTime:float
To record the start time of the mining process
endTime:float
To record the completion time of the mining process
minSup : int
The user given minSup
minAllConf: float
The user given minimum all confidence Ratio(should be in range of 0 to 1)
Database : list
To store the transactions of a database in list
mapSupport : Dictionary
To maintain the information of item and their frequency
lno : int
it represents the total no of transactions
tree : class
it represents the Tree class
itemSetCount : int
it represents the total no of patterns
finalPatterns : dict
it represents to store the patterns
itemSetBuffer : list
it represents the store the items in mining
maxPatternLength : int
it represents the constraint for pattern length
:**Description**: CoMine is one of the fundamental algorithm to discover correlated patterns in a transactional database. It is based on the traditional FP-Growth algorithm. This algorithm uses depth-first search technique to find all correlated patterns in a transactional database.

:**Reference**: Lee, Y.K., Kim, W.Y., Cao, D., Han, J. (2003). CoMine: efficient mining of correlated patterns. In ICDM (pp. 581–584).

:**parameters**: **iFile** (*str*) -- **Name of the Input file to mine complete set of correlated patterns**
**oFile** (*str*) -- **Name of the output file to store complete set of correlated patterns**
**minSup** (*int or float or str*) -- **The user can specify minSup either in count or proportion of database size. If the program detects the data type of minSup is integer, then it treats minSup is expressed in count.**
**minAllConf** (*float*) -- **The user can specify minAllConf values within the range (0, 1).**
**sep** (*str*) -- **This variable is used to distinguish items from one another in a transaction. The default seperator is tab space. However, the users can override their default separator.**

:**Attributes**: **memoryUSS** (*float*) -- **To store the total amount of USS memory consumed by the program**
**memoryRSS** (*float*) -- **To store the total amount of RSS memory consumed by the program**
**startTime** (*float*) -- **To record the start time of the mining process**
**endTime** (*float*) -- **To record the completion time of the mining process**
**minSup** (*int*) -- **The user given minSup**
**minAllConf** (*float*) -- **The user given minimum all confidence Ratio(should be in range of 0 to 1)**
**Database** (*list*) -- **To store the transactions of a database in list**
**mapSupport** (*Dictionary*) -- **To maintain the information of item and their frequency**
**lno** (*int*) -- **it represents the total no of transactions**
**tree** (*class*) -- **it represents the Tree class**
**itemSetCount** (*int*) -- **it represents the total no of patterns**
**finalPatterns** (*dict*) -- **it represents to store the patterns**
**itemSetBuffer** (*list*) -- **it represents the store the items in mining**
**maxPatternLength** (*int*) -- **it represents the constraint for pattern length**

Execution methods
=================
Expand All @@ -318,6 +283,12 @@ class CoMine(_ab._correlatedPatterns):

from PAMI.correlatedPattern.basic import CoMine as alg

iFile = 'sampleTDB.txt'

minSup = 0.25 # can be specified between 0 and 1

minAllConf = 0.2 # can be specified between 0 and 1

obj = alg.CoMine(iFile, minSup, minAllConf,sep)

obj.mine()
Expand Down Expand Up @@ -420,10 +391,10 @@ def _getRatio(self, prefix: List[int], prefixLength: int, s: int) -> float:
:type prefix: list
:param prefixLength: length
:type prefixLength:int
:s :current ratio
:param s:current ratio
:type s:float
:return: minAllConf of prefix
:rtype:float
:rtype: float
"""
maximums = 0
for ele in range(prefixLength):
Expand Down Expand Up @@ -472,6 +443,7 @@ def _convert(self, value: Union[int, float, str]) -> None:
To convert the type of user specified minSup value

:param value: user specified minSup value
:type value: int or float or str
:return: None
"""
if type(value) is int:
Expand All @@ -492,13 +464,13 @@ def _saveAllCombinations(self, tempBuffer, s, position, prefix, prefixLength) ->

:param tempBuffer: items in a single branch
:type tempBuffer: list
:param s : support at leaf node of a branch
:param position : the length of a tempBuffer
:type position : int
:param prefix : it represents the list of leaf node
:type prefix : list
:param prefixLength : the length of prefix
:type prefixLength :int
:param s: support at leaf node of a branch
:param position: the length of a tempBuffer
:type position: int
:param prefix: it represents the list of leaf node
:type prefix: list
:param prefixLength: the length of prefix
:type prefixLength: int
:return: None
"""
max1 = 1 << position
Expand All @@ -517,12 +489,12 @@ def _correlatedPatternGrowthGenerate(self, correlatedPatternTree, prefix, prefix

:param correlatedPatternTree: it represents the correlatedPatternTree
:type correlatedPatternTree: class Tree
:param prefix : it represents an empty list and store the patterns that are mined
:type prefix : list
:param prefixLength : the length of prefix
:type prefixLength :int
:param mapSupport : it represents the support of item
:type mapSupport : dictionary
:param prefix: it represents an empty list and store the patterns that are mined
:type prefix: list
:param prefixLength: the length of prefix
:type prefixLength: int
:param mapSupport: it represents the support of item
:type mapSupport: dictionary
:return: None
"""

Expand Down
Loading