|
| 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 | +} |
0 commit comments