Networkx Reference Release 2.0.Dev20150614235007
Total Page:16
File Type:pdf, Size:1020Kb
NetworkX Reference Release 2.0.dev20150614235007 Aric Hagberg, Dan Schult, Pieter Swart June 15, 2015 Contents 1 Overview 1 1.1 Who uses NetworkX?..........................................1 1.2 Goals...................................................1 1.3 The Python programming language...................................1 1.4 Free software...............................................2 1.5 History..................................................2 2 Introduction 3 2.1 NetworkX Basics.............................................3 2.2 Nodes and Edges.............................................4 3 Graph types 9 3.1 Which graph class should I use?.....................................9 3.2 Basic graph types.............................................9 4 Algorithms 25 4.1 Approximation.............................................. 25 4.2 Assortativity............................................... 34 4.3 Bipartite................................................. 34 4.4 Blockmodeling.............................................. 61 4.5 Boundary................................................. 61 4.6 Centrality................................................. 62 4.7 Chordal.................................................. 63 4.8 Clique.................................................. 66 4.9 Clustering................................................ 69 4.10 Coloring................................................. 73 4.11 Communities............................................... 73 4.12 Components............................................... 74 4.13 Connectivity............................................... 90 4.14 Cores................................................... 108 4.15 Cycles.................................................. 111 4.16 Directed Acyclic Graphs......................................... 114 4.17 Distance Measures............................................ 118 4.18 Distance-Regular Graphs......................................... 120 4.19 Dominance................................................ 122 4.20 Dominating Sets............................................. 123 4.21 Eulerian.................................................. 124 4.22 Flows................................................... 125 i 4.23 Graphical degree sequence........................................ 126 4.24 Hierarchy................................................. 129 4.25 Hybrid.................................................. 130 4.26 Isolates.................................................. 131 4.27 Isomorphism............................................... 132 4.28 Link Analysis............................................... 134 4.29 Link Prediction.............................................. 140 4.30 Matching................................................. 146 4.31 Minors.................................................. 147 4.32 Maximal independent set......................................... 151 4.33 Minimum Spanning Tree......................................... 152 4.34 Operators................................................. 154 4.35 Rich Club................................................. 162 4.36 Shortest Paths.............................................. 163 4.37 Simple Paths............................................... 181 4.38 Swap................................................... 183 4.39 Traversal................................................. 185 4.40 Tree.................................................... 192 4.41 Triads................................................... 197 4.42 Vitality.................................................. 198 5 Functions 201 5.1 Graph................................................... 201 5.2 Nodes................................................... 202 5.3 Edges................................................... 204 5.4 Attributes................................................. 205 5.5 Freezing graph structure......................................... 207 6 Graph generators 209 6.1 Atlas................................................... 209 6.2 Classic.................................................. 209 6.3 Expanders................................................ 214 6.4 Small................................................... 215 6.5 Random Graphs............................................. 219 6.6 Degree Sequence............................................. 227 6.7 Random Clustered............................................ 233 6.8 Directed................................................. 234 6.9 Geometric................................................ 237 6.10 Line Graph................................................ 240 6.11 Ego Graph................................................ 241 6.12 Stochastic................................................. 242 6.13 Intersection................................................ 243 6.14 Social Networks............................................. 244 6.15 Community................................................ 245 6.16 Non Isomorphic Trees.......................................... 249 7 Linear algebra 251 7.1 Graph Matrix............................................... 251 7.2 Laplacian Matrix............................................. 252 7.3 Spectrum................................................. 255 7.4 Algebraic Connectivity.......................................... 256 7.5 Attribute Matrices............................................ 258 8 Converting to and from other data formats 263 8.1 To NetworkX Graph........................................... 263 ii 8.2 Dictionaries................................................ 264 8.3 Lists................................................... 265 8.4 Numpy.................................................. 267 8.5 Scipy................................................... 271 8.6 Pandas.................................................. 273 9 Reading and writing graphs 277 9.1 Adjacency List.............................................. 277 9.2 Multiline Adjacency List......................................... 280 9.3 Edge List................................................. 284 9.4 GEXF................................................... 290 9.5 GML................................................... 292 9.6 Pickle................................................... 296 9.7 GraphML................................................. 297 9.8 JSON................................................... 300 9.9 LEDA................................................... 300 9.10 YAML.................................................. 301 9.11 SparseGraph6.............................................. 302 9.12 Pajek................................................... 308 9.13 GIS Shapefile............................................... 309 10 Drawing 311 10.1 Matplotlib................................................ 311 10.2 Graphviz AGraph (dot).......................................... 319 10.3 Graphviz with pydot........................................... 322 10.4 Graph Layout............................................... 324 11 Exceptions 329 11.1 Exceptions................................................ 329 12 Utilities 331 12.1 Helper Functions............................................. 331 12.2 Data Structures and Algorithms..................................... 332 12.3 Random Sequence Generators...................................... 332 12.4 Decorators................................................ 335 12.5 Cuthill-Mckee Ordering......................................... 336 12.6 Context Managers............................................ 338 13 License 339 14 Citing 341 15 Credits 343 15.1 Contributions............................................... 343 15.2 Support.................................................. 345 16 Glossary 347 Python Module Index 349 iii iv CHAPTER 1 Overview NetworkX is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and function of complex networks. With NetworkX you can load and store networks in standard and nonstandard data formats, generate many types of random and classic networks, analyze network structure, build network models, design new network algorithms, draw networks, and much more. 1.1 Who uses NetworkX? The potential audience for NetworkX includes mathematicians, physicists, biologists, computer scientists, and social scientists. Good reviews of the state-of-the-art in the science of complex networks are presented in Albert and Barabási [BA02], Newman [Newman03], and Dorogovtsev and Mendes [DM03]. See also the classic texts [Bollobas01], [Diestel97] and [West01] for graph theoretic results and terminology. For basic graph algorithms, we recommend the texts of Sedgewick, e.g. [Sedgewick01] and [Sedgewick02] and the survey of Brandes and Erlebach [BE05]. 1.2 Goals NetworkX is intended to provide • tools for the study of the structure and dynamics of social, biological, and infrastructure networks, • a standard programming interface and graph implementation that is suitable for many applications, • a rapid development environment for collaborative, multidisciplinary projects, • an interface to existing numerical algorithms and code written in C, C++, and FORTRAN, • the ability to painlessly slurp in large nonstandard data sets. 1.3 The Python programming language Python is a powerful programming language that allows simple and flexible representations of networks, and clear and concise expressions of network algorithms (and other algorithms too). Python has a vibrant and