Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hseba/deepdense
  • wmegherbi/deepdense
2 results
Show changes
import numpy as np
def Filewrite2(E,fo):
for i in E:
if len(i) > 5:
stri = "nc "
print("i ",i)
stri = stri + str(i[0]) + ", "
for j in i:
if j != i[0]:
stri = stri + str(j) + " "
strt = stri[-3:]
if ',' not in strt:
fo.write(stri + "\n")
#L = np.load("graph/test_Star.npy", allow_pickle=True)
C = np.load("graph/test_Cliques.npy", allow_pickle=True)
#print(L)
print(C)
T = []
k = []
for i in C:
if i not in k:
x = i
m = i
print("hay x",x)
for j in C:
if j != i and j[0] == i[0]:
x = x+j
[m.append(obj) for obj in x if obj not in m]
k.append(j)
print("X",m)
T.append(m)
print(C)
print(T,len(T))
print(k)
fo = open("example1.model", "a")
Filewrite2(T,fo)
fo.close()
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import time
def Recuperation(G):
#recuperation de tous les noeuds du graph avec une taille > x.
T = []
for i in G.nodes():
if len(G.edges(i)) >= 2:
T.append(i)
Suppression(T,G)
def Suppression(T,G):
#retirer les liens avec les noeuds non recupérer
E = nx.edges(G)
E = np.asarray(E)
M = []
for i in range(len(E)):
if E[i,0] not in T or E[i,1] not in T:
M.append(i)
size = len(E)
E = [v for i,v in enumerate(E) if i not in M]
E = np.array(E)
new_size = len(E)
if size != new_size:
O = nx.Graph()
O.add_edges_from(E, nodetype=int)
Recuperation(O)
else:
O = nx.Graph()
O.add_edges_from(E, nodetype=int)
def Filewrite(E):
stri = "fc "
fo = open("example1.model", "a")
R = []
for i in E:
x = True
for j in E:
if set(i).issubset(set(j)) and i != j:
x = False
if x:
R.append(set(i))
strt = ' '.join(map(str, i))
fo.write(stri + strt + "\n")
fo.close()
print("The file contains: ")
fo = open("example1.model", "r")
dummy = fo.read()
print(dummy)
fo.close()
import os
print(os.path.abspath("example1.model"))
fh = open("C:/Users/LENOVO/Desktop/karate.edgelist", "rb")
G = nx.read_edgelist(fh,nodetype=int)
x = G.number_of_nodes()
print(nx.number_of_nodes(G))
y = x % 100
if y != 0:
for i in range(100-y):
G.add_node(x+i)
start = time.time()
x = list(nx.find_cliques(G))
Filewrite(x)
print(time.time()-start)
start = time.time()
Recuperation(G)
Filewrite(x)
print(time.time()-start)
import networkx as nx
import numpy as np
import time
from ANN_CLIQUES import PatternFinding
from train import Training
from compact import Compact
import matplotlib.pyplot as plt
fh = open("C:/Users/LENOVO/Desktop/karate.edgelist", "rb")
G = nx.read_edgelist(fh,nodetype=int)
#nx.draw(G, node_size = 900)
#plt.show()
W = G.number_of_nodes()
x = list(set(list(G.nodes)))
size = x[len(x)-1]
print("====== Start stars ======")
y = (size+1) % 100
if y != 0:
for i in range(100-y):
G.add_node(W+i)
#print("n",x+i)
total_size = G.number_of_nodes()
#print(total_size)
outU = np.zeros(size + 1 + 100 -y)
U = list(sorted(list(G.nodes)))
start = time.time()
for i in U:
if len(list(G.neighbors(i))) > 1:
outU[i] = 1
outU[list(G.neighbors(i))] = 1
#print(outU)
PatternFinding(G.edges,outU)
Training()
#print(type(G.edges))
#print(G.nodes())
#print(U)
#print("haylik",U[1])
#A = nx.adjacency_matrix(G, nodelist=sorted(G.nodes()), weight='weight')
#A.setdiag(A.diagonal() * 2)
#A = A.todense()
#print(A[0])
#B = copy.deepcopy(A)
#print("ici",list(G.neighbors(91)),len(list(G.neighbors(91))),len(list(G.neighbors(1))))
#fo = open("example1.model", "w")
R = []
for i in range(W):
#stri = "st "
s = []
x = True
v = list(G.neighbors(U[i]))
if (len(v) < 1):
#B[i] = 0
continue
else:
#print(U[i])
#print(U[i])
s.append(U[i])
#fo.write(stri + str(i+1) + ", ")
#stri = stri + str(U[i]) + ", "
#print("voisinnnnnns",U[i],list(G.neighbors(U[i])))
m = sorted(list(G.neighbors(U[i])))
#m = list(U[i]) + m
s = s + m
#stri = stri + str(m) + " "
#for j in m:
# if j not in output:
# output.append(j)
#stri = stri + str(j) + " "
"""
for j in range(W):
#print("ici",len(list(G.neighbors(j+1))))
if G.number_of_edges(U[i], U[j]) >= 1:
#sortie[j] = 1
#fo.write(str(j+1) + " ")
s.append(U[j])
stri = stri + str(U[j]) + " "
if U[j] not in output:
output.append(U[j])
"""
#strt = stri[-3:]
if len(s) > 2:#',' not in strt:
#for j in R:
# if set(s).issubset(set(j)):
# print("babaha", set(s), set(j))
# x = False
#if x:
R.append(s)
# print("sss",stri)
#fo.write(stri + "\n")
#else:
# print("letoile", U[i])
np.save('graph/test_Star.npy', R)
#fo.close()
Compact(R)
print("====== End of step succesful ======")
print("Time",time.time()-start)
#print(len(output),output)
#nx.draw(G,cmap=plt.get_cmap('viridis'),with_labels=True)
#plt.show()
""" ###################################################
M = []
data=[]
x = time.time()
print("debut bendada")
for a,b in G.edges():
data.append([a,b])
y = time.time()
print("fin bendada",y-x,len(list(G.nodes)))
data = np.asarray(data)
data = np.expand_dims(data,axis=0)
np.save('graph/test_Bip.npy',data)
print(data)
Z = nx.Graph()
for i in range(len(sortie)):
#print("i",i)
for j in range(len(sortie)):
if sortie[i] == 1 and sortie[j] == 1 and i != j:
Z.add_edge(str(i),str(j))
#print("Z",Z.edges)
sz = []
T = nx.edges(Z)
T = np.asarray(T)
#print(M,len(M))
#print(output)
########################################
fh = open("C:/Users/LENOVO/Desktop/karate.edgelist", "rb")
print("hay len ya t7a7na", len(T))
E = T
for i in range(len(E)):
#print("ca rentre")
x = E[i, 0]
c = E[i, 1]
#print("x",len(np.argwhere(T == x)))
#print("c",len(np.argwhere(T == c)))
#print("hnnnnnnnaaaaaaaayyyyyyaaaaaaaa",x,np.argwhere(T == x),len(np.argwhere(T == x)))
if (len(np.argwhere(T == x)) < 2) or (len(np.argwhere(T == c)) < 2):
#print("c'est ce lien qui va etre supp " , c , x)
w = -1
t = np.argwhere(T == (x, c))
d = np.argwhere(T == (c, x))
t = np.concatenate((t, d))
for r in range(len(t)):
for k in range(len(t)):
if (t[r, 0] == t[k, 0]) and r != k and w != t[r, 0]:
w = t[r, 0]
break
P = np.delete(T, w, axis=0)
T = P
#################################################
print("====== End of second step ======")
end = time.time()
print("Time",end-start)
sz.append(T)
#print("uuuuuuuuuuuuuuuu uuuuuuuuuuuuuu",sz[0])
#print(np.count_nonzero(A[0] == 1))
#print(np.count_nonzero(sortie == 1))
#print(np.count_nonzero(B == 1))
np.save('graph/test.npy', data)
np.save('graph/sam.npy', sz[0])
#print(sz[0],len(sz[0]))
#O = nx.Graph()
#O.add_edges_from(sz[0],nodetype=int)
#nx.draw(O,cmap=plt.get_cmap('viridis'),with_labels=True)
#plt.show()
np.save('graph/labfin.npy',sortie)
"""
\ No newline at end of file
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import copy
from networkx.algorithms import clique
import time
from ANN_CLIQUES import PatternFinding
from train import Training
def Filewrite(E):
stri = "fc "
fo = open("example1.model", "a")
R = []
for i in E:
#x = True
#for j in E:
# if set(i).issubset(set(j)) and i != j:
# x = False
#if x:
#R.append(set(i))
strt = ' '.join(map(str, i))
fo.write(stri + strt + "\n")
fo.close()
import os
#print(os.path.abspath("example1.model"))
#print("lancement")
fh = open("C:/Users/LENOVO/Desktop/karate.edgelist", "rb")
start = time.time()
G = nx.read_edgelist(fh)
x = G.number_of_nodes()
#print(x)
print("====== Start Cliques ======")
y = x % 100
if y != 0:
for i in range(100-y):
G.add_node(x+i)
total_size = G.number_of_nodes()
cliques = list(clique.find_cliques(G))
flat_list = [sublist for sublist in cliques if len(sublist) > 5]
cliques = np.asarray(([y for x in flat_list for y in x if len(x) >= 5]))
#print("cliques",flat_list,len(flat_list))
fo = open("example1.model", "w")
#fo.write(str(flat_list))
#fo.close()
node_cliques = np.unique(cliques)
nodes_cliques = node_cliques.astype(int)
val_map = {}
key = []
i = 0
values = [val_map.get(node, 0.25) for node in G.nodes()]
""" pour les quasi-cliques
key=np.zeros(G.number_of_nodes())
for clique in cliques:
for node in clique:
val_map[node]=1.0
key[int(node)] = 1
i = i+1
key[nodes_cliques]=1
"""
output = np.zeros(G.number_of_nodes())
output[nodes_cliques] = 1
#print(output)
end = time.time()
print("====== End of first step ======")
print("Time",end-start)
M = []
data=[]
for a,b in G.edges():
data.append([a,b])
data = np.asarray(data)
data = np.expand_dims(data,axis=0)
PatternFinding(G.edges,output)
Training()
Filewrite(flat_list)
np.save('graph/test_Cliques.npy', flat_list)
sz = []
T = nx.edges(G)
E = np.asarray(T)
for i in range(len(E)):
x = E[i, 0]
c = E[i, 1]
if (x not in node_cliques) or (c not in node_cliques):
G.remove_edge(x, c)
T = nx.edges(G)
T = np.asarray(T)
sz.append(T)
#print(sz)
end = time.time()
print("====== End of second step ======")
print("Time",end-start)
np.save('graph/test.npy', data)
np.save('graph/sam.npy', sz[0])
np.save('graph/labfin.npy',output)
f = open("C:/Users/LENOVO/Desktop/karate.edgelist","r")
paragraph = f.readlines()
f1 = open("C:/Users/LENOVO/Desktop/o.txt","w")
print("hna")
r = []
for line in paragraph:
#f1.write(line.strip()+",1\n")
tmp = line.strip().split(',')
print(tmp[0])
print(tmp[1])
#x = []
#x.append(int(tmp[0]))
#x.append(int(tmp[1]))
#if tmp[0] != tmp[1] and sorted(x) not in r:
#r.append(sorted(x))
f1.write(str(int(tmp[0]))+","+str(int(tmp[1]))+"\n")
#f1.write("x["+str(int(tmp[0]))+","+str(int(tmp[1]))+"] <- NA\n")
"""
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(11,17,color='r')
G.add_edge(11,12,color='r')
G.add_edge(11,7,color='r')
G.add_edge(12,17,color='r')
G.add_edge(12,7,color='r')
G.add_edge(12,5,color='r')
G.add_edge(12,6,color='r')
G.add_edge(5,6,color='r')
G.add_edge(5,17,color='r')
G.add_edge(1,17,color='r')
G.add_edge(13,2,color='r')
G.add_edge(10,2,color='r')
G.add_edge(32,24,color='r')
G.add_edge(32,28,color='r')
G.add_edge(24,29,color='r')
G.add_edge(25,24,color='r')
G.add_edge(28,26,color='r')
G.add_edge(28,29,color='r')
G.add_edge(29,26,color='r')
G.add_edge(29,25,color='r')
G.add_edge(5,11,color='g')
G.add_edge(5,7,color='g')
G.add_edge(5,1,color='g')
G.add_edge(6,17,color='g')
G.add_edge(6,7,color='g')
G.add_edge(6,11,color='g')
G.add_edge(1,6,color='g')
G.add_edge(1,7,color='g')
G.add_edge(7,17,color='g')
G.add_edge(1,11,color='g')
G.add_edge(1,12,color='g')
G.add_edge(1,12,color='g')
G.add_edge(2,22,color='g')
G.add_edge(20,2,color='g')
G.add_edge(2,4,color='g')
G.add_edge(2,8,color='g')
G.add_edge(2,3,color='g')
G.add_edge(2,18,color='g')
G.add_edge(2,14,color='g')
G.add_edge(9,34,color='g')
G.add_edge(15,34,color='g')
G.add_edge(16,34,color='g')
G.add_edge(19,34,color='g')
G.add_edge(21,34,color='g')
G.add_edge(23,34,color='g')
G.add_edge(24,28,color='g')
G.add_edge(24,26,color='g')
G.add_edge(25,32,color='g')
G.add_edge(25,28,color='g')
G.add_edge(25,26,color='g')
G.add_edge(26,32,color='g')
G.add_edge(27,34,color='g')
G.add_edge(29,32,color='g')
G.add_edge(30,34,color='g')
G.add_edge(31,34,color='g')
G.add_edge(33,34,color='g')
G.add_edge(1,32,color='black')
G.add_edge(1,22,color='black')
G.add_edge(1,20,color='black')
G.add_edge(1,18,color='black')
G.add_edge(1,14,color='black')
G.add_edge(1,13,color='black')
G.add_edge(1,9,color='black')
G.add_edge(1,8,color='black')
G.add_edge(1,4,color='black')
G.add_edge(1,3,color='black')
G.add_edge(1,2,color='black')
G.add_edge(2,31,color='black')
G.add_edge(3,15,color='black')
G.add_edge(3,9,color='black')
G.add_edge(3,10,color='black')
G.add_edge(3,33,color='black')
G.add_edge(3,29,color='black')
G.add_edge(3,28,color='black')
G.add_edge(3,8,color='black')
G.add_edge(3,4,color='black')
G.add_edge(4,14,color='black')
G.add_edge(4,13,color='black')
G.add_edge(4,8,color='black')
G.add_edge(9,33,color='black')
G.add_edge(10,34,color='black')
G.add_edge(14,34,color='black')
G.add_edge(15,33,color='black')
G.add_edge(16,33,color='black')
G.add_edge(19,33,color='black')
G.add_edge(20,34,color='black')
G.add_edge(21,33,color='black')
G.add_edge(23,33,color='black')
G.add_edge(24,30,color='black')
G.add_edge(24,34,color='black')
G.add_edge(24,33,color='black')
G.add_edge(27,30,color='black')
G.add_edge(28,34,color='black')
G.add_edge(29,34,color='black')
G.add_edge(30,33,color='black')
G.add_edge(31,33,color='black')
G.add_edge(32,34,color='black')
G.add_edge(32,33,color='black')
colors = nx.get_edge_attributes(G,'color').values()
pos = nx.circular_layout(G)
nx.draw(G,
edge_color=colors,
with_labels=True,node_size = 800)
#nx.draw(G, with_labels='True',node_size = 1000, edge_color = ['red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','red','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','green','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black','black'])
plt.show()"""
\ No newline at end of file
File added
File added
from multiprocessing import Pool
from itertools import repeat
import numpy as np
import copy
from compact2 import Compact2
def Filewrite(E):
fo = open("example1.model", "w")
for i in E:
stri = "st "
print("i ",i)
stri = stri + str(i[0]) + ", "
for j in i:
if j != i[0]:
stri = stri + str(j) + " "
strt = stri[-3:]
if ',' not in strt:
fo.write(stri + "\n")
fo.close()
def localisation(L,i):
for j in L:
if j != i and i[0] in j:
i.remove(j[0])
return i
def Compact(flat_list):
print("=======Start compact========")
new_L = []
L2 = copy.deepcopy(flat_list)
for i in range(len(flat_list)):
if len(flat_list[i]) > 2:
for j in range(len(flat_list)):
if len(flat_list[j]) > 2:
x = flat_list[i]
if flat_list[i] != flat_list[j] and x[0] in L2[j]:
y = flat_list[j]
if y[0] in L2[i]:
L2[i].remove(y[0])
new_L.append(L2[i])
np.save('graph/test_Star.npy', new_L)
print("wsel")
Compact2(new_L)
\ No newline at end of file