From 5ce244798657500847b4cc228703b9c131c06af3 Mon Sep 17 00:00:00 2001 From: Charan Teja Date: Thu, 4 Apr 2024 23:59:42 +0530 Subject: [PATCH] edits in extras --- PAMI/extras/DF2DB/DF2DB.py | 9 ++- PAMI/extras/DF2DB/DF2DBPlus.py | 10 ++- PAMI/extras/DF2DB/DenseFormatDF.py | 74 ++++++++++++------- PAMI/extras/DF2DB/SparseFormatDF.py | 12 ++- PAMI/extras/DF2DB/createTDB.py | 4 +- PAMI/extras/DF2DB/denseDF2DBPlus.py | 12 ++- PAMI/extras/DF2DB/denseDF2DB_dump.py | 29 +++++--- PAMI/extras/DF2DB/sparseDF2DBPlus.py | 11 ++- PAMI/extras/dbStats/SequentialDatabase.py | 42 ++++++----- PAMI/extras/dbStats/UtilityDatabase.py | 3 +- .../fuzzyTransformation/temporalToFuzzy.py | 8 +- .../transactionalToFuzzy.py | 6 +- .../fuzzyTransformation/utilityToFuzzy.py | 6 +- .../generateSpatioTemporalDatabase.py | 5 +- .../generateTemporalDatabase.py | 37 +++++++--- .../generateTransactionalDatabase.py | 70 +++++++++++------- PAMI/extras/graph/DF2Fig.py | 19 ++++- PAMI/extras/graph/DF2Tex.py | 6 +- .../graph/plotLineGraphFromDictionary.py | 6 +- .../graph/plotLineGraphsFromDataFrame.py | 7 +- PAMI/extras/graph/visualizeFuzzyPatterns.py | 20 +++-- PAMI/extras/graph/visualizePatterns.py | 44 ++++++----- .../imageProcessing/imagery2Databases.py | 7 +- PAMI/extras/messaging/gmail.py | 2 +- ...hborsUsingEuclideanDistanceforPointInfo.py | 7 +- .../findNeighboursUsingEuclidean.py | 6 +- .../neighbours/findNeighboursUsingGeodesic.py | 6 +- PAMI/extras/stats/TransactionalDatabase.py | 22 +++++- PAMI/extras/stats/sequentialDatabase.py | 69 ++++++++++++----- PAMI/extras/stats/temporalDatabase.py | 29 +++++++- PAMI/extras/stats/utilityDatabase.py | 36 +++++++-- 31 files changed, 441 insertions(+), 183 deletions(-) diff --git a/PAMI/extras/DF2DB/DF2DB.py b/PAMI/extras/DF2DB/DF2DB.py index ef43d0b3..930b8725 100644 --- a/PAMI/extras/DF2DB/DF2DB.py +++ b/PAMI/extras/DF2DB/DF2DB.py @@ -16,8 +16,10 @@ # + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,7 +68,7 @@ class DF2DB: obj.getTemporal("outputFileName") # To create temporal database obj.getUtility("outputFileName") # To create utility database - """ + """ def __init__(self, inputDF, thresholdValue, condition, DFtype='sparse') -> None: @@ -87,6 +89,7 @@ def getTransactionalDatabase(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createTransactional(outputFile) return self.DF2DB.getFileName() @@ -97,6 +100,7 @@ def getTemporalDatabase(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createTemporal(outputFile) return self.DF2DB.getFileName() @@ -107,6 +111,7 @@ def getUtilityDatabase(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createUtility(outputFile) return self.DF2DB.getFileName() diff --git a/PAMI/extras/DF2DB/DF2DBPlus.py b/PAMI/extras/DF2DB/DF2DBPlus.py index 5131145d..1631eb07 100644 --- a/PAMI/extras/DF2DB/DF2DBPlus.py +++ b/PAMI/extras/DF2DB/DF2DBPlus.py @@ -13,9 +13,12 @@ # # obj.getUDB("outputFileName") # To create a utility database # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -84,6 +87,7 @@ def getTransactional(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createTransactional(outputFile) return self.DF2DB.getFileName() @@ -94,6 +98,7 @@ def getTDB(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createTemporal(outputFile) return self.DF2DB.getFileName() @@ -104,6 +109,7 @@ def getUDB(self, outputFile) -> str: :param outputFile: file name or path to store database :type outputFile: str :return: outputFile name + :rtype: str """ self.DF2DB.createUtility(outputFile) return self.DF2DB.getFileName() diff --git a/PAMI/extras/DF2DB/DenseFormatDF.py b/PAMI/extras/DF2DB/DenseFormatDF.py index 07dafa8c..e8f39060 100644 --- a/PAMI/extras/DF2DB/DenseFormatDF.py +++ b/PAMI/extras/DF2DB/DenseFormatDF.py @@ -18,9 +18,14 @@ # obj.convert2UtilityDatabase("outputFileName") # To create utility database # # obj.getFileName("outputFileName") # To get file name of the database +# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -96,12 +101,17 @@ def convert2TransactionalDatabase(self, outputFile: str, condition: str, thresho :Attributes: - :param outputFile: str : - Write transactional database into outputFile - :param condition: str : - It is condition to judge the value in dataframe - :param thresholdValue: int or float : - User defined value. + :param outputFile: Write transactional database into outputFile + + :type outputFile: str + + :param condition: It is condition to judge the value in dataframe + + :type condition: str + + :param thresholdValue: User defined value. + + :type thresholdValue: Union[int, float] """ @@ -125,15 +135,19 @@ def convert2TransactionalDatabase(self, outputFile: str, condition: str, thresho def convert2TemporalDatabase(self, outputFile: str, condition: str, thresholdValue: Union[int, float]) -> None: """ - :Description: Create temporal database + :Description: Create temporal database - :param outputFile: str : - Write temporal database into outputFile - :param condition: str : - It is condition to judge the value in dataframe - :param thresholdValue: int or float : - User defined value. + :param outputFile: Write temporal database into outputFile + + :type outputFile: str + + :param condition: It is condition to judge the value in dataframe + :type condition: str + + :param thresholdValue: User defined value. + + :type thresholdValue: Union """ self.outputFile = outputFile @@ -158,17 +172,21 @@ def convert2TemporalDatabase(self, outputFile: str, condition: str, thresholdVal def convert2MultipleTimeSeries(self, interval: int, outputFile: str, condition: str, thresholdValue: Union[int, float]) -> None: """ - :Description: Create the multiple time series database. + :Description: Create the multiple time series database. - :param outputFile: str : - Write multiple time series database into outputFile. - :param interval: int: - Breaks the given timeseries into intervals. - :param condition: str : - It is condition to judge the value in dataframe - :param thresholdValue: int or float : - User defined value. + :param outputFile: Write multiple time series database into outputFile. + + :type outputFile: str + :param interval: Breaks the given timeseries into intervals. + + :type interval: int + + :param condition: It is condition to judge the value in dataframe + + :param thresholdValue: User defined value. + + :type thresholdValue: int or float """ self.outputFile = outputFile writer = open(self.outputFile, 'w+') @@ -233,10 +251,13 @@ def convert2UncertainTransactional(self, outputFile: str, condition: str, def convert2UtilityDatabase(self, outputFile: str) -> None: """ - :Description: Create the utility database. + :Description: Create the utility database. + + :param outputFile: Write utility database into outputFile + + :type outputFile: str - :param outputFile: str : - Write utility database into outputFile + :return: None """ self.outputFile = outputFile @@ -256,6 +277,7 @@ def convert2UtilityDatabase(self, outputFile: str) -> None: def getFileName(self) -> str: """ :return: outputFile name + :rtype: str """ return self.outputFile diff --git a/PAMI/extras/DF2DB/SparseFormatDF.py b/PAMI/extras/DF2DB/SparseFormatDF.py index 0c2792aa..332407e6 100644 --- a/PAMI/extras/DF2DB/SparseFormatDF.py +++ b/PAMI/extras/DF2DB/SparseFormatDF.py @@ -17,10 +17,12 @@ # # obj.getFileName("outputFileName") # To get file name of the database # -# -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -94,7 +96,7 @@ def createTransactional(self, outputFile: str) -> None: Create transactional data base :param outputFile: Write transactional data base into outputFile :type outputFile: str - + :return: None """ self.outputFile = outputFile with open(self.outputFile, 'w') as f: @@ -109,6 +111,7 @@ def createTemporal(self, outputFile: str) -> None: Create temporal data base :param outputFile: Write temporal data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -124,6 +127,7 @@ def createUtility(self, outputFile: str) -> None: Create the utility database. :param outputFile: Write utility database into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile diff --git a/PAMI/extras/DF2DB/createTDB.py b/PAMI/extras/DF2DB/createTDB.py index 61f0dc09..a06c5164 100644 --- a/PAMI/extras/DF2DB/createTDB.py +++ b/PAMI/extras/DF2DB/createTDB.py @@ -9,7 +9,9 @@ # # obj.save(oFile) # -# + + + import sys diff --git a/PAMI/extras/DF2DB/denseDF2DBPlus.py b/PAMI/extras/DF2DB/denseDF2DBPlus.py index d1c8906f..fe616688 100644 --- a/PAMI/extras/DF2DB/denseDF2DBPlus.py +++ b/PAMI/extras/DF2DB/denseDF2DBPlus.py @@ -17,10 +17,12 @@ # # obj.getFileName("outputFileName") # To get file name of the database # -# -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -69,7 +71,6 @@ class DenseFormatDFPlus: obj.getFileName("outputFileName") # To get file name of the database - """ def __init__(self, inputDF, thresholdConditionDF) -> None: @@ -88,6 +89,7 @@ def createTransactional(self, outputFile: str) -> None: Create transactional data base :param outputFile: Write transactional data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -117,6 +119,7 @@ def createTemporal(self, outputFile: str) -> None: Create temporal data base :param outputFile: Write temporal data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -145,6 +148,7 @@ def createUtility(self, outputFile: str) -> None: Create the utility data base. :param outputFile: Write utility data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile diff --git a/PAMI/extras/DF2DB/denseDF2DB_dump.py b/PAMI/extras/DF2DB/denseDF2DB_dump.py index 49561d55..7bd38312 100644 --- a/PAMI/extras/DF2DB/denseDF2DB_dump.py +++ b/PAMI/extras/DF2DB/denseDF2DB_dump.py @@ -17,8 +17,10 @@ # # obj.getFileName("outputFileName") # To get file name of the database # -# -# + + + + __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -87,8 +89,11 @@ def createTransactional(self, outputFile: str) -> None: """ :Description: Create transactional data base - :param outputFile: str : - Write transactional data base into outputFile + :param outputFile: Write transactional data base into outputFile + + :type outputFile: str + + :return: None """ @@ -176,11 +181,13 @@ def createTransactional(self, outputFile: str) -> None: def createTemporal(self, outputFile: str) -> None: """ - :Description: Create temporal data base + :Description: Create temporal data base + + :param outputFile: Write temporal data base into outputFile - :param outputFile: str : - Write temporal data base into outputFile + :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -275,9 +282,11 @@ def createUtility(self, outputFile: str) -> None: :Description: Create the utility database. - :param outputFile: str : + :param outputFile: Write utility database into outputFile - Write utility database into outputFile + :type outputFile: str + + :return: None """ @@ -297,6 +306,8 @@ def createUtility(self, outputFile: str) -> None: def getFileName(self) -> str: """ :return: outputFile name + + :rtype: str """ return self.outputFile diff --git a/PAMI/extras/DF2DB/sparseDF2DBPlus.py b/PAMI/extras/DF2DB/sparseDF2DBPlus.py index b4ccb46f..7ecf4be6 100644 --- a/PAMI/extras/DF2DB/sparseDF2DBPlus.py +++ b/PAMI/extras/DF2DB/sparseDF2DBPlus.py @@ -18,8 +18,12 @@ # obj.getFileName("outputFileName") # To get file name of the database # # + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,7 +70,7 @@ class SparseFormatDFPlus: obj.createUtility("outputFileName") # To create utility database obj.getFileName("outputFileName") # To get file name of the database - """ + """ def __init__(self, inputDF, thresholdConditionDF) -> None: @@ -86,6 +90,7 @@ def createTransactional(self, outputFile: str) -> None: Create transactional data base :param outputFile: Write transactional data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -101,6 +106,7 @@ def createTemporal(self, outputFile: str) -> None: Create temporal data base :param outputFile: Write temporal data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile @@ -116,6 +122,7 @@ def createUtility(self, outputFile: str) -> None: Create the utility data base. :param outputFile: Write utility data base into outputFile :type outputFile: str + :return: None """ self.outputFile = outputFile diff --git a/PAMI/extras/dbStats/SequentialDatabase.py b/PAMI/extras/dbStats/SequentialDatabase.py index da68e83f..0fec9877 100644 --- a/PAMI/extras/dbStats/SequentialDatabase.py +++ b/PAMI/extras/dbStats/SequentialDatabase.py @@ -116,24 +116,30 @@ class SequentialDatabase(): **Executing the code on terminal:** ------------------------------------------------- - Format: - - >>> python3 SequentialDatabase.py - Examples: - - >>> python3 SequentialDatabase.py sampleDB.txt - >>> python3 SequentialDatabase.py sampleDB.txt - - **Sample run of the importing code:** - ---------------------------------------------------- - import PAMI.extra.DBstats.SequentialDatabase as alg - _ap=alg.SequentialDatabase(inputfile,sep) - _ap.readDatabase() - _ap.printStats() - _ap.plotGraphs() - **Credits:** - --------------------- - The complete program was written by Shota Suzuki under the supervision of Professor Rage Uday Kiran. + + .. code-block:: console + + Format: + + (.venv) $ python3 SequentialDatabase.py + + Example Usage: + + (.venv) $ python3 SequentialDatabase.py sampleDB.txt + + (.venv) $ python3 SequentialDatabase.py sampleDB.txt + + + **Sample run of the importing code:** + ---------------------------------------------------- + import PAMI.extra.DBstats.SequentialDatabase as alg + _ap=alg.SequentialDatabase(inputfile,sep) + _ap.readDatabase() + _ap.printStats() + _ap.plotGraphs() + **Credits:** + --------------------- + The complete program was written by Shota Suzuki under the supervision of Professor Rage Uday Kiran. """ def __init__(self, inputFile: str, sep: str='\t') -> None: diff --git a/PAMI/extras/dbStats/UtilityDatabase.py b/PAMI/extras/dbStats/UtilityDatabase.py index ad25c7fd..2e828df7 100644 --- a/PAMI/extras/dbStats/UtilityDatabase.py +++ b/PAMI/extras/dbStats/UtilityDatabase.py @@ -146,7 +146,8 @@ def readDatabase(self) -> None: def getDatabaseSize(self) -> int: """ get the size of database - :return: int + :return: size of database + :rtype: int """ return len(self.database) diff --git a/PAMI/extras/fuzzyTransformation/temporalToFuzzy.py b/PAMI/extras/fuzzyTransformation/temporalToFuzzy.py index ebb2c63c..41c76b9f 100644 --- a/PAMI/extras/fuzzyTransformation/temporalToFuzzy.py +++ b/PAMI/extras/fuzzyTransformation/temporalToFuzzy.py @@ -9,12 +9,12 @@ # # obj.startConvert() # -# -# + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -155,7 +155,7 @@ def _Regions(self, quantity: int) -> None: calculate the labelled region of input "quantity" :param quantity: represents the quantity of item :type quantity: int - :return: None + :return: None """ self._list = [0] * len(self._LabelKey) if self._RegionsCal[0][0] < quantity <= self._RegionsCal[0][1]: diff --git a/PAMI/extras/fuzzyTransformation/transactionalToFuzzy.py b/PAMI/extras/fuzzyTransformation/transactionalToFuzzy.py index 4365d8f7..767c0daf 100644 --- a/PAMI/extras/fuzzyTransformation/transactionalToFuzzy.py +++ b/PAMI/extras/fuzzyTransformation/transactionalToFuzzy.py @@ -9,12 +9,12 @@ # # obj.startConvert() # -# + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -160,7 +160,7 @@ def _Regions(self, quantity: int) -> None: calculate the labelled region of input "quantity" :param quantity: represents the quantity of item :type quantity: int - :return: None + :return: None """ self._list = [0] * len(self._LabelKey) if self._RegionsCal[0][0] < quantity <= self._RegionsCal[0][1]: diff --git a/PAMI/extras/fuzzyTransformation/utilityToFuzzy.py b/PAMI/extras/fuzzyTransformation/utilityToFuzzy.py index ee5e1a5a..e5794833 100644 --- a/PAMI/extras/fuzzyTransformation/utilityToFuzzy.py +++ b/PAMI/extras/fuzzyTransformation/utilityToFuzzy.py @@ -9,10 +9,12 @@ # # obj.startConvert() # -# + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/generateDatabase/generateSpatioTemporalDatabase.py b/PAMI/extras/generateDatabase/generateSpatioTemporalDatabase.py index 628948b1..96578d04 100644 --- a/PAMI/extras/generateDatabase/generateSpatioTemporalDatabase.py +++ b/PAMI/extras/generateDatabase/generateSpatioTemporalDatabase.py @@ -14,8 +14,11 @@ # obj.saveAsFile("outputFileName") # To create a file # + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/generateDatabase/generateTemporalDatabase.py b/PAMI/extras/generateDatabase/generateTemporalDatabase.py index a48e9441..7efc5856 100644 --- a/PAMI/extras/generateDatabase/generateTemporalDatabase.py +++ b/PAMI/extras/generateDatabase/generateTemporalDatabase.py @@ -14,9 +14,13 @@ # obj.getDatabaseAsDataFrame("outputFileName") # to convert database into dataframe # # obj.createTemporalFile("outputFileName") # to get outputfile +# + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -146,19 +150,27 @@ def __init__(self, numOfTransactions: int, avgLenOfTransactions: int, def getFileName(self) -> str: """ return filename - :return: + :return: filename + :rtype: str """ return self.outputFile def getDatabaseAsDataFrame(self) -> pd.DataFrame: """ return dataframe - return: pd.dataframe + :return: dataframe + :rtype: pd.DataFrame """ return self.df def performCoinFlip(self, probability: float) -> bool: - """Perform a coin flip with the given probability.""" + """ + Perform a coin flip with the given probability. + :param probability: probability to perform coin flip + :type probability: float + :return: True if coin flip is performed, False otherwise + :rtype: bool + """ result = np.random.choice([0, 1], p=[1 - probability, probability]) return result == 1 @@ -167,12 +179,17 @@ def tuning(self, array, sumRes) -> list: """ Tune the array so that the sum of the values is equal to sumRes - Parameters: - array: list - list of values - sumRes: int - target sum + :param array: list of values + + :type array: list + + :param sumRes: target sum + + :type sumRes: int + + :return: list of values with the sum equal to sumRes after tuning - Returns: - array: list - tuned array + :rtype: list """ # first generate a random array of length n whose values average to m @@ -199,7 +216,7 @@ def tuning(self, array, sumRes) -> list: def createTemporalFile(self) -> None: """ create Temporal database or dataframe depending on input - :return: + :return: None """ db = [] diff --git a/PAMI/extras/generateDatabase/generateTransactionalDatabase.py b/PAMI/extras/generateDatabase/generateTransactionalDatabase.py index 9268e394..956e0302 100644 --- a/PAMI/extras/generateDatabase/generateTransactionalDatabase.py +++ b/PAMI/extras/generateDatabase/generateTransactionalDatabase.py @@ -1,7 +1,3 @@ -import numpy as np -import pandas as pd -import sys - # generateTransactionalDatabase is a code used to convert the database into Temporal database. # # **Importing this algorithm into a python program** @@ -16,9 +12,13 @@ # -------------------------------------------------------- # python generateDatabase.py 10 5 10 db.txt # cat db.txt +# + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,6 +34,12 @@ along with this program. If not, see . """ + +import numpy as np +import pandas as pd +import sys + + class generateTransactionalDatabase: """ :Description Generate a transactional database with the given number of lines, average number of items per line, and total number of items @@ -78,12 +84,17 @@ def tuning(self, array, sumRes) -> list: """ Tune the array so that the sum of the values is equal to sumRes - Parameters: - array: list - list of values - sumRes: int - target sum + :param array: list of values + + :type array: list + + :param sumRes: the sum of the values in the array to be tuned + + :type sumRes: int - Returns: - array: list - tuned array + :return: list of values with the tuned values and the sum of the values in the array to be tuned and sumRes is equal to sumRes + + :rtype: list """ while np.sum(array) != sumRes: @@ -103,13 +114,21 @@ def generateArray(self, nums, avg, maxItems) -> list: """ Generate a random array of length n whose values average to m - Parameters: - nums: int - number of values - avg: int - average value - maxItems: int - maximum value + :param nums: number of values + + :type nums: list + + :param avg: average value + + :type avg: float - Returns: - values: list - random array + :param maxItems: maximum value + + :type maxItems: int + + :return: random array + + :rtype: list """ # generate n random values @@ -142,11 +161,8 @@ def generateArray(self, nums, avg, maxItems) -> list: def create(self) -> None: """ - Generate the transactional database - - Returns: - + :return: None """ db = set() @@ -160,9 +176,11 @@ def save(self, filename) -> None: """ Save the transactional database to a file - Parameters: - filename: str - name of the file - + :param filename: name of the file + + :type filename: str + + :return: None """ with open(filename, 'w') as f: @@ -173,9 +191,9 @@ def getTransactions(self) -> pd.DataFrame: """ Get the transactional database - Returns: - db: list - transactional database - + :return: the transactional database + + :rtype: pd.DataFrame """ df = pd.DataFrame(self.db) return df diff --git a/PAMI/extras/graph/DF2Fig.py b/PAMI/extras/graph/DF2Fig.py index 54430272..2da4064a 100644 --- a/PAMI/extras/graph/DF2Fig.py +++ b/PAMI/extras/graph/DF2Fig.py @@ -14,8 +14,11 @@ # obj.plotGraphsFromDataFrame("minSup", "runtime") # + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -75,6 +78,20 @@ def __init__(self, dataFrame: _pd.DataFrame) -> None: def plot(self, xColumn, yColumn, algorithm=None) -> None: """ To plot graphs from given dataframe + + :param xColumn: Name of the X-axis of the dataframe + + :type xColumn: str + + :param yColumn: Name of the Y-axis of the dataframe + + :type yColumn: str + + :param algorithm: Specify the column name containing the algorithms + + :type algorithm: str + + :return: None """ if algorithm is None: fig = _px.line(self._dataFrame, x=self._dataFrame[xColumn] , y=self._dataFrame[yColumn], color=self._dataFrame.iloc[:, 0], labels={'x': xColumn, 'y': yColumn}) diff --git a/PAMI/extras/graph/DF2Tex.py b/PAMI/extras/graph/DF2Tex.py index dff8184c..abe2eeb7 100644 --- a/PAMI/extras/graph/DF2Tex.py +++ b/PAMI/extras/graph/DF2Tex.py @@ -13,8 +13,12 @@ # # obj.save("outputFile.tex") # + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/graph/plotLineGraphFromDictionary.py b/PAMI/extras/graph/plotLineGraphFromDictionary.py index c01929d6..daf916d6 100644 --- a/PAMI/extras/graph/plotLineGraphFromDictionary.py +++ b/PAMI/extras/graph/plotLineGraphFromDictionary.py @@ -8,10 +8,13 @@ # obj = plt.plotLineGraphFromDictionary(idict, 100, 0, " ") # # obj.save() +# + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -68,6 +71,7 @@ def __init__(self, data: dict, end: int=100, start: int=0, title: str='', xlabel :type xlabel: str :param ylabel: ylabel of grapth :type ylabel: str + :return: None """ end = int(len(data) * end / 100) start = int(len(data) * start / 100) diff --git a/PAMI/extras/graph/plotLineGraphsFromDataFrame.py b/PAMI/extras/graph/plotLineGraphsFromDataFrame.py index e940ad3d..aa182296 100644 --- a/PAMI/extras/graph/plotLineGraphsFromDataFrame.py +++ b/PAMI/extras/graph/plotLineGraphsFromDataFrame.py @@ -9,10 +9,13 @@ # # obj.save() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/graph/visualizeFuzzyPatterns.py b/PAMI/extras/graph/visualizeFuzzyPatterns.py index 677f0bbd..33153a98 100644 --- a/PAMI/extras/graph/visualizeFuzzyPatterns.py +++ b/PAMI/extras/graph/visualizeFuzzyPatterns.py @@ -9,10 +9,13 @@ # # obj.save() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,10 +68,15 @@ def visualize(self, markerSize: int = 20, zoom: int = 3, width: int = 1500, heig """ Visualize points produced by pattern miner. - :param markerSize: integer - :param zoom: int - :param width: int - :param height: int + :param markerSize: Size of the marker + :type markerSize: int + :param zoom: Zoom level + :type zoom: int + :param width: Width of the graph + :type width: int + :param height: Height of the graph on the screen + :type width: int + :return: None """ long = [] diff --git a/PAMI/extras/graph/visualizePatterns.py b/PAMI/extras/graph/visualizePatterns.py index c3a66d60..fdaaef1b 100644 --- a/PAMI/extras/graph/visualizePatterns.py +++ b/PAMI/extras/graph/visualizePatterns.py @@ -9,10 +9,13 @@ # # obj.save() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,24 +39,24 @@ class visualizePatterns(): """ - :Description: visualizePatterns is used to visualize points produced by pattern miner . + :Description: visualizePatterns is used to visualize points produced by pattern miner . - :Attributes: + :Attributes: - :param file : file - store input data as file - :param topk : int - Takes the value int as input + :param file : file + store input data as file + :param topk : int + Takes the value int as input - **Importing this algorithm into a python program** - -------------------------------------------------------- - .. code-block:: python + **Importing this algorithm into a python program** + -------------------------------------------------------- + .. code-block:: python - from PAMI.extras.graph import visualizePatterns as viz + from PAMI.extras.graph import visualizePatterns as viz - obj = viz.visualizePatterns(iFile, topk) + obj = viz.visualizePatterns(iFile, topk) - obj.save() + obj.save() """ @@ -65,10 +68,15 @@ def visualize(self, markerSize: int = 20, zoom: int = 3, width: int = 1500, heig """ Visualize points produced by pattern miner. - :param markerSize: integer - :param zoom: int - :param width: int - :param height: int + :param markerSize: Size of the marker + :type markerSize: int + :param zoom: Zoom level + :type zoom: int + :param width: Width of the graph + :type width: int + :param height: Height of the graph on the screen + :type width: int + :return: None """ long = [] diff --git a/PAMI/extras/imageProcessing/imagery2Databases.py b/PAMI/extras/imageProcessing/imagery2Databases.py index 5344aff6..53ec6df5 100644 --- a/PAMI/extras/imageProcessing/imagery2Databases.py +++ b/PAMI/extras/imageProcessing/imagery2Databases.py @@ -9,10 +9,13 @@ # # obj.save() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/messaging/gmail.py b/PAMI/extras/messaging/gmail.py index 36dd3cc7..b237554b 100644 --- a/PAMI/extras/messaging/gmail.py +++ b/PAMI/extras/messaging/gmail.py @@ -1,5 +1,5 @@ __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/neighbours/findNeighborsUsingEuclideanDistanceforPointInfo.py b/PAMI/extras/neighbours/findNeighborsUsingEuclideanDistanceforPointInfo.py index a25fdd61..a605bae8 100644 --- a/PAMI/extras/neighbours/findNeighborsUsingEuclideanDistanceforPointInfo.py +++ b/PAMI/extras/neighbours/findNeighborsUsingEuclideanDistanceforPointInfo.py @@ -9,10 +9,13 @@ # # obj.save() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/neighbours/findNeighboursUsingEuclidean.py b/PAMI/extras/neighbours/findNeighboursUsingEuclidean.py index 80342cca..372cfddf 100644 --- a/PAMI/extras/neighbours/findNeighboursUsingEuclidean.py +++ b/PAMI/extras/neighbours/findNeighboursUsingEuclidean.py @@ -9,10 +9,12 @@ # # obj.save() # -# + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/neighbours/findNeighboursUsingGeodesic.py b/PAMI/extras/neighbours/findNeighboursUsingGeodesic.py index 7f28d7e0..561c97d6 100644 --- a/PAMI/extras/neighbours/findNeighboursUsingGeodesic.py +++ b/PAMI/extras/neighbours/findNeighboursUsingGeodesic.py @@ -9,10 +9,12 @@ # # obj.save() # -# + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/PAMI/extras/stats/TransactionalDatabase.py b/PAMI/extras/stats/TransactionalDatabase.py index aef0df00..b70f849e 100644 --- a/PAMI/extras/stats/TransactionalDatabase.py +++ b/PAMI/extras/stats/TransactionalDatabase.py @@ -12,11 +12,13 @@ # obj.run() # # obj.printStats() +# + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -105,6 +107,9 @@ def __init__(self, inputFile: Union[str, pd.DataFrame], sep: str = '\t') -> None """ :param inputFile: input file name or path :type inputFile: str + :param sep: separator + :type sep: str + :return: None """ self.inputFile = inputFile self.lengthList = [] @@ -154,6 +159,7 @@ def getDatabaseSize(self) -> int: """ get the size of database :return: dataset size + :rtype: int """ return len(self.database) @@ -161,6 +167,7 @@ def getTotalNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -168,6 +175,7 @@ def getMinimumTransactionLength(self) -> int: """ get the minimum transaction length :return: minimum transaction length + :rtype: int """ return min(self.lengthList) @@ -175,6 +183,7 @@ def getAverageTransactionLength(self) -> float: """ get the average transaction length. It is sum of all transaction length divided by database length. :return: average transaction length + :rtype: float """ totalLength = sum(self.lengthList) return totalLength / len(self.database) @@ -183,6 +192,7 @@ def getMaximumTransactionLength(self) -> int: """ get the maximum transaction length :return: maximum transaction length + :rtype: int """ return max(self.lengthList) @@ -190,6 +200,7 @@ def getStandardDeviationTransactionLength(self) -> float: """ get the standard deviation transaction length :return: standard deviation transaction length + :rtype: float """ return statistics.pstdev(self.lengthList) @@ -197,6 +208,7 @@ def getVarianceTransactionLength(self) -> float: """ get the variance transaction length :return: variance transaction length + :rtype: float """ return statistics.variance(self.lengthList) @@ -204,6 +216,7 @@ def getNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -232,6 +245,7 @@ def getSparsity(self) -> float: """ get the sparsity of database. sparsity is percentage of 0 of database. :return: database sparsity + :rtype: float """ big_array = self.convertDataIntoMatrix() n_zeros = np.count_nonzero(big_array == 0) @@ -241,6 +255,7 @@ def getDensity(self) -> float: """ get the sparsity of database. sparsity is percentage of 0 of database. :return: database sparsity + :rtype: float """ big_array = self.convertDataIntoMatrix() n_zeros = np.count_nonzero(big_array != 0) @@ -250,6 +265,7 @@ def getSortedListOfItemFrequencies(self) -> dict: """ get sorted list of item frequencies :return: item frequencies + :rtype: dict """ itemFrequencies = {} for tid in self.database: @@ -274,7 +290,8 @@ def getFrequenciesInRange(self) -> dict: def getTransanctionalLengthDistribution(self) -> dict: """ Get transaction length - :return: dict + :return: a dictionary with transaction + :rtype: dict """ transactionLength = {} for length in self.lengthList: @@ -289,6 +306,7 @@ def save(self, data: dict, outputFile: str) -> None: :type data: dict :param outputFile: output file name or path to store :type outputFile: str + :return: None """ with open(outputFile, 'w') as f: for key, value in data.items(): diff --git a/PAMI/extras/stats/sequentialDatabase.py b/PAMI/extras/stats/sequentialDatabase.py index e9903399..842a89b3 100644 --- a/PAMI/extras/stats/sequentialDatabase.py +++ b/PAMI/extras/stats/sequentialDatabase.py @@ -13,10 +13,13 @@ # # obj.printStats() # -# + + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -113,30 +116,38 @@ class sequentialDatabase(): **Executing the code on terminal:** ------------------------------------------------- - Format: - - >>> python3 sequentialDatabase.py - Examples: - - >>> python3 sequentialDatabase.py sampleDB.txt - >>> python3 sequentialDatabase.py sampleDB.txt - - **Sample run of the importing code:** - ---------------------------------------------------- - import PAMI.extra.DBstats.SequentialDatabase as alg - _ap=alg.SequentialDatabase(inputfile,sep) - _ap.readDatabase() - _ap.printStats() - _ap.plotGraphs() - **Credits:** - --------------------- - The complete program was written by Shota Suzuki under the supervision of Professor Rage Uday Kiran. + + .. code-block:: console + + Format: + + (.venv) $ python3 sequentialDatabase.py + + Example Usage: + + (.venv) $ python3 sequentialDatabase.py sampleDB.txt + + + + **Sample run of the importing code:** + ---------------------------------------------------- + import PAMI.extra.DBstats.SequentialDatabase as alg + _ap=alg.SequentialDatabase(inputfile,sep) + _ap.readDatabase() + _ap.printStats() + _ap.plotGraphs() + **Credits:** + --------------------- + The complete program was written by Shota Suzuki under the supervision of Professor Rage Uday Kiran. """ def __init__(self, inputFile: str, sep: str='\t') -> None: """ :param inputFile: input file name or path :type inputFile: str + :param sep: separator character for input file + :type sep: str + :return: None """ self.inputFile = inputFile self.seqLengthList = [] @@ -198,6 +209,7 @@ def getDatabaseSize(self) -> int: """ get the size of database :return: dataset size + :rtype: int """ return len(self.database) @@ -205,6 +217,7 @@ def getTotalNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -212,6 +225,7 @@ def getMinimumSequenceLength(self) -> int: """ get the minimum sequence length :return: minimum sequence length + :rtype: int """ return min(self.seqLengthList) @@ -219,6 +233,7 @@ def getAverageSubsequencePerSequenceLength(self) -> float: """ get the average subsequence length per sequence length. It is sum of all subsequence length divided by sequence length. :return: average subsequence length per sequence length + :rtype: float """ totalLength = sum(self.seqLengthList) return totalLength / len(self.database) @@ -228,6 +243,7 @@ def getAverageItemPerSubsequenceLength(self) -> float: """ get the average Item length per subsequence. It is sum of all item length divided by subsequence length. :return: average Item length per subsequence + :rtype: float """ totalLength = sum(list(map(sum,self.subSeqLengthList))) @@ -237,6 +253,7 @@ def getMaximumSequenceLength(self) -> int: """ get the maximum sequence length :return: maximum sequence length + :rtype: int """ return max(self.seqLengthList) @@ -244,6 +261,7 @@ def getStandardDeviationSequenceLength(self) -> float: """ get the standard deviation sequence length :return: standard deviation sequence length + :rtype: float """ return statistics.pstdev(self.seqLengthList) @@ -251,6 +269,7 @@ def getVarianceSequenceLength(self) -> float: """ get the variance Sequence length :return: variance Sequence length + :rtype: float """ return statistics.variance(self.seqLengthList) @@ -258,6 +277,7 @@ def getSequenceSize(self) -> int: """ get the size of sequence :return: sequences size + :rtype: int """ return sum(self.seqLengthList) @@ -265,6 +285,7 @@ def getMinimumSubsequenceLength(self) -> int: """ get the minimum subsequence length :return: minimum subsequence length + :rtype: int """ return min(list(map(min,self.subSeqLengthList))) @@ -272,6 +293,7 @@ def getAverageItemPerSequenceLength(self) -> float: """ get the average item length per sequence. It is sum of all item length divided by sequence length. :return: average item length per sequence + :rtype: float """ totalLength = sum(list(map(sum,self.subSeqLengthList))) return totalLength / len(self.database) @@ -280,6 +302,7 @@ def getMaximumSubsequenceLength(self) -> int: """ get the maximum subsequence length :return: maximum subsequence length + :rtype: int """ return max(list(map(max,self.subSeqLengthList))) @@ -287,6 +310,7 @@ def getStandardDeviationSubsequenceLength(self) -> float: """ get the standard deviation subsequence length :return: standard deviation subsequence length + :rtype: float """ allList=[] for i in self.subSeqLengthList: @@ -297,6 +321,7 @@ def getVarianceSubsequenceLength(self) -> float: """ get the variance subSequence length :return: variance subSequence length + :rtype: float """ allList = [] for i in self.subSeqLengthList: @@ -307,6 +332,7 @@ def getSortedListOfItemFrequencies(self) -> Dict[str, int]: """ get sorted list of item frequencies :return: item frequencies + :rtype: dict """ itemFrequencies = {} for seq in self.database: @@ -320,6 +346,7 @@ def getFrequenciesInRange(self) -> Dict[int, int]: """ get sorted list of item frequencies in some range :return: item separated by its frequencies + :rtype: dict """ fre = self.getSortedListOfItemFrequencies() rangeFrequencies = {} @@ -336,6 +363,7 @@ def getSequencialLengthDistribution(self) -> Dict[int, int]: """ get Sequence length Distribution :return: Sequence length + :rtype: dict """ transactionLength = {} for length in self.seqLengthList: @@ -347,6 +375,7 @@ def getSubsequencialLengthDistribution(self) -> Dict[int, int]: """ get subSequence length distribution :return: subSequence length + :rtype: dict """ transactionLength = {} for sublen in self.subSeqLengthList: diff --git a/PAMI/extras/stats/temporalDatabase.py b/PAMI/extras/stats/temporalDatabase.py index a225a01a..c2c4a564 100644 --- a/PAMI/extras/stats/temporalDatabase.py +++ b/PAMI/extras/stats/temporalDatabase.py @@ -14,8 +14,11 @@ # obj.printStats() # + + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -104,7 +107,9 @@ def __init__(self, inputFile: Union[str, pd.DataFrame], sep: str = '\t') -> None """ :param inputFile: input file name or path :type inputFile: str - :param sep: + :param sep: separator between column names and values in input file + :type sep: str + :return: None """ self.inputFile = inputFile self.database = {} @@ -182,6 +187,7 @@ def getDatabaseSize(self) -> int: """ get the size of database :return: dataset size + :rtype: int """ return len(self.database) @@ -189,6 +195,7 @@ def getMinimumTransactionLength(self) -> int: """ get the minimum transaction length :return: minimum transaction length + :rtype: int """ return min(self.lengthList) @@ -196,6 +203,7 @@ def getAverageTransactionLength(self) -> float: """ get the average transaction length. It is sum of all transaction length divided by database length. :return: average transaction length + :rtype: float """ totalLength = sum(self.lengthList) return totalLength / len(self.database) @@ -204,6 +212,7 @@ def getMaximumTransactionLength(self) -> int: """ get the maximum transaction length :return: maximum transaction length + :rtype: int """ return max(self.lengthList) @@ -211,6 +220,7 @@ def getStandardDeviationTransactionLength(self) -> float: """ get the standard deviation transaction length :return: standard deviation transaction length + :rtype: float """ return statistics.pstdev(self.lengthList) @@ -218,6 +228,7 @@ def getVarianceTransactionLength(self) -> float: """ get the variance transaction length :return: variance transaction length + :rtype: float """ return statistics.variance(self.lengthList) @@ -244,6 +255,7 @@ def getSparsity(self) -> float: """ get the sparsity of database. sparsity is percentage of 0 of database. :return: database sparsity + :rtype: float """ big_array = self.convertDataIntoMatrix() n_zeros = np.count_nonzero(big_array == 0) @@ -253,6 +265,7 @@ def getDensity(self) -> float: """ get the sparsity of database. sparsity is percentage of 0 of database. :return: database sparsity + :rtype: float """ big_array = self.convertDataIntoMatrix() n_zeros = np.count_nonzero(big_array == 1) @@ -262,6 +275,7 @@ def getTotalNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -269,6 +283,7 @@ def getSortedListOfItemFrequencies(self) -> Dict[str, int]: """ get sorted list of item frequencies :return: item frequencies + :rtype: dict """ itemFrequencies = {} for tid in self.database: @@ -307,6 +322,7 @@ def getTransanctionalLengthDistribution(self) -> Dict[int, int]: """ get transaction length :return: transactional length + :rtype: dict """ transactionLength = {} for length in self.lengthList: @@ -321,6 +337,7 @@ def save(self, data: dict, outputFile: str) -> None: :type data: dict :param outputFile: output file name or path to store :type outputFile: str + :return: None """ with open(outputFile, 'w') as f: for key, value in data.items(): @@ -330,6 +347,7 @@ def getMinimumInterArrivalPeriod(self) -> int: """ get the minimum inter arrival period :return: minimum inter arrival period + :rtype: int """ return min(self.periodList) @@ -337,6 +355,7 @@ def getAverageInterArrivalPeriod(self) -> float: """ get the average inter arrival period. It is sum of all period divided by number of period. :return: average inter arrival period + :rtype: float """ totalPeriod = sum(self.periodList) return totalPeriod / len(self.periodList) @@ -345,6 +364,7 @@ def getMaximumInterArrivalPeriod(self) -> int: """ get the maximum inter arrival period :return: maximum inter arrival period + :rtype: int """ return max(self.periodList) @@ -352,6 +372,7 @@ def getMinimumPeriodOfItem(self) -> int: """ get the minimum period of the item :return: minimum period + :rtype: int """ return min([i for i in self.periods.values()]) @@ -359,6 +380,7 @@ def getAveragePeriodOfItem(self) -> float: """ get the average period of the item :return: average period + :rtype: float """ return sum([i for i in self.periods.values()]) / len(self.periods) @@ -366,6 +388,7 @@ def getMaximumPeriodOfItem(self) -> int: """ get the maximum period of the item :return: maximum period + :rtype:int """ return max([i for i in self.periods.values()]) @@ -373,6 +396,7 @@ def getStandardDeviationPeriod(self) -> float: """ get the standard deviation period :return: standard deviation period + :rtype: float """ return statistics.pstdev(self.periodList) @@ -380,6 +404,7 @@ def getNumberOfTransactionsPerTimestamp(self) -> Dict[int, int]: """ get number of transactions per time stamp :return: number of transactions per time stamp as dict + :rtype: dict """ maxTS = max(list(self.timeStampCount.keys())) return {ts: self.timeStampCount.get(ts, 0) for ts in range(1, maxTS + 1)} diff --git a/PAMI/extras/stats/utilityDatabase.py b/PAMI/extras/stats/utilityDatabase.py index 5e59abc4..db99daf3 100644 --- a/PAMI/extras/stats/utilityDatabase.py +++ b/PAMI/extras/stats/utilityDatabase.py @@ -12,10 +12,13 @@ # obj.run() # # obj.printStats() +# + + __copyright__ = """ - Copyright (C) 2021 Rage Uday Kiran +Copyright (C) 2021 Rage Uday Kiran This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -68,6 +71,9 @@ def __init__(self, inputFile: Union[str, pd.DataFrame], sep: str='\t') -> None: """ :param inputFile: input file name or path :type inputFile: str + :param sep: separator between files. Default is tab space + :type sep: str + :return: None """ self.inputFile = inputFile self.database = {} @@ -140,7 +146,8 @@ def readDatabase(self) -> None: def getDatabaseSize(self) -> int: """ get the size of database - :return: int + :return: size of database after reading from database + :rtype: int """ return len(self.database) @@ -148,6 +155,7 @@ def getTotalNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -155,6 +163,7 @@ def getMinimumTransactionLength(self) -> int: """ get the minimum transaction length :return: minimum transaction length + :rtype: int """ return min(self.lengthList) @@ -162,6 +171,7 @@ def getAverageTransactionLength(self) -> float: """ get the average transaction length. It is sum of all transaction length divided by database length. :return: average transaction length + :rtype: float """ totalLength = sum(self.lengthList) return totalLength / len(self.database) @@ -170,6 +180,7 @@ def getMaximumTransactionLength(self) -> int: """ get the maximum transaction length :return: maximum transaction length + :rtype: int """ return max(self.lengthList) @@ -177,6 +188,7 @@ def getStandardDeviationTransactionLength(self) -> float: """ get the standard deviation transaction length :return: standard deviation transaction length + :rtype: float """ return statistics.pstdev(self.lengthList) @@ -184,6 +196,7 @@ def getVarianceTransactionLength(self) -> float: """ get the variance transaction length :return: variance transaction length + :rtype: float """ return statistics.variance(self.lengthList) @@ -191,6 +204,7 @@ def getNumberOfItems(self) -> int: """ get the number of items in database. :return: number of items + :rtype: int """ return len(self.getSortedListOfItemFrequencies()) @@ -198,7 +212,8 @@ def getSparsity(self) -> float: # percentage of 0 dense dataframe """ get the sparsity of database - :return: float + :return: sparsity of database after reading from database + :rtype: float """ matrixSize = self.getDatabaseSize()*len(self.getSortedListOfItemFrequencies()) return (matrixSize - sum(self.getSortedListOfItemFrequencies().values())) / matrixSize @@ -207,6 +222,7 @@ def getSortedListOfItemFrequencies(self) -> dict: """ get sorted list of item frequencies :return: item frequencies + :rtype: dict """ itemFrequencies = {} for tid in self.database: @@ -219,6 +235,7 @@ def getFrequenciesInRange(self) -> dict: """ This function is used to get the Frequencies in range :return: Frequencies In Range + :rtype: dict """ fre = self.getSortedListOfItemFrequencies() rangeFrequencies = {} @@ -236,7 +253,8 @@ def getFrequenciesInRange(self) -> dict: def getTransanctionalLengthDistribution(self) -> dict: """ get transaction length - :return: dict + :return: Transanctional Length Distribution + :rtype: dict """ transactionLength = {} for length in self.lengthList: @@ -251,6 +269,7 @@ def save(self, data, outputFile) -> None: :type data: dict :param outputFile: output file name or path to store :type outputFile: str + :return: None """ with open(outputFile, 'w') as f: for key, value in data.items(): @@ -260,13 +279,15 @@ def getTotalUtility(self) -> int: """ get sum of utility :return: total utility + :rtype: int """ return sum(list(self.utility.values())) def getMinimumUtility(self) -> int: """ get the minimum utility - :return: int + :return: minimum utility + :rtype: int """ return min(list(self.utility.values())) @@ -274,13 +295,15 @@ def getAverageUtility(self) -> float: """ get the average utility :return: average utility + :rtype: float """ return sum(list(self.utility.values())) / len(self.utility) def getMaximumUtility(self) -> int: """ get the maximum utility - :return: int + :return: maximum utility + :rtype: int """ return max(list(self.utility.values())) @@ -288,6 +311,7 @@ def getSortedUtilityValuesOfItem(self) -> dict: """ get sorted utility value each item. key is item and value is utility of item :return: sorted dictionary utility value of item + :rtype: dict """ return self.utility