15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

310 CHAPTER 15. BASICS OF NETWORKSExercise 15.8 Construct a graph by generating a complete graph made <strong>of</strong> 10nodes, <strong>and</strong> <strong>the</strong>n connect a new additional node <strong>to</strong> each <strong>of</strong> <strong>the</strong> 10 nodes, using oneedge each.Exercise 15.9 Create Zachary’s Karate Club graph using NetworkX’s built-infunction, <strong>and</strong> inspect its nodes <strong>and</strong> edges <strong>to</strong> see if <strong>the</strong>y have any non-<strong>to</strong>pologicalproperties.15.4 Visualizing Networks with NetworkXNetworkX also provides functions for visualizing networks. They are not as powerful aso<strong>the</strong>r more specialized s<strong>of</strong>tware 1 , but still quite h<strong>and</strong>y <strong>and</strong> useful, especially for small- <strong>to</strong>mid-sized network visualization. Those visualization functions depend on <strong>the</strong> functionsdefined in matplotlib (pylab), so we need <strong>to</strong> import it before visualizing networks.The simplest way is <strong>to</strong> use NetworkX’s draw function:Code 15.11: karate-club-visualization.pyfrom pylab import *import networkx as nxg = nx.karate_club_graph()nx.draw(g)show()The result is shown in Fig. 15.3. Red circles represent <strong>the</strong> nodes, <strong>and</strong> <strong>the</strong> black linesconnecting <strong>the</strong>m represent <strong>the</strong> edges. By default, <strong>the</strong> layout <strong>of</strong> <strong>the</strong> nodes <strong>and</strong> edgesis au<strong>to</strong>matically determined by <strong>the</strong> Fruchterman-Reingold force-directed algorithm [62](called “spring layout” in NetworkX), which conducts a pseudo-physics simulation <strong>of</strong> <strong>the</strong>movements <strong>of</strong> <strong>the</strong> nodes, assuming that each edge is a spring with a fixed equilibriumdistance. This heuristic algorithm tends <strong>to</strong> bring groups <strong>of</strong> well-connected nodes closer<strong>to</strong> each o<strong>the</strong>r, making <strong>the</strong> result <strong>of</strong> visualization more meaningful <strong>and</strong> aes<strong>the</strong>tically morepleasing.1 For example, Gephi (http://gephi.github.io/) can h<strong>and</strong>le much larger networks, <strong>and</strong> it has manymore node-embedding algorithms than NetworkX.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!