Skip to content

Commit 261a4d2

Browse files
authored
Merge pull request #1 from GemsLab/evaluation
Evaluation --> Master
2 parents 4384f72 + 514e85b commit 261a4d2

44 files changed

Lines changed: 78546 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

12 KB
Binary file not shown.

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,16 @@ cython_debug/
143143

144144
# backup files
145145
*.bak
146+
147+
# Mac OS file
148+
*.DS_Store
149+
150+
# struc2vec pickles and random walks
151+
semb/methods/struc2vec/pickles/
152+
semb/methods/struc2vec/random_walks.txt
153+
154+
# drne intermediate files
155+
semb/methods/drne/eni/
156+
157+
# riwalk intermediate files
158+
semb/methods/riwalk/walks/

Untitled.ipynb

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"graphwave\n",
13+
"drne\n"
14+
]
15+
},
16+
{
17+
"name": "stderr",
18+
"output_type": "stream",
19+
"text": [
20+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:493: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
21+
" _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
22+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:494: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
23+
" _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
24+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:495: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
25+
" _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
26+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:496: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
27+
" _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
28+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:497: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
29+
" _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
30+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:502: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
31+
" np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
32+
]
33+
},
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"node2vec\n",
39+
"role2vec\n",
40+
"line\n",
41+
"struc2vec\n",
42+
"xnetmf\n",
43+
"multilens\n",
44+
"segk\n",
45+
"riwalk\n"
46+
]
47+
},
48+
{
49+
"name": "stderr",
50+
"output_type": "stream",
51+
"text": [
52+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.\n",
53+
" warnings.warn(msg, category=DeprecationWarning)\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"from semb.methods import load as load_method\n",
59+
"from semb.methods import get_method_ids\n",
60+
"for mid in get_method_ids():\n",
61+
" print(mid)\n",
62+
" load_method(mid)"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 2,
68+
"metadata": {},
69+
"outputs": [
70+
{
71+
"name": "stdout",
72+
"output_type": "stream",
73+
"text": [
74+
"airports\n"
75+
]
76+
}
77+
],
78+
"source": [
79+
"from semb.datasets import load as load_dataset\n",
80+
"from semb.datasets import get_dataset_ids\n",
81+
"for did in get_dataset_ids():\n",
82+
" print(did)\n",
83+
" load_dataset(did)"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 3,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"ename": "AttributeError",
93+
"evalue": "'Graph' object has no attribute 'N'",
94+
"output_type": "error",
95+
"traceback": [
96+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
97+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
98+
"\u001b[0;32m<ipython-input-3-b934f906c1fe>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mnode2vec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNode2VecMethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbrazil_airport_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m128\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mnode2vec\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0memb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnode2vec\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_embeddings\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
99+
"\u001b[0;32m~/GoogleDrive/UM/S4/GEMS/Git/StrucEmbeddingLibrary/semb/methods/xnetmf/method.py\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 15\u001b[0m alpha=self.params['discount'], gammastruc=self.params['gamma']) \n\u001b[1;32m 16\u001b[0m \u001b[0;31m# FIXME: this doesnt look like a standard embeddings format\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m \u001b[0mrepresentations\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_representations\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrep_method\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 18\u001b[0m \u001b[0mlist_nodes\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0membeddings\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
100+
"\u001b[0;32m~/GoogleDrive/UM/S4/GEMS/Git/StrucEmbeddingLibrary/semb/methods/xnetmf/internal/xnetmf.py\u001b[0m in \u001b[0;36mget_representations\u001b[0;34m(graph, rep_method, verbose)\u001b[0m\n\u001b[1;32m 165\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_representations\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrep_method\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;31m#Node identity extraction\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 167\u001b[0;31m \u001b[0mfeature_matrix\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_features\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrep_method\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 168\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 169\u001b[0m \u001b[0;31m#Efficient similarity-based representation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
101+
"\u001b[0;32m~/GoogleDrive/UM/S4/GEMS/Git/StrucEmbeddingLibrary/semb/methods/xnetmf/internal/xnetmf.py\u001b[0m in \u001b[0;36mget_features\u001b[0;34m(graph, rep_method, verbose)\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0mbefore_khop\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;31m#Get k-hop neighbors of all nodes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 102\u001b[0;31m \u001b[0mkhop_neighbors_nobfs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_khop_neighbors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrep_method\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 103\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkhop_neighbors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkhop_neighbors_nobfs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
102+
"\u001b[0;32m~/GoogleDrive/UM/S4/GEMS/Git/StrucEmbeddingLibrary/semb/methods/xnetmf/internal/xnetmf.py\u001b[0m in \u001b[0;36mget_khop_neighbors\u001b[0;34m(graph, rep_method)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;31m#only 0-hop neighbor of a node is itself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;31m#neighbors of a node have nonzero connections to it in adj matrix\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mnode\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0mneighbors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnonzero\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mG_adj\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m###\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mneighbors\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m#disconnected node\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
103+
"\u001b[0;31mAttributeError\u001b[0m: 'Graph' object has no attribute 'N'"
104+
]
105+
}
106+
],
107+
"source": [
108+
"from semb.methods import load as load_method\n",
109+
"from semb.datasets import load as load_dataset\n",
110+
"\n",
111+
"Node2VecMethod = load_method(\"xnetmf\")\n",
112+
"AirportDataProvider = load_dataset(\"airports\")\n",
113+
"airport_datasets = AirportDataProvider().get_datasets()\n",
114+
"brazil_airport_graph = AirportDataProvider().load_dataset(airport_datasets[0])\n",
115+
"\n",
116+
"node2vec = Node2VecMethod(brazil_airport_graph, dim=128)\n",
117+
"node2vec.train()\n",
118+
"emb = node2vec.get_embeddings()"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": []
127+
}
128+
],
129+
"metadata": {
130+
"kernelspec": {
131+
"display_name": "SEMB",
132+
"language": "python",
133+
"name": "semb"
134+
},
135+
"language_info": {
136+
"codemirror_mode": {
137+
"name": "ipython",
138+
"version": 3
139+
},
140+
"file_extension": ".py",
141+
"mimetype": "text/x-python",
142+
"name": "python",
143+
"nbconvert_exporter": "python",
144+
"pygments_lexer": "ipython3",
145+
"version": "3.6.2"
146+
}
147+
},
148+
"nbformat": 4,
149+
"nbformat_minor": 2
150+
}

Untitled1.ipynb

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"graphwave\n",
13+
"degree2\n",
14+
"drne\n"
15+
]
16+
},
17+
{
18+
"name": "stderr",
19+
"output_type": "stream",
20+
"text": [
21+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:493: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
22+
" _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
23+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:494: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
24+
" _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
25+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:495: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
26+
" _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
27+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:496: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
28+
" _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
29+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:497: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
30+
" _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
31+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:502: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
32+
" np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
33+
]
34+
},
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"node2vec\n",
40+
"degree\n",
41+
"role2vec\n",
42+
"line\n",
43+
"degree1\n",
44+
"struc2vec\n",
45+
"xnetmf\n",
46+
"multilens\n",
47+
"segk\n"
48+
]
49+
},
50+
{
51+
"name": "stderr",
52+
"output_type": "stream",
53+
"text": [
54+
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.\n",
55+
" warnings.warn(msg, category=DeprecationWarning)\n"
56+
]
57+
},
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
"riwalk\n"
63+
]
64+
}
65+
],
66+
"source": [
67+
"from semb.methods import load as load_method\n",
68+
"from semb.methods import get_method_ids\n",
69+
"for mid in get_method_ids():\n",
70+
" print(mid)\n",
71+
" load_method(mid)"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 2,
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"name": "stdout",
81+
"output_type": "stream",
82+
"text": [
83+
"airports\n"
84+
]
85+
}
86+
],
87+
"source": [
88+
"from semb.datasets import load as load_dataset\n",
89+
"from semb.datasets import get_dataset_ids\n",
90+
"for did in get_dataset_ids():\n",
91+
" print(did)\n",
92+
" load_dataset(did)"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 3,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"from semb.methods import load as load_method\n",
102+
"from semb.datasets import load as load_dataset\n",
103+
"\n",
104+
"Node2VecMethod = load_method(\"segk\")\n",
105+
"AirportDataProvider = load_dataset(\"airports\")\n",
106+
"airport_datasets = AirportDataProvider().get_datasets()\n",
107+
"brazil_airport_graph = AirportDataProvider().load_dataset(airport_datasets[0])\n",
108+
"\n",
109+
"node2vec = Node2VecMethod(brazil_airport_graph)\n",
110+
"node2vec.train()\n",
111+
"emb = node2vec.get_embeddings()"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": []
120+
}
121+
],
122+
"metadata": {
123+
"kernelspec": {
124+
"display_name": "SEMB",
125+
"language": "python",
126+
"name": "semb"
127+
},
128+
"language_info": {
129+
"codemirror_mode": {
130+
"name": "ipython",
131+
"version": 3
132+
},
133+
"file_extension": ".py",
134+
"mimetype": "text/x-python",
135+
"name": "python",
136+
"nbconvert_exporter": "python",
137+
"pygments_lexer": "ipython3",
138+
"version": "3.6.2"
139+
}
140+
},
141+
"nbformat": 4,
142+
"nbformat_minor": 4
143+
}

0 commit comments

Comments
 (0)