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_correction #300

Merged
merged 2 commits into from
Feb 6, 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
80 changes: 48 additions & 32 deletions PAMI/georeferencedFrequentPattern/basic/FSPGrowth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# that satisfy the user-specified minimum support (minSup) and maximum distance (maxDist) constraints
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
# -------------------------------------------------------
#
# from PAMI.georeferencedFrequentPattern.basic import FSPGrowth as alg
#
Expand All @@ -28,6 +28,7 @@
#
# print("Total ExecutionTime in seconds:", run)
#

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

Expand Down Expand Up @@ -55,8 +56,9 @@
class _Node:
"""
A class used to represent the node of frequentPatternTree
Attributes
----------

:Attributes:

item : int
Storing item of a node
count : int
Expand All @@ -77,14 +79,16 @@ def __init__(self, item, count, children):
class _Tree:
"""
A class used to represent the frequentPatternGrowth tree structure
Attributes
----------

:Attributes:

root : Node
The first node of the tree set to Null.
nodeLink : dict
Stores the nodes which shares same item
Methods
-------

:Methods:

createTree(transaction,count)
Adding transaction into the tree
linkNode(node)
Expand All @@ -108,6 +112,7 @@ def __init__(self):
def createTree(self, transaction, count):
"""
Create tree or add transaction into yourself.

:param transaction: list
:param count: int
:return: Tree
Expand All @@ -126,6 +131,7 @@ def createTree(self, transaction, count):
def linkNode(self, node):
"""
Maintain link of node by adding node to nodeLink

:param node: Node
:return:
"""
Expand All @@ -138,6 +144,7 @@ def linkNode(self, node):
def createCPB(self, item, neighbour) :
"""
Create conditional pattern base based on item and neighbour

:param item: int
:param neighbour: dict
:return: Tree
Expand All @@ -153,6 +160,7 @@ def createCPB(self, item, neighbour) :
def mergeTree(self, tree, fpList):
"""
Merge tree into yourself

:param tree: Tree
:param fpList: list
:return: Tree
Expand All @@ -165,8 +173,9 @@ def mergeTree(self, tree, fpList):
def createTransactions(self, fpList):
"""
Create transactions that configure yourself

:param fpList: list
:return: list
:return: transaction list
"""
transactions = []
flist = [x for x in fpList if x in self.nodeLink]
Expand All @@ -185,6 +194,7 @@ def createTransactions(self, fpList):
def getPattern(self, item, suffixItem, minSup, neighbour):
"""
Get frequent patterns based on suffixItem

:param item: int
:param suffixItem: tuple
:param minSup: int
Expand All @@ -208,6 +218,7 @@ def getPattern(self, item, suffixItem, minSup, neighbour):
def mining(self, minSup:collable[int, float], neighbourhood: [Dict[int, List[int]]] = None):
"""
Pattern mining on your own

:param minSup: int
:param neighbourhood: function
:param neighbourhood: dict
Expand All @@ -222,17 +233,14 @@ def mining(self, minSup:collable[int, float], neighbourhood: [Dict[int, List[int

class FSPGrowth(_ab._spatialFrequentPatterns):
"""
Description:
-------------
Given a transactional database and a spatial (or neighborhood) file, FSPM aims to discover all of those patterns
that satisfy the user-specified minimum support (minSup) and maximum distance (maxDist) constraints
Reference:
-----------
Rage, Uday & Fournier Viger, Philippe & Zettsu, Koji & Toyoda, Masashi & Kitsuregawa, Masaru. (2020).
Discovering Frequent Spatial Patterns in Very Large Spatiotemporal Databases.

Attributes:
------------
:Description: Given a transactional database and a spatial (or neighborhood) file, FSPM aims to discover all of those patterns
that satisfy the user-specified minimum support (minSup) and maximum distance (maxDist) constraints

:Reference: Rage, Uday & Fournier Viger, Philippe & Zettsu, Koji & Toyoda, Masashi & Kitsuregawa, Masaru. (2020).
Discovering Frequent Spatial Patterns in Very Large Spatiotemporal Databases.

:Attributes:

iFile : file
Input file name or path of the input file
nFile : file
Expand All @@ -252,8 +260,8 @@ class FSPGrowth(_ab._spatialFrequentPatterns):
memoryRSS : float
To store the total amount of RSS memory consumed by the program

Methods:
--------
:Methods:

startMine()
This function starts pattern mining.
getPatterns()
Expand Down Expand Up @@ -285,17 +293,17 @@ class FSPGrowth(_ab._spatialFrequentPatterns):
getAllFrequentPatterns(data, fpList, ndata)
This function generates all frequent patterns

Executing the code on terminal :
---------------------------------
Format:
**Executing the code on terminal :**
--------------------------------------

Format:
>>> python3 FSPGrowth.py <inputFile> <outputFile> <neighbourFile> <minSup>
Examples:

>>> python3 FSPGrowth.py sampleTDB.txt output.txt sampleN.txt 0.5 (minSup will be considered in percentage of database transactions)
Examples:
>>> python3 FSPGrowth.py sampleTDB.txt output.txt sampleN.txt 0.5

Sample run of importing the code :
-----------------------------------
**Sample run of importing the code :**
----------------------------------------
.. code-block:: python

from PAMI.georeferencedFrequentPattern.basic import FSPGrowth as alg
Expand All @@ -322,8 +330,8 @@ class FSPGrowth(_ab._spatialFrequentPatterns):

print("Total ExecutionTime in seconds:", run)

Credits:
----------
**Credits:**
--------------
The complete program was written by Yudai Masu under the supervision of Professor Rage Uday Kiran.
"""

Expand Down Expand Up @@ -441,6 +449,7 @@ def _sortTransaction(self):
def _convert(self, value):
"""
To convert the given user specified value

:param value: user specified value
:return: converted value
"""
Expand Down Expand Up @@ -479,6 +488,7 @@ def startMine(self):

def getMemoryUSS(self):
"""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
:rtype: float
"""
Expand All @@ -487,6 +497,7 @@ def getMemoryUSS(self):

def getMemoryRSS(self):
"""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
:rtype: float
"""
Expand All @@ -495,6 +506,7 @@ def getMemoryRSS(self):

def getRuntime(self):
"""Calculating the total amount of runtime taken by the mining process

:return: returning total amount of runtime taken by the mining process
:rtype: float
"""
Expand All @@ -503,6 +515,7 @@ def getRuntime(self):

def getPatternsAsDataFrame(self):
"""Storing final frequent patterns in a dataframe

:return: returning frequent patterns in a dataframe
:rtype: pd.DataFrame
"""
Expand All @@ -517,8 +530,9 @@ def getPatternsAsDataFrame(self):
def save(self, oFile):
"""
Complete set of frequent patterns will be loaded in to a output file

:param oFile: name of the output file
:type oFile: file
:type oFile: csv file
"""
self._oFile = oFile
writer = open(self._oFile, 'w+')
Expand All @@ -529,14 +543,16 @@ def save(self, oFile):
def getPatterns(self):
"""
Function to send the set of frequent patterns after completion of the mining process

:return: returning frequent patterns
:rtype: dict
"""

return self._finalPatterns

def printResults(self):
""" This function is used to print the results
"""
This function is used to print the results
"""
print("Total number of Spatial Frequent Patterns:", len(self.getPatterns()))
print("Total Memory in USS:", self.getMemoryUSS())
Expand Down
59 changes: 29 additions & 30 deletions PAMI/georeferencedFrequentPattern/basic/SpatialECLAT.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,15 @@

class SpatialECLAT(_ab._spatialFrequentPatterns):
"""
Description:
--------------
Spatial Eclat is a Extension of ECLAT algorithm,which stands for Equivalence Class Clustering and bottom-up
Lattice Traversal.It is one of the popular methods of Association Rule mining. It is a more efficient and
scalable version of the Apriori algorithm.

Reference:
-----------
Rage, Uday & Fournier Viger, Philippe & Zettsu, Koji & Toyoda, Masashi & Kitsuregawa, Masaru. (2020).
Discovering Frequent Spatial Patterns in Very Large Spatiotemporal Databases.

Attributes :
---------------
:Description: Spatial Eclat is a Extension of ECLAT algorithm,which stands for Equivalence Class Clustering and bottom-up
Lattice Traversal.It is one of the popular methods of Association Rule mining. It is a more efficient and
scalable version of the Apriori algorithm.

:Reference: Rage, Uday & Fournier Viger, Philippe & Zettsu, Koji & Toyoda, Masashi & Kitsuregawa, Masaru. (2020).
Discovering Frequent Spatial Patterns in Very Large Spatiotemporal Databases.

:Attributes:

iFile : str
Input file name or path of the input file
nFile: str
Expand All @@ -91,8 +87,8 @@ class SpatialECLAT(_ab._spatialFrequentPatterns):
Database : list
To store the complete set of transactions available in the input database/file

Methods :
------------
:Methods:

startMine()
Mining process will start from here
getPatterns()
Expand Down Expand Up @@ -124,18 +120,18 @@ class SpatialECLAT(_ab._spatialFrequentPatterns):
mapNeighbours(file):
A function to map items to their neighbours

Executing the code on terminal :
----------------------------------
Format:
**Executing the code on terminal :**
----------------------------------------

Format:
>>> python3 SpatialECLAT.py <inputFile> <outputFile> <neighbourFile> <minSup>

Examples:

>>> python3 SpatialECLAT.py sampleTDB.txt output.txt sampleN.txt 0.5 (minSup will be considered in percentage of database transactions)

Sample run of importing the code :
-----------------------------------


**Sample run of importing the code :**
------------------------------------------
.. code-block:: python

from PAMI.georeferencedFrequentPattern.basic import SpatialECLAT as alg
Expand Down Expand Up @@ -163,8 +159,8 @@ class SpatialECLAT(_ab._spatialFrequentPatterns):
print("Total ExecutionTime in seconds:", run)


Credits:
---------
**Credits:**
----------------
The complete program was written by B.Sai Chitra under the supervision of Professor Rage Uday Kiran.
"""

Expand Down Expand Up @@ -235,6 +231,7 @@ def _frequentOneItem(self):
def _convert(self, value):
"""
To convert the given user specified value

:param value: user specified value
:return: converted value
"""
Expand Down Expand Up @@ -323,11 +320,12 @@ def _generateSpatialFrequentPatterns(self, tidList):

def _getNeighbourItems(self, keySet):
"""
A function to get Neighbours of a item
:param keySet:itemSet
:type keySet:str or tuple
:return: set of common neighbours
:rtype:set
A function to get Neighbours of a item

:param keySet:itemSet
:type keySet:str or tuple
:return: set of common neighbours
:rtype:set
"""
itemNeighbours = self._NeighboursMap.keys()
if isinstance(keySet, str):
Expand All @@ -344,7 +342,8 @@ def _getNeighbourItems(self, keySet):

def _mapNeighbours(self):
"""
A function to map items to their Neighbours

A function to map items to their Neighbours
"""
self._NeighboursMap = {}
if isinstance(self._nFile, _ab._pd.DataFrame):
Expand Down
Loading