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 #381

Merged
merged 5 commits into from
Apr 23, 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
110 changes: 88 additions & 22 deletions PAMI/uncertainFaultTolerantFrequentPattern/VBFTMine.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# VBFTMine is one of the fundamental algorithm to discover fault-tolerant frequent patterns in an uncertain transactional database based on bitset representation.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
#
# import PAMI.uncertainFaultTolerantFrequentPattern.basic.VBFTMine as alg
#
# iFile = 'sampleDB.txt'
#
# minSup = 10 # can also be specified between 0 and 1
#
# itemSup = 2 # can also be specified between 0 and 1
#
# minLength = 3 # can also be specified between 0 and 1
#
# faultTolerance = 2 # can also be specified between 0 and 1
#
# obj = alg.VBFTMine(iFile, minSup, itemSup, minLength, faultTolerance)
#
# obj.startMine()
# obj.mine()
#
# faultTolerantFrequentPattern = obj.getPatterns()
#
Expand Down Expand Up @@ -56,24 +64,26 @@

class VBFTMine(_ab._faultTolerantFrequentPatterns):
"""
About this algorithm
====================

:Description: VBFTMine is one of the fundamental algorithm to discover fault tolerant frequent patterns in an uncertain transactional database based on
bitset representation.
This program employs apriori property (or downward closure property) to reduce the search space effectively.

:Reference: Koh, JL., Yo, PW. (2005). An Efficient Approach for Mining Fault-Tolerant Frequent Patterns Based on Bit Vector Representations.
In: Zhou, L., Ooi, B.C., Meng, X. (eds) Database Systems for Advanced Applications. DASFAA 2005. Lecture Notes in Computer Science,
In: Zhou, L., Ooi, B.C., Meng, X. (eds) Database Systems for Advanced Applications. DASFAA 2005. Lecture Notes in Computer Science,
vol 3453. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11408079_51

:param iFile: str :
Name of the Input file to mine complete set of uncertain Fault Tolerant FrequentFrequent Patterns
:param oFile: str :
Name of the output file to store complete set of uncertain Fault Tolerant FrequentFrequent Patterns
:param minSup: float or int 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.
Otherwise, it will be treated as float.
Example: minSup=10 will be treated as integer, while minSup=10.0 will be treated as float
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.
Otherwise, it will be treated as float.
Example: minSup=10 will be treated as integer, while minSup=10.0 will be treated as float
:param itemSup: int or float :
Frequency of an item
:param minLength: int
Expand Down Expand Up @@ -104,11 +114,14 @@ class VBFTMine(_ab._faultTolerantFrequentPatterns):
To store the transactions of a database in list


**Executing the code on terminal**:
------------------------------------
.. code-block:: console
Execution methods
=================

**Terminal command**


.. code-block:: console

Format:

(.venv) $ python3 VBFTMine.py <inputFile> <outputFile> <minSup> <itemSup> <minLength> <faultTolerance>
Expand All @@ -117,19 +130,28 @@ class VBFTMine(_ab._faultTolerantFrequentPatterns):

(.venv) $ python3 VBFTMine.py sampleDB.txt patterns.txt 10.0 3.0 3 1

.. note:: minSup will be considered in times of minSup and count of database transactions

.. note:: minSup will be considered in times of minSup and count of database transactions

**Calling from a python program**

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

import PAMI.faultTolerantFrequentPattern.basic.VBFTMine as alg

iFile = 'sampleDB.txt'

minSup = 10 # can also be specified between 0 and 1

itemSup = 2 # can also be specified between 0 and 1

minLength = 3 # can also be specified between 0 and 1

faultTolerance = 2 # can also be specified between 0 and 1

obj = alg.VBFTMine(iFile, minSup, itemSup, minLength, faultTolerance)

obj.startMine()
obj.mine()

faultTolerantFrequentPattern = obj.getPatterns()

Expand All @@ -139,15 +161,22 @@ class VBFTMine(_ab._faultTolerantFrequentPatterns):

Df = obj.getPatternInDataFrame()

print("Total Memory in USS:", obj.getMemoryUSS())
memUSS = obj.getMemoryUSS()

print("Total Memory in USS:", memUSS)

print("Total Memory in RSS", obj.getMemoryRSS())
memRSS = obj.getMemoryRSS()

print("Total ExecutionTime in seconds:", obj.getRuntime())
print("Total Memory in RSS", memRSS)

**Credits**:
------------
The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran.
run = obj.getRuntime()

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

Credits
=======

The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran.

"""

Expand Down Expand Up @@ -226,13 +255,32 @@ def _convert(self, value):
return value

def _Count(self, tids):
"""
Count the occurrences of 1s in the given list of transaction IDs.

:param tids: List of transaction IDs.
:type tids: List[int]
:return: Count of occurrences of 1s in the list.
:rtype: int
"""
count = 0
for i in tids:
if i == 1:
count += 1
return count

def _save(self, prefix, suffix, tidsetx):
"""
Save the pattern with its support count if it meets the fault tolerance criteria.

:param prefix: Prefix part of the pattern.
:type prefix: list
:param suffix: Suffix part of the pattern.
:type suffix: list
:param tidsetx: Transaction IDs associated with the pattern.
:type tidsetx: list
:return: None
"""
if (prefix == None):
prefix = suffix
else:
Expand All @@ -244,6 +292,17 @@ def _save(self, prefix, suffix, tidsetx):
self._finalPatterns[tuple(prefix)] = val

def _processEquivalenceClass(self, prefix, itemsets, tidsets):
"""
Process the equivalence class to generate frequent patterns.

:param prefix: Prefix part of the pattern.
:type prefix: list.
:param itemsets: List of itemsets in the equivalence class.
:type itemsets: list.
:param tidsets: List of transaction IDs associated with each itemset.
:type tidsets: list
:return: None
"""
if (len(itemsets) == 1):
i = itemsets[0]
tidi = tidsets[0]
Expand Down Expand Up @@ -291,7 +350,8 @@ def _oneLengthFrequentItems(self):
items.append(x)
return Vector, items

@deprecated("It is recommended to use mine() instead of startMine() for mining process")
@deprecated(
"It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.")
def startMine(self):
"""
Frequent pattern mining process will start from here
Expand Down Expand Up @@ -337,6 +397,7 @@ def mine(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
Expand All @@ -347,6 +408,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
Expand All @@ -357,6 +419,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
Expand All @@ -367,6 +430,7 @@ def getRuntime(self):

def getPatternsAsDataFrame(self):
"""

Storing final frequent patterns in a dataframe

:return: returning frequent patterns in a dataframe
Expand All @@ -386,6 +450,7 @@ def getPatternsAsDataFrame(self):

def save(self, outFile):
"""

Complete set of frequent patterns will be loaded in to an output file

:param outFile: name of the output file
Expand All @@ -402,6 +467,7 @@ def save(self, outFile):

def getPatterns(self):
"""

Function to send the set of frequent patterns after completion of the mining process

:return: returning frequent patterns
Expand Down
Loading