Clique algorithms (taken from NetworkX)
This commit is contained in:
parent
e30f30b0f9
commit
26b7ce87a5
3 changed files with 269 additions and 70 deletions
122
usa_roads.ipynb
122
usa_roads.ipynb
|
@ -2,7 +2,7 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -21,7 +21,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -37,7 +37,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -46,29 +46,14 @@
|
|||
"slide_type": "-"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"version: 2.26 (commit b89e6b4e, Thu Nov 9 14:55:43 2017 +0000)\n",
|
||||
"gcc version: 7.2.0\n",
|
||||
"compilation flags: -DNDEBUG -D_FORTIFY_SOURCE=2 -fopenmp -O3 -fvisibility=default -fvisibility-inlines-hidden -Wno-deprecated -Wall -Wextra -ftemplate-backtrace-limit=0 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now\n",
|
||||
"install prefix: /usr\n",
|
||||
"python dir: /usr/lib/python3.6/site-packages\n",
|
||||
"graph filtering: True\n",
|
||||
"openmp: True\n",
|
||||
"uname: Linux asha 4.15.6-1-ARCH #1 SMP PREEMPT Sun Feb 25 12:53:23 UTC 2018 x86_64\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gt.show_config()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -85,7 +70,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -101,7 +86,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -110,16 +95,7 @@
|
|||
"slide_type": "-"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<Graph object, directed, with 264347 vertices and 733846 edges at 0x7fde8465c2b0>\n",
|
||||
"distance (edge) (type: int32_t)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(G)\n",
|
||||
"G.list_properties()"
|
||||
|
@ -127,7 +103,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -136,18 +112,7 @@
|
|||
"slide_type": "-"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"PropertyArray([ 803, 842, 2428, ..., 1158, 323, 368], dtype=int32)"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dist = G.ep.get(\"distance\")\n",
|
||||
"dist.get_array()"
|
||||
|
@ -155,7 +120,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -164,16 +129,7 @@
|
|||
"slide_type": "-"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0.6327185812827214\n",
|
||||
"464318\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"filt = G.new_edge_property(\"bool\")\n",
|
||||
"filt.a = dist.a > 800\n",
|
||||
|
@ -184,7 +140,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"autoscroll": false,
|
||||
"collapsed": false,
|
||||
|
@ -193,18 +149,7 @@
|
|||
"slide_type": "-"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"PropertyArray([ 1, 2, 3, ..., 34918, 36421, 36946], dtype=int32)"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ordered_dist = dist.get_array()\n",
|
||||
"ordered_dist = np.unique(np.sort(ordered_dist))\n",
|
||||
|
@ -223,6 +168,45 @@
|
|||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import clique as cl"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"condmat = gt.collection.data[\"cond-mat-2005\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"clique_sizes = []\n",
|
||||
"for c in cl.find_cliques(condmat):\n",
|
||||
" clique_sizes.append(len(c))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"ax.hist(clique_sizes, bins=100);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue