Commit e49469d0 authored by Fize Jacques's avatar Fize Jacques

- Change vertex_ranking

parent c9d5bf47
......@@ -5,11 +5,9 @@ import numpy as np
cimport numpy as np
from scipy.stats import spearmanr
from .base cimport Base
def intersect(a, b):
return list(set(a) & set(b))
class VertexRanking():
cdef class VertexRanking(Base):
"""
Vertex Ranking
presented in Web graph similarity for anomaly detection, Journal of Internet Services and Applications, 2008 # Maybe not ??
......@@ -18,22 +16,25 @@ class VertexRanking():
Code Author : Jacques Fize
"""
__type__ = "sim"
@staticmethod
def compare(listgs):
cdef int n = len(listgs)
cdef np.ndarray comparison_matrix = np.zeros((n,n))
cdef list page_r=[nx.pagerank(nx.DiGraph(g)) for g in listgs]
cdef list node_intersection
cdef list X
cdef list Y
def __init__(self):
Base.__init__(self,0,True)
cpdef np.ndarray compare(self,list listgs, list selected):
cdef int n,i,j # number of graphs
n = len(listgs)
cdef np.ndarray comparison_matrix = np.zeros((n,n)) #similarity matrix
cdef list X,Y,pager_i,pager_j,page_r,node_intersection #temp data (page rank data for the most part)
page_r=[nx.pagerank(nx.DiGraph(g)) for g in listgs]
for i in range(n):
pager_i=list(page_r[i])
for j in range(i,n):
node_intersection=intersect(list(page_r[i].keys()),list(page_r[j].keys()))
pager_j=list(page_r[j])
node_intersection=list(set(pager_i) & set(pager_j))
X,Y=[],[]
for node in node_intersection:
X.append(page_r[i][node])
Y.append(page_r[j][node])
comparison_matrix[i,j] = spearmanr(X,Y)[0]
comparison_matrix[j,i] = comparison_matrix[i,j]
return comparison_matrix
return np.nan_to_num(comparison_matrix)
import sys, os
import sys, os, shutil
from distutils.core import setup
from distutils.extension import Extension
import numpy as np
try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
......@@ -14,9 +14,15 @@ setup(
name="Gmatch4py",
description="A module for graph matching",
packages=["gmatch4py", "gmatch4py.ged", "gmatch4py.kernels"],
ext_modules=cythonize([Extension("*", ["gmatch4py/*.pyx"])]),
ext_modules=cythonize([Extension("*", ["gmatch4py/*.pyx"],include_dirs=[np.get_include()])]),
cmdclass={'build_ext': build_ext},
setup_requires=["numpy","networkx"],
install_requires=["numpy","networkx"],
version="0.1"
)
#Clean cpp and compiled file
f=False
if f:
if os.path.exists("build"):
shutil.rmtree("build")
os.system("find . -name \*.c -delete ; find . -name \*.cpp -delete ;")
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment