Book Image

Network Science with Python and NetworkX Quick Start Guide

By : Edward L. Platt
Book Image

Network Science with Python and NetworkX Quick Start Guide

By: Edward L. Platt

Overview of this book

NetworkX is a leading free and open source package used for network science with the Python programming language. NetworkX can track properties of individuals and relationships, find communities, analyze resilience, detect key network locations, and perform a wide range of important tasks. With the recent release of version 2, NetworkX has been updated to be more powerful and easy to use. If you’re a data scientist, engineer, or computational social scientist, this book will guide you in using the Python programming language to gain insights into real-world networks. Starting with the fundamentals, you’ll be introduced to the core concepts of network science, along with examples that use real-world data and Python code. This book will introduce you to theoretical concepts such as scale-free and small-world networks, centrality measures, and agent-based modeling. You’ll also be able to look for scale-free networks in real data and visualize a network using circular, directed, and shell layouts. By the end of this book, you’ll be able to choose appropriate network representations, use NetworkX to build and characterize networks, and uncover insights while working with real-world systems.
Table of Contents (15 chapters)

What is a network?

If you walk down into the Kendall Square subway station in Cambridge, Massachusetts, through the turnstiles and past the Paul Matisse art installation, you will see a common feature of all subways: a map.

If you have ever used a subway map, you know that they are not quite like other maps, which tend to be concerned with details like distance and terrain. Subway maps leave all that out, showing you the bare minimum you need to know to get from one place to another: which stations are connected to each other.

When you're using a subway, it doesn't matter how long a stretch of track is, what exact direction it goes in, or even whether it is above ground, underground, or under water. All you have to do is get on at one station and get off at another, possibly with some transfers between the two. Such a map is an excellent example of the types of networks used by network scientists.

Nodes and edges

In network science, a network is simply a set of things and the connections between them. The things are called nodes, and the connections are called edges. Nodes are really just placeholders for any type of thing that can have a connection or relationship, such as subway stations, people, or atoms. Similarly, edges are placeholders for connections or relationships, such as subway tracks, friendships, or molecular bonds. Just like the subway map, representing a system as a network strips away a lot of information, making it possible to focus just on the structure.

Sometimes, you might see nodes called vertices, or edges called links. Mathematicians like vertices and edges, while computer scientists prefer nodes and links. NetworkX uses nodes and edges (perhaps as a compromise?), so I will use that terminology in this book.

Visualizing networks

Networks are often visualized by drawing a dot or circle for each node and a line for each edge, as in the following diagram:

Example network with five nodes

Looking at the network in this diagram, you might as yourself where to draw the nodes. The answer is wherever you want! (Although technically possible, it might be advisable to avoid hot surfaces, the mouths of large predatory animals, and/or important historical documents.) Because networks are meant to focus on structure and connectivity, there are many ways to draw the same network. Nodes can be drawn anywhere. Edges can be straight or squiggly, long or short. Edges can even cross, but that should never be interpreted as being connected to each other!

The same network can be drawn in many other ways, as shown in the following diagram. The nodes have been labelled with letters to make it easier to compare between different network diagrams. Regardless of which diagram you look at, any particular node will be connected to the same set of other nodes. While different ways of drawing the same network are equally correct, some may be helpful at highlighting particular features of the network. Chapter 11, Visualization, describes common approaches to visualizing networks and their various applications:

Equivalent networks