Explore Directed Networks

Complex Network Analysis in Python — by Dmitry Zinoviev (81 / 91)

The Pragmatic Programmers
The Pragmatic Programmers
5 min readJan 28, 2021

👈 Discover Asymmetric Relationships | TOC | Apply Topological Sort to Directed Acycli c Graphs 👉

The directedness of edges dramatically affects almost all network measures and structural elements. Let’s have a look at some affected properties. As an example, let’s use a directed network of the top three preferred migration destinations for each state in 2015, constructed from the United States Census Bureau State-to-State Migration Flows dataset.[56] You can find the Python code for the network construction in the file migrations.py. The picture shows the network sketch (the meaning of the colors will be explained laterhere).

images/migration.png

Degree

Each node in a directed graph G has three degrees: G.in_degree (the number of incoming incident edges), G.out_degree (the number of outgoing incident edges), and the total G.degree (the number of all edges). These methods return InDegreeView, OutDegreeView, and DiDegreeView objects, respectively. Note that the total degree is the sum of the indegree and outdegree.

The indegree and total degrees of the migration graph designate the most attractive destinations (which are, not surprisingly, sunny California, Florida, and Texas). By construction, all nodes have the same outdegree of 3.

​ sorted(dict(G.in_degree()).items(), key=​lambda​ x: x[1], reverse=True)[:3]
​ sorted(dict(G.out_degree()).items(),key=​lambda​ x: x[1], reverse=True)[:3]
​ sorted(dict(G.degree()).items(), key=​lambda​ x: x[1], reverse=True)[:3]
​<= [('CA', 21), ('FL', 17), ('TX', 16)]
​ [('KY', 3), ('MT', 3), ('MS', 3)]
​ [('CA', 24), ('FL', 20), ('TX', 19)]

Neighbors

A node in a directed graph has two types of neighbors: G.successors (reachable through the outgoing edges) and G.predecessors (reachable through the incoming edges). The method G.neighbors is another name of G.successors. In the migration network, the successors of the final_destination (CA) are the preferred destinations of the outgoing migration. The successors are the states from which migrants come to California.

​ final_destination = sorted(dict(G.in_degree().items())…

Read the full story with a free account.

The author made this story available to Medium members only.
Sign up to read this one for free.

Or, continue in mobile web

Already have an account? Sign in

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.

Lists

See more recommendations