821 lines
29 KiB
Plaintext
821 lines
29 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "af118d77-d87a-4687-be5b-e810a24c403e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-07-03 14:30:30 +0000 | io:INFO | Loaded TOML config file successfully.\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"A:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\transformers\\utils\\generic.py:441: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
|
" _torch_pytree._register_pytree_node(\n",
|
|
"A:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\huggingface_hub\\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n",
|
|
" warnings.warn(\n",
|
|
"A:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\transformers\\utils\\generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
|
" _torch_pytree._register_pytree_node(\n",
|
|
"A:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\transformers\\utils\\generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
|
" _torch_pytree._register_pytree_node(\n",
|
|
"A:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\huggingface_hub\\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n",
|
|
" warnings.warn(\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from lang_main import io\n",
|
|
"from lang_main.analysis.graphs import rescale_edge_weights\n",
|
|
"\n",
|
|
"from pathlib import Path\n",
|
|
"import pickle\n",
|
|
"import base64\n",
|
|
"\n",
|
|
"import numpy as np"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "4256081a-6364-4e8f-8cfd-799912ca6b94",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"res_path = Path(r'A:\\Arbeitsaufgaben\\lang-main\\scripts\\results\\test_20240619')\n",
|
|
"assert res_path.exists()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "e9a92ad6-5e63-49c4-b9e7-9f81da8549fe",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#obj = 'TK-GRAPH_POSTPROCESSING.pkl'\n",
|
|
"obj = 'TK-GRAPH_ANALYSIS.pkl'\n",
|
|
"load_pth = res_path / obj\n",
|
|
"assert load_pth.exists()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "c2421d89-ed8c-41dd-b363-ad5b5b716704",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-07-03 14:30:35 +0000 | io:INFO | Loaded file successfully.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"ret = io.load_pickle(load_pth)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "ca25a7f2-84af-4b5e-89d6-b139fca35617",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"tkg = ret[0]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "ff7e7ab6-67d9-4a2c-b668-cf10740f7542",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"TokenGraph(name: TokenGraph, number of nodes: 143, number of edges: 163)"
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"tkg"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "f0df3580-cea5-48cc-bdbc-2927dd446e1b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import networkx as nx\n",
|
|
"from alph import alph, layout\n",
|
|
"import altair as alt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f042b302-fa3c-45b0-8d7a-7a68b66bf595",
|
|
"metadata": {},
|
|
"source": [
|
|
"layout_fn=lambda g: nx.spring_layout(\n",
|
|
" g,\n",
|
|
" weight=\"weight\",\n",
|
|
" k=20,\n",
|
|
" iterations=5000,\n",
|
|
" seed=42\n",
|
|
" ),\n",
|
|
"layout_fn=lambda g: layout.force_atlas_sknet(\n",
|
|
" g,\n",
|
|
" n_iter=1000,\n",
|
|
" gravity_factor=0.01,\n",
|
|
" repulsive_factor=0.1,\n",
|
|
" init_seed=42,\n",
|
|
" ),\n",
|
|
"layout_fn=lambda g: nx.nx_agraph.pygraphviz_layout(\n",
|
|
" g,\n",
|
|
" prog=\"fdp\",\n",
|
|
" args='-GK=5'\n",
|
|
" ),\n",
|
|
"layout_fn=lambda g: nx.nx_agraph.pygraphviz_layout(\n",
|
|
" g,\n",
|
|
" prog=\"sfdp\",\n",
|
|
" args='-GK=5 -Gbeautify=true -Goverlap=true'\n",
|
|
" ),\n",
|
|
"layout_fn=lambda g: nx.nx_agraph.pygraphviz_layout(\n",
|
|
" g,\n",
|
|
" prog=\"neato\",\n",
|
|
" args='-Goverlap=false'\n",
|
|
" ),"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "04d3d857-37cb-420e-8426-b1465d94efae",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"alph_params = dict(\n",
|
|
" weight_attr=\"weight\",\n",
|
|
" layout_fn=lambda g: nx.nx_agraph.pygraphviz_layout(\n",
|
|
" g,\n",
|
|
" prog=\"sfdp\",\n",
|
|
" args='-GK=5 -Gbeautify=true -Goverlap=true'\n",
|
|
" ),\n",
|
|
" node_args=dict(\n",
|
|
" size=alt.Size(\n",
|
|
" \"degree_centrality\",\n",
|
|
" scale=alt.Scale(domain=[0,1], range=[12**2, 40**2]),\n",
|
|
" legend=None\n",
|
|
" ),\n",
|
|
" #fill=alt.Color(\n",
|
|
" # \"degree_centrality\",\n",
|
|
" # scale=alt.Scale(domain=companies, range=palette),\n",
|
|
" #),\n",
|
|
" stroke=\"#333\",\n",
|
|
" strokeWidth=alt.Size(\n",
|
|
" \"degree_centrality\",\n",
|
|
" scale=alt.Scale(domain=[0,1], range=[2, 5]),\n",
|
|
" legend=None\n",
|
|
" ),\n",
|
|
" tooltip_attrs=[\"id\"],\n",
|
|
" label_attr=\"id\",\n",
|
|
" ),\n",
|
|
" edge_args=dict(\n",
|
|
" color=\"#000\",\n",
|
|
" ),\n",
|
|
" width=800,\n",
|
|
" height=600,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 104,
|
|
"id": "ae68d7d6-9e95-4a99-ac41-98a294afcca2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"tkg = Gtest.copy()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 105,
|
|
"id": "64e6a5c1-e42d-4ad2-8c32-5cf62bc75852",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"nx.set_node_attributes(tkg, {\n",
|
|
" n: {\n",
|
|
" \"id\": n,\n",
|
|
" } for n in tkg.nodes\n",
|
|
"})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 106,
|
|
"id": "7e895f70-74a2-433c-91c2-a440303ab81a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"nx.set_node_attributes(tkg, nx.degree_centrality(tkg), \"degree_centrality\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 107,
|
|
"id": "a13cc710-01d8-4f52-b066-3796b4609118",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "TypeError",
|
|
"evalue": "decoding to str: need a bytes-like object, NoneType found",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
|
|
"Cell \u001b[1;32mIn[107], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43malph\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtkg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43malph_params\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mconfigure_view(strokeWidth\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m)\n",
|
|
"File \u001b[1;32mA:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\alph\\core.py:195\u001b[0m, in \u001b[0;36malph\u001b[1;34m(G, weight_attr, layout_fn, node_args, edge_args, combo_group_by, combo_node_additional_attrs, combo_layout_fn, combo_node_args, combo_edge_args, combo_empty_attr_action, combo_size_scale_domain, combo_size_scale_range, combo_inner_graph_scale_factor, combo_edge_weight_agg_attr, combo_edge_agg_attrs, combo_edge_weight_threshold, include_edgeless_combo_nodes, non_serializable_datetime_format, width, height, prop_kwargs, padding, nodes_layer_params)\u001b[0m\n\u001b[0;32m 193\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 194\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m layout_fn:\n\u001b[1;32m--> 195\u001b[0m pos \u001b[38;5;241m=\u001b[39m \u001b[43mlayout_fn\u001b[49m\u001b[43m(\u001b[49m\u001b[43mG\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 196\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 197\u001b[0m pos \u001b[38;5;241m=\u001b[39m layout\u001b[38;5;241m.\u001b[39mdefault_network_layout(G, weight_attr\u001b[38;5;241m=\u001b[39mweight_attr)\n",
|
|
"Cell \u001b[1;32mIn[66], line 3\u001b[0m, in \u001b[0;36m<lambda>\u001b[1;34m(g)\u001b[0m\n\u001b[0;32m 1\u001b[0m alph_params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m(\n\u001b[0;32m 2\u001b[0m weight_attr\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mweight\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m----> 3\u001b[0m layout_fn\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m g: \u001b[43mnx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnx_agraph\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpygraphviz_layout\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43mg\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mprog\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43msfdp\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m-GK=5 -Gbeautify=true -Goverlap=true\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\n\u001b[0;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m,\n\u001b[0;32m 8\u001b[0m node_args\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mdict\u001b[39m(\n\u001b[0;32m 9\u001b[0m size\u001b[38;5;241m=\u001b[39malt\u001b[38;5;241m.\u001b[39mSize(\n\u001b[0;32m 10\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdegree_centrality\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 11\u001b[0m scale\u001b[38;5;241m=\u001b[39malt\u001b[38;5;241m.\u001b[39mScale(domain\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m1\u001b[39m], \u001b[38;5;28mrange\u001b[39m\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m12\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m40\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m]),\n\u001b[0;32m 12\u001b[0m legend\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 13\u001b[0m ),\n\u001b[0;32m 14\u001b[0m \u001b[38;5;66;03m#fill=alt.Color(\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \u001b[38;5;66;03m# \"degree_centrality\",\u001b[39;00m\n\u001b[0;32m 16\u001b[0m \u001b[38;5;66;03m# scale=alt.Scale(domain=companies, range=palette),\u001b[39;00m\n\u001b[0;32m 17\u001b[0m \u001b[38;5;66;03m#),\u001b[39;00m\n\u001b[0;32m 18\u001b[0m stroke\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m#333\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 19\u001b[0m strokeWidth\u001b[38;5;241m=\u001b[39malt\u001b[38;5;241m.\u001b[39mSize(\n\u001b[0;32m 20\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdegree_centrality\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 21\u001b[0m scale\u001b[38;5;241m=\u001b[39malt\u001b[38;5;241m.\u001b[39mScale(domain\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m1\u001b[39m], \u001b[38;5;28mrange\u001b[39m\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m5\u001b[39m]),\n\u001b[0;32m 22\u001b[0m legend\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 23\u001b[0m ),\n\u001b[0;32m 24\u001b[0m tooltip_attrs\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m 25\u001b[0m label_attr\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 26\u001b[0m ),\n\u001b[0;32m 27\u001b[0m edge_args\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mdict\u001b[39m(\n\u001b[0;32m 28\u001b[0m color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m#000\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 29\u001b[0m ),\n\u001b[0;32m 30\u001b[0m width\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m800\u001b[39m,\n\u001b[0;32m 31\u001b[0m height\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m600\u001b[39m,\n\u001b[0;32m 32\u001b[0m )\n",
|
|
"File \u001b[1;32mA:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\networkx\\drawing\\nx_agraph.py:307\u001b[0m, in \u001b[0;36mpygraphviz_layout\u001b[1;34m(G, prog, root, args)\u001b[0m\n\u001b[0;32m 305\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m root \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 306\u001b[0m args \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m-Groot=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mroot\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m--> 307\u001b[0m A \u001b[38;5;241m=\u001b[39m \u001b[43mto_agraph\u001b[49m\u001b[43m(\u001b[49m\u001b[43mG\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 308\u001b[0m A\u001b[38;5;241m.\u001b[39mlayout(prog\u001b[38;5;241m=\u001b[39mprog, args\u001b[38;5;241m=\u001b[39margs)\n\u001b[0;32m 309\u001b[0m node_pos \u001b[38;5;241m=\u001b[39m {}\n",
|
|
"File \u001b[1;32mA:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\networkx\\drawing\\nx_agraph.py:159\u001b[0m, in \u001b[0;36mto_agraph\u001b[1;34m(N)\u001b[0m\n\u001b[0;32m 157\u001b[0m \u001b[38;5;66;03m# add nodes\u001b[39;00m\n\u001b[0;32m 158\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m n, nodedata \u001b[38;5;129;01min\u001b[39;00m N\u001b[38;5;241m.\u001b[39mnodes(data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[1;32m--> 159\u001b[0m \u001b[43mA\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_node\u001b[49m\u001b[43m(\u001b[49m\u001b[43mn\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 160\u001b[0m \u001b[38;5;66;03m# Add node data\u001b[39;00m\n\u001b[0;32m 161\u001b[0m a \u001b[38;5;241m=\u001b[39m A\u001b[38;5;241m.\u001b[39mget_node(n)\n",
|
|
"File \u001b[1;32mA:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\pygraphviz\\agraph.py:338\u001b[0m, in \u001b[0;36mAGraph.add_node\u001b[1;34m(self, n, **attr)\u001b[0m\n\u001b[0;32m 336\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m:\n\u001b[0;32m 337\u001b[0m nh \u001b[38;5;241m=\u001b[39m gv\u001b[38;5;241m.\u001b[39magnode(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandle, n, _Action\u001b[38;5;241m.\u001b[39mcreate)\n\u001b[1;32m--> 338\u001b[0m node \u001b[38;5;241m=\u001b[39m \u001b[43mNode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnh\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnh\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 339\u001b[0m node\u001b[38;5;241m.\u001b[39mattr\u001b[38;5;241m.\u001b[39mupdate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mattr)\n",
|
|
"File \u001b[1;32mA:\\Arbeitsaufgaben\\lang-main\\.venv\\Lib\\site-packages\\pygraphviz\\agraph.py:1861\u001b[0m, in \u001b[0;36mNode.__new__\u001b[1;34m(self, graph, name, nh)\u001b[0m\n\u001b[0;32m 1859\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__new__\u001b[39m(\u001b[38;5;28mself\u001b[39m, graph, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, nh\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m 1860\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m nh \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1861\u001b[0m n \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__new__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43magnameof\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnh\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgraph\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1862\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1863\u001b[0m n \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__new__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name)\n",
|
|
"\u001b[1;31mTypeError\u001b[0m: decoding to str: need a bytes-like object, NoneType found"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"alph(tkg, **alph_params).configure_view(strokeWidth=0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 65,
|
|
"id": "842e01fa-29cd-4028-9461-c7af24e01c33",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'id': 'Wartungstätigkeit', 'degree_centrality': 0.04225352112676056}"
|
|
]
|
|
},
|
|
"execution_count": 65,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"tkg.nodes['Wartungstätigkeit']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8d36d22e-73fd-44fe-ab08-98f8186bc6b2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "14efa0e8-0937-44da-a76c-160829a7e9bf",
|
|
"metadata": {},
|
|
"source": [
|
|
"**additional info:**\n",
|
|
"- overlap removal for sfdp Graphviz algorithm not available because of missing triangulation library (only available on Linux)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bfc0f3a7-8865-4b44-bd9c-2c3f4ff9e70e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "1e61aca3-efea-4e38-8174-5ca4b2585256",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"obj = 'TK-GRAPH_POSTPROCESSING.pkl'\n",
|
|
"# obj = 'TK-GRAPH_ANALYSIS.pkl'\n",
|
|
"load_pth = res_path / obj\n",
|
|
"assert load_pth.exists()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "5d83c04c-03ab-4086-a4e9-ae430e4c6090",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-07-03 14:30:35 +0000 | io:INFO | Loaded file successfully.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"ret = io.load_pickle(load_pth)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "4718b54e-0891-4f70-8c67-90c439bc8bfd",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"tkg = ret[0]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "ddcb4ff0-eac4-45ba-9c6e-83ada4b0276c",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"TokenGraph(name: TokenGraph, number of nodes: 6028, number of edges: 17950)"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"tkg"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "97c46ca7-ca9f-4d11-8d86-cfbd819b7573",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "f6fc2c6a-2171-411d-92f1-4ab694adda7b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Gtest = rescale_edge_weights(tkg)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "859be6a3-a919-433a-a0a7-f4d74cdc6bf7",
|
|
"metadata": {},
|
|
"source": [
|
|
"break_early = False\n",
|
|
"i = 0\n",
|
|
"for idx, (node1, node2) in enumerate(list(Gtest.edges)):\n",
|
|
" if break_early and i == 10:\n",
|
|
" break\n",
|
|
" Gtest[node1][node2]['weight'] = adjusted_weights[idx]\n",
|
|
" \n",
|
|
" i += 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "f381b25a-6149-4a2a-876c-4cbd8bb9bd04",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Wartungstätigkeit Vorgabe 1.0\n",
|
|
"Wartungstätigkeit Maschinenhersteller 1.0\n",
|
|
"Wartungstätigkeit Maschinenbediener 0.8215\n",
|
|
"Wartungstätigkeit Laserabteilung 0.8215\n",
|
|
"Wartungstätigkeit Arbeitsplan 0.8219\n",
|
|
"Wartungstätigkeit abarbeiten 0.8215\n",
|
|
"Wartungstätigkeit Webmaschinenkontrollliste 0.2534\n",
|
|
"Wartungstätigkeit sehen 0.2534\n",
|
|
"Vorgabe Maschinenhersteller 1.0\n",
|
|
"Vorgabe Wartungsplan 0.9181\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"break_early = True\n",
|
|
"i = 0\n",
|
|
"for n1, n2, w in Gtest.edges.data('weight'):\n",
|
|
" if break_early and i == 10:\n",
|
|
" break\n",
|
|
" print(n1, n2, w)\n",
|
|
"\n",
|
|
" i += 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "c45a8136-2a81-4ede-a087-cf86ce85d939",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-07-03 14:30:39 +0000 | graphs:INFO | Successfully converted graph to one with undirected edges.\n",
|
|
"2024-07-03 14:30:39 +0000 | graphs:INFO | Graph properties: 6028 Nodes, 17554 Edges\n",
|
|
"2024-07-03 14:30:39 +0000 | graphs:INFO | Node memory: 373.36 KB\n",
|
|
"2024-07-03 14:30:39 +0000 | graphs:INFO | Edge memory: 959.98 KB\n",
|
|
"2024-07-03 14:30:39 +0000 | graphs:INFO | Total memory: 1333.34 KB\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"Gtest.to_undirected(inplace=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "303d8d0c-9320-4739-adf6-ac9ba82731de",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"id": "a7929935-3bd2-4eb8-907c-4d37251f11ea",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Wartungstätigkeit Vorgabe 1.0\n",
|
|
"Wartungstätigkeit Maschinenhersteller 1.0\n",
|
|
"Wartungstätigkeit sehen 0.2533999979496002\n",
|
|
"Wartungstätigkeit Maschinenbediener 0.8215000033378601\n",
|
|
"Wartungstätigkeit Laserabteilung 0.8215000033378601\n",
|
|
"Wartungstätigkeit Arbeitsplan 0.8219000101089478\n",
|
|
"Wartungstätigkeit abarbeiten 0.8215000033378601\n",
|
|
"Wartungstätigkeit Webmaschinenkontrollliste 0.2533999979496002\n",
|
|
"Vorgabe Maschinenhersteller 1.0\n",
|
|
"Vorgabe Wartungsplan 0.9180999994277954\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"break_early = True\n",
|
|
"i = 0\n",
|
|
"for n1, n2, w in Gtest.undirected.edges.data('weight'):\n",
|
|
" if break_early and i == 10:\n",
|
|
" break\n",
|
|
" print(n1, n2, w)\n",
|
|
"\n",
|
|
" i += 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"id": "4df89d59-3832-4b6d-9eae-b3220b6f7e5b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'num_nodes': 6028,\n",
|
|
" 'num_edges': 17554,\n",
|
|
" 'min_edge_weight': 0.09520000219345093,\n",
|
|
" 'max_edge_weight': 1.7527999877929688,\n",
|
|
" 'node_memory': 382321,\n",
|
|
" 'edge_memory': 983024,\n",
|
|
" 'total_memory': 1365345}"
|
|
]
|
|
},
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"Gtest.metadata_undirected"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"id": "adf02de4-f22c-499f-91bf-ac1be1b3186f",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'num_nodes': 6028,\n",
|
|
" 'num_edges': 17950,\n",
|
|
" 'min_edge_weight': 0.0952,\n",
|
|
" 'max_edge_weight': 1.0,\n",
|
|
" 'node_memory': 382321,\n",
|
|
" 'edge_memory': 1005200,\n",
|
|
" 'total_memory': 1387521}"
|
|
]
|
|
},
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"Gtest.metadata_directed"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9e939c9c-ba9e-4576-9d85-afba8481af93",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"id": "bfafdc8b-418d-4dd8-b986-d36082ba870e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"c_comps = nx.connected_components(Gtest.undirected)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"id": "abf5603d-dab9-49a0-8c86-d2429a36d24d",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"5714\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"4\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"3\n",
|
|
"4\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"4\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"4\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"4\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n",
|
|
"3\n",
|
|
"2\n",
|
|
"2\n",
|
|
"2\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for comp in c_comps:\n",
|
|
" print(len(comp))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "80db8d16-fa48-417d-91b0-37e5b32f3b74",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b2e2cbbe-68ef-4ea0-9ed0-b114be1efd08",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "fcd9247f-c4f9-4f73-9fd3-2ab56700073f",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"You are connected to Cytoscape!\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'apiVersion': 'v1',\n",
|
|
" 'cytoscapeVersion': '3.10.2',\n",
|
|
" 'automationAPIVersion': '1.9.0',\n",
|
|
" 'py4cytoscapeVersion': '1.9.0'}"
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import py4cytoscape as py4\n",
|
|
"dir(py4)\n",
|
|
"py4.cytoscape_ping()\n",
|
|
"py4.cytoscape_version_info()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b9290659-e33c-47fc-8d89-7aa3dd6e843a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.9"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|