You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

py-graph_test.ipynb 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "autoscroll": false,
  8. "ein.tags": "worksheet-0",
  9. "slideshow": {
  10. "slide_type": "-"
  11. }
  12. },
  13. "outputs": [],
  14. "source": [
  15. "import numpy as np\n",
  16. "import paths\n",
  17. "\n",
  18. "import pygraph\n",
  19. "\n",
  20. "from pygraph.utils.graphfiles import loadDataset\n"
  21. ]
  22. },
  23. {
  24. "cell_type": "code",
  25. "execution_count": 2,
  26. "metadata": {
  27. "autoscroll": false,
  28. "ein.tags": "worksheet-0",
  29. "slideshow": {
  30. "slide_type": "-"
  31. }
  32. },
  33. "outputs": [],
  34. "source": [
  35. "import networkx as nx\n",
  36. "import numpy as np\n",
  37. "import matplotlib.pyplot as plt\n",
  38. "\n",
  39. "# We load a ds dataset\n",
  40. "# load it from https://brunl01.users.greyc.fr/CHEMISTRY/Acyclic.tar.gz\n",
  41. "dataset, y = loadDataset(\"/home/bgauzere/work/Datasets/Acyclic/dataset_bps.ds\")"
  42. ]
  43. },
  44. {
  45. "cell_type": "code",
  46. "execution_count": 3,
  47. "metadata": {
  48. "autoscroll": false,
  49. "ein.tags": "worksheet-0",
  50. "slideshow": {
  51. "slide_type": "-"
  52. }
  53. },
  54. "outputs": [
  55. {
  56. "name": "stderr",
  57. "output_type": "stream",
  58. "text": [
  59. "100%|██████████| 183/183 [07:41<00:00, 2.52s/it]\n",
  60. "100%|██████████| 183/183 [08:39<00:00, 2.84s/it]\n",
  61. "100%|██████████| 183/183 [05:19<00:00, 1.75s/it]\n",
  62. "100%|██████████| 183/183 [05:50<00:00, 1.91s/it]\n"
  63. ]
  64. }
  65. ],
  66. "source": [
  67. "#Compute graph edit distances\n",
  68. "\n",
  69. "from tqdm import tqdm\n",
  70. "from pygraph.c_ext.lsape_binders import lsap_solverHG\n",
  71. "from pygraph.ged.costfunctions import ConstantCostFunction\n",
  72. "from pygraph.ged.GED import ged\n",
  73. "import time\n",
  74. "\n",
  75. "cf = ConstantCostFunction(1,3,1,3)\n",
  76. "N=len(dataset)\n",
  77. "\n",
  78. "methods=['Riesen + LSAP', 'Neigh + LSAP', 'Riesen + LSAPE', 'Neigh + LSAPE']\n",
  79. "ged_distances = [ np.zeros((N,N)), np.zeros((N,N)), np.zeros((N,N)), np.zeros((N,N))]\n",
  80. "\n",
  81. "times = list()\n",
  82. "start = time.clock()\n",
  83. "for i in tqdm(range(0,N)):\n",
  84. " for j in range(0,N):\n",
  85. " ged_distances[0][i,j] = ged(dataset[i],dataset[j],cf=cf, method='Riesen')[0]\n",
  86. "times.append(time.clock() - start)\n",
  87. "\n",
  88. "\n",
  89. "start = time.clock()\n",
  90. "for i in tqdm(range(0,N)):\n",
  91. " for j in range(0,N):\n",
  92. " ged_distances[1][i,j] = ged(dataset[i],dataset[j],cf=cf, method='Neighboorhood')[0]\n",
  93. "\n",
  94. "times.append(time.clock() - start)\n",
  95. "\n",
  96. "start = time.clock()\n",
  97. "for i in tqdm(range(0,N)):\n",
  98. " for j in range(0,N):\n",
  99. " ged_distances[2][i,j] = ged(dataset[i],dataset[j],cf=cf, method='Riesen',solver=lsap_solverHG)[0]\n",
  100. "times.append(time.clock() - start)\n",
  101. "\n",
  102. "start = time.clock()\n",
  103. "for i in tqdm(range(0,N)):\n",
  104. " for j in range(0,N):\n",
  105. " ged_distances[3][i,j] = ged(dataset[i],dataset[j],cf=cf, method='Neighboorhood',solver=lsap_solverHG)[0]\n",
  106. "times.append(time.clock() - start)"
  107. ]
  108. },
  109. {
  110. "cell_type": "code",
  111. "execution_count": 5,
  112. "metadata": {
  113. "autoscroll": false,
  114. "ein.tags": "worksheet-0",
  115. "slideshow": {
  116. "slide_type": "-"
  117. }
  118. },
  119. "outputs": [
  120. {
  121. "name": "stdout",
  122. "output_type": "stream",
  123. "text": [
  124. " method \t mean \t mean \t time\n",
  125. " Riesen + LSAP \t 37.79903849025053 \t 35.31207262086058 \t 463.300405 \n",
  126. " Neigh + LSAP \t 36.2281047508137 \t 33.85869987159963 \t 521.7821730000001 \n",
  127. " Riesen + LSAPE \t 35.95508973095643 \t 34.10092866314312 \t 319.83455500000014 \n",
  128. " Neigh + LSAPE \t 34.5005822807489 \t 32.5735614679447 \t 350.48029599999995 \n"
  129. ]
  130. }
  131. ],
  132. "source": [
  133. "print(\" method \\t mean \\t mean \\t time\")\n",
  134. "data = list()\n",
  135. "for i in range(0,len(ged_distances)):\n",
  136. " ged_ = np.minimum(ged_distances[i],ged_distances[i].transpose())\n",
  137. " print(\" {} \\t {} \\t {} \\t {} \".format(methods[i], np.mean(ged_distances[i]),np.mean(ged_), times[i]))\n"
  138. ]
  139. },
  140. {
  141. "cell_type": "code",
  142. "execution_count": null,
  143. "metadata": {},
  144. "outputs": [],
  145. "source": []
  146. }
  147. ],
  148. "metadata": {
  149. "kernelspec": {
  150. "display_name": "Python 3",
  151. "language": "python",
  152. "name": "python3"
  153. },
  154. "language_info": {
  155. "codemirror_mode": {
  156. "name": "ipython",
  157. "version": 3
  158. },
  159. "file_extension": ".py",
  160. "mimetype": "text/x-python",
  161. "name": "python",
  162. "nbconvert_exporter": "python",
  163. "pygments_lexer": "ipython3",
  164. "version": "3.5.2"
  165. },
  166. "name": "py-graph_test.ipynb"
  167. },
  168. "nbformat": 4,
  169. "nbformat_minor": 2
  170. }

A Python package for graph kernels, graph edit distances and graph pre-image problem.