Skip to content

Commit

Permalink
Merge branch 'UdayLab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarun-Sreepada authored Jun 30, 2024
2 parents 571880f + cbaa9c8 commit 5af66fa
Show file tree
Hide file tree
Showing 80 changed files with 1,171,499 additions and 3,537 deletions.
49 changes: 7 additions & 42 deletions PAMI/contiguousFrequentPattern/basic/PositionMining.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,10 @@
import pandas as pd
import numpy as np
import math
from PAMI.contigousFrequentPattern.basic import abstract as _ab
from PAMI.contiguousFrequentPattern import abstract as _ab
from deprecated import deprecated


__copyright__ = """
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

class Node:
def __init__(self,symbol,leaf=False):
self._val=symbol
Expand Down Expand Up @@ -96,9 +79,10 @@ class PositionMining:
"""

def __init__(self,minsup,datapath):
def __init__(self,minsup,datapath,maxlength=20):
self.min_sup=minsup
self.datapath=datapath
self.maxlength=maxlength


def readData(self):
Expand All @@ -110,6 +94,7 @@ def readData(self):
# for i in range(1,len(vals)):
# self.seq_prefixes[vals[i]]
self.data=vals
# print(self.data)

def getfreqs(self):
"""
Expand Down Expand Up @@ -272,7 +257,7 @@ def mineNext_candidates(self):
"""
Mining frequent patterns along with their positions from length 1 frequent candidates
"""
while self.current_candidate<5:
while self.current_candidate<self.maxlength-1:
curr=self.table[self.current_candidate]
self.join(curr,self.current_candidate)
self.current_candidate+=1
Expand All @@ -291,7 +276,7 @@ def mine(self):
"""
# pass
self._startTime = _ab._time.time()
self.table = {i: {} for i in range(1, 6)}
self.table = {i: {} for i in range(1, self.maxlength)}
self.readData()

self.getfreqs()
Expand All @@ -310,24 +295,4 @@ def mine(self):
self._memoryUSS = float()
self._memoryRSS = float()
self._memoryUSS = process.memory_full_info().uss
self._memoryRSS = process.memory_info().rss


# """Driver code"""

# df=pd.read_csv("data/D1.csv")
# data=df._values[:,1:]
# c=0
# for i in data:
# c+=len(i[1])

# obj = PositionMining(minsup=400,data=data)
# obj.mine()
# interestingPatterns = obj.getPatterns()
# print(interestingPatterns)
# print("Total number of interesting patterns:", len(interestingPatterns))
# obj.save("result.csv")


# print()
# print()
self._memoryRSS = process.memory_info().rss
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import pandas as pd
import numpy as np

class csvParquet():
class CSV2Parquet():
"""
:Description: csvParquet is a code used to convert temporal and utility types into sparse and dense format
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, iFile: str, sep: str='\t'):
self._iFile = iFile
self._sep = sep

def csvParquet(csv_file: str, sep: str, inputType: str, outputType: str) -> None:
def CSV2Parquet(csv_file: str, sep: str, inputType: str, outputType: str) -> None:
inputTypes = ["temporal", "utility"]
outputTypes = ["sparse", "dense"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#
# obj.saveFlatTransactions(oFile)

class FlatTransactions:
class Subgraphs2FlatTransactions:

def __init__(self):
self.flatTransactions = {}

def getFlatTransactions(self, fidGidDictMap):
"""
fidGidMap is a list of dictionaries with keys 'FID' and 'GIDs'
Expand Down Expand Up @@ -44,4 +45,4 @@ def saveFlatTransactions(self, oFile):
"""
with open(oFile, 'w') as f:
for _, fids in self.flatTransactions.items():
f.write(f"{' '.join(map(str, fids))}\n")
f.write(f"{' '.join(map(str, fids))}\n")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self,iFile,minsup,minGTC,minGTPC,maxOR=0.2):
gsp_obj.mine()
self.Sf=gsp_obj.getSubgraphGraphMapping()
self.GetFIDBasedFlatTransactions()
# print("Subgraph mining completed")
print("Subgraph mining completed")

def mine(self):
"""
Expand Down Expand Up @@ -236,4 +236,6 @@ def getRuntime(self):
:return: returning total amount of runtime taken by the mining process
:rtype: float
"""
return self._endTime-self._startTime
return self._endTime-self._startTime


Empty file.
30 changes: 30 additions & 0 deletions PAMI/graphTransactionalCoveragePattern/basic/graph_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random
def generate_random_graph(n, m, max_label,f):
vertices = [(f"v {i}", random.randint(1, max_label)) for i in range(n)]
edges = set()

while len(edges) < m:
u = random.randint(0, n - 1)
v = random.randint(0, n - 1)
label = random.randint(1, max_label)

if u != v and (u, v, label) not in edges:
edges.add((u, v, label))

for vertex in vertices:
s=f"{vertex[0]} {vertex[1]}\n"
f.write(s)

for edge in edges:
s=f"e {edge[0]} {edge[1]} {edge[2]}\n"
f.write(s)


def generate(path, transactions):
f=open(path,"w+")
for t in range(transactions):
f.write("t # {}\n".format(t))
generate_random_graph(random.randint(10,20),random.randint(20,30),3,f)

f.write("t # -1")
f.close()
3 changes: 1 addition & 2 deletions PAMI/sequentialPattern/basic/PrefixSpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from PAMI.sequentialPatternMining.basic import abstract as _ab
from PAMI.sequentialPattern.basic import abstract as _ab
import sys
sys.setrecursionlimit(10000)

Expand Down
2 changes: 1 addition & 1 deletion PAMI/sequentialPattern/basic/SPADE.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import pandas as pd
from deprecated import deprecated

from PAMI.sequentialPatternMining.basic import abstract as _ab
from PAMI.sequentialPattern.basic import abstract as _ab

_ab._sys.setrecursionlimit(10000)

Expand Down
2 changes: 1 addition & 1 deletion PAMI/sequentialPattern/basic/SPAM.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import pandas as pd
from deprecated import deprecated

from PAMI.sequentialPatternMining.basic import abstract as _ab
from PAMI.sequentialPattern.basic import abstract as _ab
_ab._sys.setrecursionlimit(10000)

class SPAM(_ab._sequentialPatterns):
Expand Down
2 changes: 1 addition & 1 deletion PAMI/subgraphMining/topK/tkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def registerAsCandidate(self, subgraph):
def isCanonical(self, c: _ab.DfsCode):
canC = _ab.DfsCode()
for i in range(c.size):
extensions = self.rightMostPathExtensionsFromSingle(canC, _ab.Graph(c))
extensions = self.rightMostPathExtensionsFromSingle(canC, _ab.Graph(-1, None, c))
minEe = None
for ee in extensions.keys():
if minEe is None or ee.smallerThan(minEe):
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
[![Downloads](https://static.pepy.tech/badge/pami)](https://pepy.tech/project/pami)
[![Downloads](https://static.pepy.tech/badge/pami/month)](https://pepy.tech/project/pami)
[![Downloads](https://static.pepy.tech/badge/pami/week)](https://pepy.tech/project/pami)
[![pages-build-deployment](https://github.com/UdayLab/PAMI/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/UdayLab/PAMI/actions/workflows/pages/pages-build-deployment)
[![Dependabot Updates](https://github.com/UdayLab/PAMI/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/UdayLab/PAMI/actions/workflows/dependabot/dependabot-updates)
[![CodeQL](https://github.com/UdayLab/PAMI/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/UdayLab/PAMI/actions/workflows/github-code-scanning/codeql)

[Click here for more information](https://pepy.tech/project/pami)

Expand Down Expand Up @@ -560,6 +563,11 @@ We invite and encourage all community members to contribute, report bugs, fix bu
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Gspan <a target="_blank" href="https://colab.research.google.com/github/UdayLab/PAMI/blob/main/notebooks/subgraphMining/basic/gspan.ipynb"> <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> </a> | TKG <a target="_blank" href="https://colab.research.google.com/github/UdayLab/PAMI/blob/main/notebooks/subgraphMining/topk/tkg.ipynb"> <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> </a> |

#### 11.2. Graph transactional coverage pattern mining
| Basic |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| GTCP<a target="_blank" href="https://colab.research.google.com/github/UdayLab/PAMI/blob/main/notebooks/graphTransactionalCoveragePatterns/basic/GTCP.ipynb"> <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> </a> |

## 12. Additional Features

#### 12.1. Creation of synthetic databases
Expand Down Expand Up @@ -590,6 +598,16 @@ We invite and encourage all community members to contribute, report bugs, fix bu
| Temporal database <a target="_blank" href="https://colab.research.google.com/github/UdayLab/PAMI/blob/main/notebooks/extras/stats/TemporalDatabase.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |
| Utility database (coming soon) |

#### 12.4. Convertors
| Approaches |
|----------------------------|
| Subgraphs2FlatTransactions |
| CSV2Parquet |
| CSV2BitInteger |
| CSV2Integer |



#### 12.4. Generating Latex code for the experimental results
| Approaches |
|--------------------------|
Expand Down
37 changes: 37 additions & 0 deletions notebooks/graphTransactionalCoveragePatterns/basic/GTCP.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 5af66fa

Please sign in to comment.