Skip to content

Commit

Permalink
#300 bug resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
udayRage committed Nov 9, 2024
1 parent 6c404db commit d2fa154
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
46 changes: 22 additions & 24 deletions PAMI/extras/syntheticDataGenerator/TemporalDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

class TemporalDatabase:

def __init__(self, numOfTransactions: int,
avgLenOfTransactions: int,
def __init__(self, databaseSize: int,
avgItemsPerTransaction: int,
numItems: int,
sep: str = '\t',
occurrenceProbabilityAtSameTimestamp: float = 0.1,
occurrenceProbabilityOfSameTimestamp: float = 0.1,
occurrenceProbabilityToSkipSubsequentTimestamp: float = 0.1) -> None:

self.numOfTransactions = numOfTransactions
self.avgItemsPerTransaction = avgLenOfTransactions
self.databaseSize = databaseSize
self.avgItemsPerTransaction = avgItemsPerTransaction
self.numItems = numItems
self.sep = sep
self.occurrenceProbabilityAtSameTimestamp = occurrenceProbabilityAtSameTimestamp
self.occurrenceProbabilityOfSameTimestamp = occurrenceProbabilityOfSameTimestamp
self.occurrenceProbabilityToSkipSubsequentTimestamp = occurrenceProbabilityToSkipSubsequentTimestamp

def performCoinFlip(self, probability: float) -> bool:
Expand Down Expand Up @@ -80,11 +80,11 @@ def create(self) -> None:

self.current_timestamp = 0 # Initialize current timestamp

sumRes = self.numOfTransactions * self.avgItemsPerTransaction # Total number of items
sumRes = self.databaseSize * self.avgItemsPerTransaction # Total number of items

for i in range(self.numOfTransactions):
for i in range(self.databaseSize):
# Determine the timestamp
if self.performCoinFlip(self.occurrenceProbabilityAtSameTimestamp):
if self.performCoinFlip(self.occurrenceProbabilityOfSameTimestamp):
timestamp = self.current_timestamp
else:
if self.performCoinFlip(self.occurrenceProbabilityToSkipSubsequentTimestamp):
Expand All @@ -107,7 +107,7 @@ def create(self) -> None:

if num_items > self.numItems:
raise ValueError(
"Error: Either increase numItems or decrease avgLenOfTransactions or modify percentage")
"Error: Either increase numItems or decrease avgItemsPerTransaction or modify percentage")
items = np.random.choice(range(1, self.numItems + 1), num_items, replace=False)
self.db[transaction_index].extend(items)

Expand All @@ -123,7 +123,7 @@ def save(self, outputFile: str = None) -> None:
if outputFile is not None:
self.outputFile = outputFile
else:
self.outputFile = "temporalDatabase." + self.typeOfFile + ".txt"
self.outputFile = "temporalDatabase.txt"

with open(self.outputFile, 'w') as writer:
for line in self.db:
Expand Down Expand Up @@ -162,29 +162,27 @@ def getTransactions(self) -> None:
return self.df

if __name__ == '__main__':
if len(sys.argv) == 10:
if len(sys.argv) == 7:
obj = TemporalDatabase(
numOfTransactions=int(sys.argv[1]),
avgLenOfTransactions=int(sys.argv[2]),
databaseSize=int(sys.argv[1]),
avgItemsPerTransaction=int(sys.argv[2]),
numItems=int(sys.argv[3]),
outputFile=sys.argv[4],
percentage=int(sys.argv[5]),
sep=sys.argv[6],
typeOfFile=sys.argv[7],
occurrenceProbabilityAtSameTimestamp=float(sys.argv[8]),
occurrenceProbabilityToSkipSubsequentTimestamp=float(sys.argv[9])
outputFile=str(sys.argv[4]),
occurrenceProbabilityOfSameTimestamp=float(sys.argv[5]),
occurrenceProbabilityToSkipSubsequentTimestamp=float(sys.argv[6]),
sep=sys.argv[7]
)
obj.create()
obj.save()
else:
print("Usage: python TemporalDatabase.py <numOfTransactions> <avgLenOfTransactions> <numItems> <outputFile> <percentage> <sep> <typeOfFile> <occurrenceProbabilityAtSameTimestamp> <occurrenceProbabilityToSkipSubsequentTimestamp>")
print("Usage: python TemporalDatabase.py <databaseSize> <avgItemsPerTransaction> <numItems> <outputFile> <occurrenceProbabilityOfSameTimestamp> <occurrenceProbabilityToSkipSubsequentTimestamp> <sep> ")

obj = TemporalDatabase(
numOfTransactions=100000,
avgLenOfTransactions=10,
databaseSize=100000,
avgItemsPerTransaction=10,
numItems=50,
sep="\t",
occurrenceProbabilityAtSameTimestamp=0.1,
occurrenceProbabilityOfSameTimestamp=0.1,
occurrenceProbabilityToSkipSubsequentTimestamp=0.1
)
obj.create()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pami',
version='2024.11.09.1',
version='2024.11.09.2',
author='Rage Uday Kiran',
author_email='uday.rage@gmail.com',
description='This software is being developed at the University of Aizu, Aizu-Wakamatsu, Fukushima, Japan',
Expand Down

0 comments on commit d2fa154

Please sign in to comment.