Skip to content

Commit

Permalink
chap 4 updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziaeemehr committed Aug 22, 2024
1 parent 029d477 commit be7a9bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Network Science, Barabási, 2013

<img src="cover.jpeg" alt="Cover Image" width="300" height="auto">

#### How to use
- using on Colab (Recommended)

Expand Down
47 changes: 44 additions & 3 deletions docs/examples/chap_04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
},
Expand All @@ -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",
Expand Down

0 comments on commit be7a9bc

Please sign in to comment.