{ "cells": [ { "cell_type": "markdown", "id": "dee32b11-7922-44f4-a587-e118c0e1b793", "metadata": {}, "source": [ "# Dynamic Networks\n", "\n", "Dynamic, or temporal, networks are a special subset of multilayer networks that allow you to examine changes in a network over time. NetworkX currently has no functionality for dynamic networks, so you'll use the Python library [Teneto](https://teneto.readthedocs.io/en/latest/).\n", "\n", "## Creating TemporalNetwork Objects" ] }, { "cell_type": "code", "execution_count": 1, "id": "2976a937-0352-4d5d-aaac-6a1ff7f474ed", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/jrladd/Library/Python/3.9/lib/python/site-packages/nilearn/input_data/__init__.py:23: FutureWarning: The import path 'nilearn.input_data' is deprecated in version 0.9. Importing from 'nilearn.input_data' will be possible at least until release 0.13.0. Please import from 'nilearn.maskers' instead.\n", " warnings.warn(message, FutureWarning)\n" ] } ], "source": [ "import networkx as nx\n", "import pandas as pd\n", "\n", "# Import the main Teneto object:\n", "from teneto import TemporalNetwork\n", "# Import the network measures you'll need:\n", "from teneto.networkmeasures import *" ] }, { "cell_type": "markdown", "id": "15824835-76a5-4ccf-b0ec-a4828bf7fc7a", "metadata": {}, "source": [ "Teneto's `TemporalNetwork` objects are different from NetworkX's `Graph` objects. You need to have a third column in your edge table that indicates the timespan in which that edge exists. This isn't a date or a pair of dates/times but rather a sequential number that indicates what \"slice\" that edge is in. Many edges will wind up being in more than one \"time slice\".\n", "\n", "This time column is typicall expressed as `t` in your graph. If you have an edgelist that includes start and stop dates, you'll need to convert these into sequential groups. Below is an example of how to do that using the *Six Degrees of Francis Bacon* Quakers network. But keep in mind that this is an idiosyncratic example and your original data may format time in a different way." ] }, { "cell_type": "code", "execution_count": 13, "id": "c6870e8e-feb5-45dc-89bf-4810c3aee461", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | i | \n", "j | \n", "t | \n", "
---|---|---|---|
0 | \n", "122 | \n", "28 | \n", "4 | \n", "
1 | \n", "122 | \n", "28 | \n", "5 | \n", "
2 | \n", "122 | \n", "167 | \n", "4 | \n", "
3 | \n", "122 | \n", "167 | \n", "5 | \n", "
4 | \n", "122 | \n", "127 | \n", "4 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
939 | \n", "163 | \n", "74 | \n", "5 | \n", "
940 | \n", "163 | \n", "74 | \n", "6 | \n", "
941 | \n", "74 | \n", "2 | \n", "5 | \n", "
942 | \n", "74 | \n", "2 | \n", "6 | \n", "
943 | \n", "74 | \n", "2 | \n", "7 | \n", "
944 rows × 3 columns
\n", "\n", " | i | \n", "j | \n", "t | \n", "
---|---|---|---|
0 | \n", "122 | \n", "28 | \n", "4 | \n", "
1 | \n", "122 | \n", "28 | \n", "5 | \n", "
2 | \n", "122 | \n", "167 | \n", "4 | \n", "
3 | \n", "122 | \n", "167 | \n", "5 | \n", "
4 | \n", "122 | \n", "127 | \n", "4 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
939 | \n", "163 | \n", "74 | \n", "5 | \n", "
940 | \n", "163 | \n", "74 | \n", "6 | \n", "
941 | \n", "74 | \n", "2 | \n", "5 | \n", "
942 | \n", "74 | \n", "2 | \n", "6 | \n", "
943 | \n", "74 | \n", "2 | \n", "7 | \n", "
944 rows × 3 columns
\n", "