From 911b630137d8ae87a138d01ffa92fdf30371ece1 Mon Sep 17 00:00:00 2001 From: victor barbier Date: Mon, 30 Oct 2023 17:21:22 +0100 Subject: [PATCH] feat(notebook): filter edges for structures graph --- notebooks/communityDetectionStructures.ipynb | 41 +++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/notebooks/communityDetectionStructures.ipynb b/notebooks/communityDetectionStructures.ipynb index eb0597cf..5eaf8ba4 100644 --- a/notebooks/communityDetectionStructures.ipynb +++ b/notebooks/communityDetectionStructures.ipynb @@ -184,14 +184,14 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 182, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Number of nodes (structures) found : 978\n" + "Number of nodes (structures) found : 1641\n" ] } ], @@ -203,9 +203,9 @@ " work_id = work.get(\"id\")\n", " for affiliation in work.get(\"affiliations\") or {}:\n", " affiliation_id = affiliation.get(\"id\")\n", - " country = affiliation.get(\"address\")[0].get(\"country\") if (\"address\" in affiliation) else None\n", + " # country = affiliation.get(\"address\")[0].get(\"country\") if (\"address\" in affiliation) else None\n", " gps = affiliation.get(\"address\")[0].get(\"gps\") if (\"address\" in affiliation) else None\n", - " if affiliation_id and gps and country == \"France\":\n", + " if affiliation_id and gps:\n", " if affiliation_id in nodes_dict:\n", " nodes_dict[affiliation_id][\"publications\"].append(work_id)\n", " else:\n", @@ -221,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": 183, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +237,7 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 197, "metadata": {}, "outputs": [], "source": [ @@ -249,54 +249,56 @@ " G.add_node(node.get(\"id\"), label=node.get(\"name\"), weight=len(node.get(\"publications\")))\n", "\n", "# Add edges\n", + "min_weight_edge = 10\n", "for edge in edges:\n", - " G.add_edge(edge.get(\"source\"), edge.get(\"target\"), weight=edge.get(\"weight\"))" + " if edge.get(\"weight\") > min_weight_edge:\n", + " G.add_edge(edge.get(\"source\"), edge.get(\"target\"), weight=edge.get(\"weight\"))" ] }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 198, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Graph filtered : 96 \n", - "Minimum number of works required: 24\n" + "Graph filtered : 100 \n", + "Minimum number of works required: 25\n" ] } ], "source": [ "# Filter graph\n", "max_order = 100\n", - "min_weight = 1\n", + "min_weight_node = 1\n", "\n", "while G.order() > max_order:\n", - " min_weight += 1\n", - " G = G.subgraph([node for node, attrdict in G.nodes.items() if attrdict.get(\"weight\") >= min_weight]) \n", + " min_weight_node += 1\n", + " G = G.subgraph([node for node, attrdict in G.nodes.items() if attrdict.get(\"weight\") >= min_weight_node]) \n", " # print(f\"Minimum number of works auto computed : {min_weight} (order={G.order()})\")\n", "\n", - "print(f\"Graph filtered : {len(G.nodes) or 0} \\nMinimum number of works required: {min_weight}\")" + "print(f\"Graph filtered : {len(G.nodes) or 0} \\nMinimum number of works required: {min_weight_node}\")" ] }, { "cell_type": "code", - "execution_count": 181, + "execution_count": 199, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d333909ccf6541cdb87b0c7cd4e53c74", + "model_id": "0d6ef99c0f354e77af5469a8d6f8cfbd", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Sigma(nx.Graph with 96 nodes and 2,019 edges)" + "Sigma(nx.Graph with 100 nodes and 540 edges)" ] }, - "execution_count": 181, + "execution_count": 199, "metadata": {}, "output_type": "execute_result" } @@ -309,7 +311,8 @@ " node_border_color_from=\"node\",\n", " # layout=nodes_dict,\n", " default_edge_type=\"curve\",\n", - " hide_edges_on_move=True)" + " hide_edges_on_move=True,\n", + " start_layout=1)" ] }, {