Skip to content

Commit

Permalink
feat(notebook): filter edges for structures graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Dec 1, 2023
1 parent 0206bde commit 911b630
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions notebooks/communityDetectionStructures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
],
Expand All @@ -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",
Expand All @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": 143,
"execution_count": 183,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -237,7 +237,7 @@
},
{
"cell_type": "code",
"execution_count": 144,
"execution_count": 197,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
}
Expand All @@ -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)"
]
},
{
Expand Down

0 comments on commit 911b630

Please sign in to comment.