The Jackson text may seem a bit mathy or formal...but if you are going to study networks, you have to get used to a bit of math.
The most important thing is to take your time and remain calm when you read it:
Graph theory uses a variety of symbols, including set-builder notation:
Set of all i such that i is an element in g...
How is a set different from a Python list???
In [1]:
set([1,2,3,4])
Out[1]:
Set:
Matrix:
Membership:
Owns, has member:
Set such that:
Subset, subset or equal set:
Superset, superset or equal set:
Union:
Intersect:
Anyone remember what the difference between a set union and a set intersect is?
Stats class anyone?
$\sum\limits_{i=1}^ni=1 + 2 + 3 + \dots + n$
IT'S OK! We've still got Python to help us. Let's put all of this in terms we understand.
All of the above statements can be expressed in Python. Translate them!
For example:
# 1
N = set(range(1, 11))
Translate the following:
Hint: Ever looked at the Python docs for set?
In [2]:
# Translate here. Add as many new cells as you like.
In [3]:
sum(range(5))
Out[3]:
What if we need to apply an operation to each element in the summation first?
$\sum\limits_{i=1}^ni^2=1^2 + 2^2 + 3^2 + \dots + n^2$
Implement a one liner in Python that performs the above summation with n = 4.
In [4]:
# One liner here :)
sum(map(lambda x: x * x, range(5)))
Out[4]:
pp. 41-44
Jackson defines a graph as a set $N = \{1,...,n\}$ of n nodes involved in a network of relationships defined as a real valued $n x n$ matrix $g$, where $g_{ij}$ represents the relation between $i$ and $j$.
A network is directed if if it is possible that:
Edges can also be represented as a set of tuples:
A subset of edges:
The network created by deleting all edges except those that are between nodes in the set $S$ where $S \subset N$:
The set of all undirected and unweighted networks on $N$:
The set of nodes that have at least one link in the network $g$:
Can you translate that to set builder speak?
Isomorphism is a mapping (bijection) that preserves edge structure.
Jackson p. 43 one line at a time:
$(N, g)$ and $(N', g')$ are isomorphic if there exists a bijection
$f : N \to N'$ such that
$ij \in g$ if and only if
$f(i)f(j) \in g'$
Page 44-45
Definitions:
A walk is a sequence of links connecting a sequence of nodes.
A cycle is a walk that starts and ends at the same node, with all nodes appearing once except the starting node which also appears as the ending node.
A path is a walk where a node appears at most once in the sequence.
A geodesic between two nodes is a shortest path between them.
Formally...
A path in a network $g \in G(N)$ betgween nodes $i$ and $j$ is a sequence of links
$i_1,i_2,\dots,i_{K-1},i_K$ such that
$i_ki_{k+1} \in g$ for each
$k \in \{1,\dots,K-1\}$, with
$i_1 = i$ and $i_K = j$, and such that each node in the sequence
$i_1,\dots,i_K$ is distinct.
A walk in a network $g \in G(N)$ betgween nodes $i$ and $j$ is a sequence of links
$i_1,i_2,\dots,i_{K-1},i_K$ such that
$i_kI_{k+1} \in g$ for each
$k \in \{1,\dots,K-1\}$, with
$i_1 = i$ and $i_K = j$
WAIT! WHAT'S THE DIFFERENCE BETWEEN A PATH AND A WALK AGAIN?
Remember that a network is connected (path connected) if every two nodes in the network are connected by some path in the network.
A component of a network $(N,g)$, is a nonempty subnetwork $(N',g')$ such that $\emptyset \ne N' \subset N, g' \subset g, $ and
Set of components of a network $(N,g)$ is denoted $C(N,g)$
pp. 50-51
The neighborhood of a node i is the set of nodes that i is linked to.
Given some set of nodes $S$, the neighborhood of $S$ is the union of the neighborhoods of its members:
We can also extend the neighborhood of a node, remember we tried to do this in class 4...
pp. 51
The degree of node is the number of links that are connected to it.
A node $i$'s degree in a network $g$, denoted $d_i(g)$ is:
Degree distribution is one of the fundamental ways to describe a graph. It describes the relative frequencies of the nodes that have different degrees in the graph.
Look at the following examples. Is their anything about the structure of the two graphs that strikes you as different?
In [5]:
# Config environment for code examples.
%matplotlib inline
import networkx as nx
import matplotlib as plt
plt.rcParams['figure.figsize'] = 17, 12
In [6]:
g = nx.scale_free_graph(40).to_undirected()
nx.draw_networkx(g)
In [7]:
g = nx.gnp_random_graph(40, 0.1)
nx.draw_networkx(g)
pp. 61-65
Degree centrality - a normalized measure of a node's connectivity:
Closeness centrality - a the inverse of the average distance between $i$ and any other node:
Betweenness centrality - the proportion of how many shortest paths a node lies on averaged across all pairs of nodes in a network:
Use NetworkX to generate a scale free graph and a gnp random graph, then plot the degree distribution of each graph...
HINTS:
nx.degree(graph)
plt.scatter(xvals, yvals)
plt.yscale("log")
plt.xscale("log")
In [8]:
def degree_distribution(g):
"""
:param g: networkx.Graph
:returns ?: whatever you need to plot the degree distribution.
"""
pass
# Here you can either script or write a function to plot the degree distributions.
# Use as many cells as you need.