initial push
This commit is contained in:
commit
738a3cc530
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,124 @@
|
|||
0;0
|
||||
1;0
|
||||
2;0
|
||||
3;0
|
||||
4;0
|
||||
5;0
|
||||
6;0
|
||||
7;0
|
||||
8;0
|
||||
9;0
|
||||
10;0
|
||||
11;0
|
||||
12;0
|
||||
13;0
|
||||
14;0
|
||||
15;0
|
||||
16;0
|
||||
17;0
|
||||
18;1
|
||||
19;0
|
||||
20;0
|
||||
21;0
|
||||
22;0
|
||||
23;0
|
||||
24;0
|
||||
25;0
|
||||
26;0
|
||||
27;0
|
||||
28;0
|
||||
29;0
|
||||
30;0
|
||||
31;0
|
||||
32;0
|
||||
33;0
|
||||
34;0
|
||||
35;0
|
||||
36;1
|
||||
37;0
|
||||
38;0
|
||||
39;0
|
||||
40;0
|
||||
41;0
|
||||
42;0
|
||||
43;0
|
||||
44;0
|
||||
45;1
|
||||
46;0
|
||||
47;0
|
||||
48;0
|
||||
49;0
|
||||
50;0
|
||||
51;0
|
||||
52;0
|
||||
53;0
|
||||
54;0
|
||||
55;0
|
||||
56;0
|
||||
57;0
|
||||
58;0
|
||||
59;0
|
||||
60;0
|
||||
61;0
|
||||
62;0
|
||||
63;0
|
||||
64;0
|
||||
65;0
|
||||
66;1
|
||||
67;0
|
||||
68;0
|
||||
69;0
|
||||
70;0
|
||||
71;0
|
||||
72;0
|
||||
73;0
|
||||
74;0
|
||||
75;0
|
||||
76;0
|
||||
77;0
|
||||
78;0
|
||||
79;0
|
||||
80;1
|
||||
81;0
|
||||
82;0
|
||||
83;0
|
||||
84;0
|
||||
85;0
|
||||
86;0
|
||||
87;0
|
||||
88;0
|
||||
89;0
|
||||
90;0
|
||||
91;0
|
||||
92;0
|
||||
93;0
|
||||
94;0
|
||||
95;0
|
||||
96;0
|
||||
97;0
|
||||
98;0
|
||||
99;0
|
||||
100;0
|
||||
101;0
|
||||
102;0
|
||||
103;0
|
||||
104;0
|
||||
105;0
|
||||
106;0
|
||||
107;0
|
||||
108;0
|
||||
109;0
|
||||
110;0
|
||||
111;0
|
||||
112;0
|
||||
113;0
|
||||
114;0
|
||||
115;0
|
||||
116;0
|
||||
117;0
|
||||
118;0
|
||||
119;0
|
||||
120;1
|
||||
121;0
|
||||
122;0
|
||||
123;0
|
|
@ -0,0 +1,124 @@
|
|||
B00004Y7S5,0
|
||||
6305940959,1
|
||||
B000087EY0,2
|
||||
1558908412,3
|
||||
B00008DDR8,4
|
||||
B00004R997,5
|
||||
6305942331,6
|
||||
B000063V8G,7
|
||||
B00005JKHN,8
|
||||
B00004R995,9
|
||||
B00004R993,10
|
||||
B00001U0DR,11
|
||||
B0000640VM,12
|
||||
B000063V8M,13
|
||||
B0000694ZS,14
|
||||
B00005JL96,15
|
||||
B00004R999,16
|
||||
B00005JKX4,17
|
||||
B00005T5YC,18
|
||||
6304711921,19
|
||||
B00008Y47T,20
|
||||
1558908404,21
|
||||
B00005RDSQ,22
|
||||
B00005RDSN,23
|
||||
B000085EF7,24
|
||||
B00005RDST,25
|
||||
B00003CXHS,26
|
||||
B000087EXZ,27
|
||||
B0000683BE,28
|
||||
6304711867,29
|
||||
B0000524D0,30
|
||||
0788816462,31
|
||||
B00003CXQ7,32
|
||||
630595027X,33
|
||||
B00005JLR2,34
|
||||
B00005JMB3,35
|
||||
B00006LPHB,36
|
||||
B000089799,37
|
||||
B000068QPM,38
|
||||
B00005RDSM,39
|
||||
B00005O06B,40
|
||||
1558908374,41
|
||||
B00003CXWJ,42
|
||||
B000065V3X,43
|
||||
B00001TZ6K,44
|
||||
B00004R99B,45
|
||||
B00004R99D,46
|
||||
6305090602,47
|
||||
B00004R99F,48
|
||||
B00007ELG3,49
|
||||
B00004R99H,50
|
||||
B00007LVCT,51
|
||||
6305616027,52
|
||||
B00004U9WR,53
|
||||
B00004R99J,54
|
||||
B00004U9WQ,55
|
||||
B00006LPAJ,56
|
||||
B00004R99L,57
|
||||
B000065V43,58
|
||||
B00004R99O,59
|
||||
B000065V44,60
|
||||
B00004R99Q,61
|
||||
B00004R99S,62
|
||||
B00004R99U,63
|
||||
B00004R99W,64
|
||||
B00004R99Y,65
|
||||
B00005T7HD,66
|
||||
B00005A1RF,67
|
||||
B00001QEBQ,68
|
||||
6305784116,69
|
||||
B00003CWPX,70
|
||||
B000096IAI,71
|
||||
B0000649EQ,72
|
||||
B000089G5O,73
|
||||
B00005T7H7,74
|
||||
B00005KAQJ,75
|
||||
B00005T7H5,76
|
||||
B00003CX9W,77
|
||||
B00005T7H3,78
|
||||
6305320950,79
|
||||
B00004T2SJ,80
|
||||
B00003CXCQ,81
|
||||
B00008432O,82
|
||||
B00008432N,83
|
||||
B000068NLQ,84
|
||||
B00006SFIP,85
|
||||
B000035Z50,86
|
||||
B000068NLS,87
|
||||
B000068NLR,88
|
||||
B00005K9OE,89
|
||||
B000068NLT,90
|
||||
B00003CX8Y,91
|
||||
B000050MN3,92
|
||||
B00005K9OF,93
|
||||
B000059XUT,94
|
||||
B000035Z48,95
|
||||
B0000764K0,96
|
||||
B000068MC6,97
|
||||
B00001QEE8,98
|
||||
B00005AR3G,99
|
||||
B00001QEE9,100
|
||||
B00001QEE6,101
|
||||
B00001QEE7,102
|
||||
6305950547,103
|
||||
B00001QEE4,104
|
||||
B00001QEE5,105
|
||||
B000059TCE,106
|
||||
B000068MBO,107
|
||||
B00001QEE2,108
|
||||
B00001QEE3,109
|
||||
B000059TCD,110
|
||||
B00003CXB4,111
|
||||
B00004R9A0,112
|
||||
B000035Z2T,113
|
||||
6305949980,114
|
||||
B00003CXQY,115
|
||||
B00004R9A4,116
|
||||
B00005JKDR,117
|
||||
B00004R9A6,118
|
||||
B000059Z8M,119
|
||||
B00004WL3E,120
|
||||
B00005KARI,121
|
||||
B00005TN8K,122
|
||||
B00005KARK,123
|
|
Binary file not shown.
|
@ -0,0 +1,53 @@
|
|||
import xmltodict
|
||||
import numpy as np
|
||||
|
||||
def raw():
|
||||
with open("Disney.graphml","r") as f:
|
||||
return xmltodict.parse(f.read())
|
||||
|
||||
def basic_parse():
|
||||
d=raw()
|
||||
d=d["graphml"]
|
||||
d=d["graph"]
|
||||
nodes=d["node"]
|
||||
edges=d["edge"]
|
||||
|
||||
return nodes,edges
|
||||
|
||||
def read():
|
||||
nodes,edges=basic_parse()
|
||||
nodes=[{"id":int(zw["@id"]),"data":[float(zx["#text"]) for zx in zw["data"]]} for zw in nodes]
|
||||
|
||||
edges=[[int(zw["@source"]),int(zw["@target"])] for zw in edges]
|
||||
|
||||
nodes.sort(key=lambda x:x["id"])
|
||||
nodes=[zw["data"] for zw in nodes]
|
||||
|
||||
return nodes,edges
|
||||
|
||||
def adj():
|
||||
n,e=read()
|
||||
a=np.zeros((len(n),len(n)))
|
||||
for e1,e2 in e:
|
||||
a[e1,e2]=1.0
|
||||
a[e2,e1]=1.0
|
||||
a=np.expand_dims(a,axis=0)
|
||||
n=np.array(n)
|
||||
n=np.expand_dims(n,axis=0)
|
||||
return a,n
|
||||
|
||||
def load_true():
|
||||
with open("Disney.true","r") as f:
|
||||
q=f.read().split("\n")
|
||||
return np.array([";1" in zw for zw in q if len(zw.strip())>2])
|
||||
|
||||
if __name__ == "__main__":
|
||||
a,n=adj()
|
||||
|
||||
t=load_true()
|
||||
|
||||
#print(t.shape,np.mean(t),np.sum(t))
|
||||
|
||||
np.savez_compressed("data",x=n,a=a,t=t)
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
import tensorflow.compat.v1 as tf
|
||||
tf.disable_v2_behavior()
|
||||
|
||||
import grapa as g
|
||||
from grapa.functionals import *
|
||||
from grapa.layers import *
|
||||
from grapa.constants import *
|
||||
|
||||
keras=tf.keras
|
||||
K=keras.backend
|
||||
|
||||
from data import adj
|
||||
|
||||
|
||||
A,X=adj()
|
||||
|
||||
data=np.concatenate((X,A),axis=2)
|
||||
|
||||
|
||||
def createmodel():
|
||||
i=Input(shape=data.shape[1:])#define your input
|
||||
gs=int(data.shape[1])#find the number of initial nodes
|
||||
param=int(data.shape[2])-gs#find the number of features per node
|
||||
g=grap(state(gs=gs,param=param))#create a grap object for use in the functional api
|
||||
g.X,g.A=gcutparam(gs=gs,param1=param,param2=gs)([i])#set the current feature vector and adjacency matrix of your grap object by cutting the input
|
||||
|
||||
m=getm()#get the standart constant file
|
||||
|
||||
xx=g.X#save this value, since it is the initial comparison variable
|
||||
|
||||
g=gnl(g,m)#a single graph update step
|
||||
|
||||
oparam=g.s.param#save the number of parameters, to assert that after the ae step this number is still the same
|
||||
|
||||
|
||||
#g=compress(g,m,5,12)#execute one compression step, reducing gs nodes into gs/5 nodes and adding 12 features to each node
|
||||
|
||||
#g=gll(g,m,k=4)#a new graph update step. Here gll means relearning of your graph using a topk (k=4) algorithm
|
||||
|
||||
#m.decompress="paramlike"#choose paramlike decompression
|
||||
|
||||
#g,com,i2=decompress(g,m,5)#decompress by a factor of 5 (gs/5 nodes -> gs nodes)
|
||||
|
||||
g=gnl(g,m)#a final graph update step, using the graph generated in the decompression step
|
||||
|
||||
g=remparam(g,oparam)#remove to many parameters again
|
||||
|
||||
return i,g
|
||||
return handlereturn(i,xx,com,i2,g.X,False)#this function uses compression input, initial comparison, compressed state,decompression input,decompressed version, run as a variational autoencoder
|
||||
|
||||
|
||||
def prepare():
|
||||
i,g=createmodel()#returns z1,z2, which are the same since we dont use a vae,
|
||||
|
||||
model=Model(i,g)
|
||||
|
||||
plot_model(model,to_file="model.png",show_shapes=True)#save model plots
|
||||
|
||||
loss=mse(g,K.ones_like(g))#loss is mse
|
||||
loss=K.mean(loss)
|
||||
|
||||
#if shallvae:
|
||||
# kl_loss=-0.5*K.mean(1+z2-K.square(z1)-K.exp(z2))
|
||||
# loss+=kl_loss
|
||||
|
||||
model.add_loss(loss)
|
||||
model.compile(Adam(lr=lr))#we use the adam optimizer
|
||||
model.summary()
|
||||
#plot_model(vae,to_file=f"{nam}.png",show_shapes=True)
|
||||
|
||||
return model
|
||||
|
||||
if __name__ == '__main__':
|
||||
model=prepare()
|
||||
|
Loading…
Reference in New Issue