From be7a9bc371358cecbbf317661e850ce9f4e36395 Mon Sep 17 00:00:00 2001 From: Ziaeemehr Date: Thu, 22 Aug 2024 13:41:58 +0200 Subject: [PATCH] chap 4 updated. --- README.md | 2 ++ docs/examples/chap_04.ipynb | 47 ++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4247ae8..ddc00cd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ - Network Science, Barabási, 2013 +Cover Image + #### How to use - using on Colab (Recommended) diff --git a/docs/examples/chap_04.ipynb b/docs/examples/chap_04.ipynb index a0ab653..a13f0ac 100644 --- a/docs/examples/chap_04.ipynb +++ b/docs/examples/chap_04.ipynb @@ -142,10 +142,51 @@ "from netsci.utils import list_sample_graphs, load_sample_graph\n", "from netsci.analysis import graph_info\n", "\n", + "# on colab:\n", + "nets = ['Collaboration', 'Internet', 'PowerGrid', 'Protein', 'PhoneCalls', 'Citation', 'Metabolic', 'Email', 'WWW', 'Actor']\n", + "\n", + "# on local:\n", "nets = list(list_sample_graphs().keys())\n", "print(nets)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### On Google Colab only" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.colab import drive\n", + "import os\n", + "\n", + "# URL of the zip file to be downloaded\n", + "url = \"https://networksciencebook.com/translations/en/resources/networks.zip\"\n", + "# Mount Google Drive\n", + "drive.mount('/content/drive')\n", + "# Create the 'network_science' directory in MyDrive if it doesn't exist\n", + "network_science_dir = '/content/drive/MyDrive/network_science'\n", + "os.makedirs(network_science_dir, exist_ok=True)\n", + "# empty the directory\n", + "!rm -rf /content/drive/MyDrive/network_science/*\n", + "# Change directory to 'network_science'\n", + "os.chdir(network_science_dir)\n", + "# Download the zip file to the 'network_science' directory\n", + "!wget $url -O networks.zip\n", + "# Unzip the downloaded file in the 'network_science' directory\n", + "!unzip networks.zip\n", + "\n", + "json_file = \"https://raw.githubusercontent.com/Ziaeemehr/netsci/main/netsci/datasets/sample_graphs.json\"\n", + "# download json file\n", + "!wget $json_file -O sample_graphs.json" + ] + }, { "cell_type": "code", "execution_count": 5, @@ -182,7 +223,7 @@ "from scipy.stats import poisson\n", "\n", "\n", - "G_collab = load_sample_graph(\"Collaboration\")\n", + "G_collab = load_sample_graph(\"Collaboration\") # on colab: add colab_path=network_science_dir\n", "graph_info(G_collab, quick=True)\n", "degrees = list(dict(G_collab.degree()).values())\n", "degree_count = Counter(degrees)\n", @@ -450,7 +491,7 @@ "from netsci.utils import load_sample_graphi\n", "\n", "# download_sample_dataset()\n", - "sample_graph_names = list(list_sample_graphs().keys())\n", + "sample_graph_names = list(list_sample_graphs().keys()) # not on colab\n", "sample_graph_names" ] }, @@ -472,7 +513,7 @@ "graphs = {}\n", "\n", "for name in tqdm(sample_graph_names, desc=\"processing graphs\"):\n", - " G = load_sample_graphi(name)\n", + " G = load_sample_graphi(name) # on colab: add colab_path=network_science_dir\n", " directed = G.is_directed()\n", " if directed:\n", " in_degrees = G.degree(mode=\"in\")\n",