├── .gitignore
├── LICENSE
├── README.md
├── _config.yml
├── assets
├── cover.jpg
└── css
│ └── style.scss
├── datasets
├── README.md
├── bio-yeast-protein-inter
│ ├── README.md
│ └── bio-yeast-protein-inter.edges
├── celegansneural
│ ├── README.md
│ └── celegansneural.edges
├── eco-everglades
│ ├── README.md
│ └── eco-everglades.edges
├── email-Enron
│ ├── README.md
│ └── email-Enron.edges.gz
├── enwiki_math
│ ├── Check subcategories.ipynb
│ ├── Create network.ipynb
│ ├── README.md
│ ├── enwiki_math.edges.gz
│ └── enwiki_math.graphml.gz
├── friends.adjlist
├── ia-enron-only
│ └── ia-enron-only.edges
├── icwsm_polarization
│ ├── all.edges.gz
│ ├── all.graphml.gz
│ ├── all.nodes.gz
│ ├── data_format_specification.docx
│ ├── mention.edges.gz
│ ├── mention.graphml.gz
│ ├── mention.nodes.gz
│ ├── multidigraph to digraph.ipynb
│ ├── retweet-digraph.edges.gz
│ ├── retweet.edges.gz
│ ├── retweet.graphml.gz
│ └── retweet.nodes.gz
├── imdb
│ ├── actors_costar.edges.gz
│ ├── actors_costar.graphml.gz
│ ├── actors_movies.edges.gz
│ └── actors_movies.graphml.gz
├── karate_club.graphml
├── openflights
│ ├── README.md
│ ├── openflights_usa.edges.gz
│ ├── openflights_usa.graphml.gz
│ ├── openflights_world.edges.gz
│ └── openflights_world.graphml.gz
├── repealthe19th.jsonl.gz
├── science_tweets.json
├── socfb-Northwestern25
│ └── socfb-Northwestern25.edges.gz
├── summary_statistics.csv
├── summary_statistics.ipynb
└── tech-RL-caida
│ ├── README.md
│ └── tech-RL-caida.edges.gz
├── sample
├── Selected_Exercise_Solutions.pdf
├── chapters
│ ├── chapter0.pdf
│ └── chapter4.pdf
└── slides
│ ├── chapter0.key
│ ├── chapter0.pptx
│ ├── chapter4.key
│ └── chapter4.pptx
└── tutorials
├── Appendix - Python Tutorial.ipynb
├── Chapter 1 Tutorial.ipynb
├── Chapter 2 Tutorial.ipynb
├── Chapter 3 Tutorial.ipynb
├── Chapter 4 Tutorial (Twitter API v1).ipynb
├── Chapter 4 Tutorial (Twitter API v2).ipynb
├── Chapter 5 Tutorial.ipynb
├── Chapter 6 Tutorial.ipynb
├── Chapter 7 Tutorial.ipynb
└── simulation.py
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .ipynb_checkpoints
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2018-2019 Indiana University
2 |
3 | This work is licensed under the Creative Commons Attribution 4.0 International License.
4 | To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](http://www.youtube.com/watch?v=GZJgPiuQgcw "Untangling Network Science")
2 |
3 | # A First Course in Network Science
4 |
5 | **Edition:** 1
6 |
7 | **Publication year:** 2020
8 |
9 | **ISBN:** 9781108471138
10 |
11 | **Buy:** [Amazon](https://www.amazon.com/First-Course-Network-Science/dp/1108471137/) | [Cambridge University Press](https://www.cambridge.org/us/academic/subjects/physics/statistical-physics/first-course-network-science)
12 |
13 | ## Authors
14 |
15 | * [Filippo Menczer](https://about.me/fil.m), Indiana University, Bloomington
16 | * [Santo Fortunato](https://sites.google.com/view/santofortunato/), Indiana University, Bloomington
17 | * [Clayton A. Davis](https://www.clayadavis.net/), Indiana University, Bloomington
18 |
19 | ## Level
20 |
21 | - Undergraduate
22 | - Graduate
23 |
24 | ## Subject Areas
25 |
26 | network science, complexity, statistical physics, social networks, computer science, information science, brain science, political science, communication, management, mathematics, health, financial networks, biological networks
27 |
28 | ## Abstract
29 |
30 | Networks pervade all aspects of our lives: networks of friends, communication, computers, the Web, and transportation are examples we experience daily, while networks in our brain and cells determine our very survival. The network is a general yet powerful way to represent and study simple and complex relationships. Today, a basic understanding of network processes is required in job sectors from marketing to technology, from management to design, and from biology to the arts and humanities. This textbook is designed to introduce networks to a broad audience of undergraduate students from informatics, business, computer science and engineering, information science, biology, physics, statistics, and social sciences. After surveying networks in many areas, the book talks about the properties of social networks and the key role of hubs. Directed and weighted networks are discussed using the Web and the spread of information and misinformation in social media as case studies. The final chapters cover the more advanced topics of networks models, communities, and dynamics. No technical mathematical or programming background is required, making the book feasible for introductory courses at any level, including network literacy and programming literacy courses. However, the book includes optional technical sections for more advanced students. Programming tutorials, exercises, and datasets allow readers to gain and test their understanding through hands-on activities for building and analyzing networks.
31 |
32 | ## Reviews & Endorsements
33 |
34 | > This is a book that truly takes in hand students from all backgrounds to discover the power of network science. It guides the readers through the basic concepts needed to enter the field, while providing at the same time the necessary programming rudiments and tools. Rigorous, albeit very accessible, this book is the ideal starting point for any student fascinated by the emerging field of network science.
35 |
36 | --Alessandro Vespignani, Sternberg Distinguished Professor of Physics, Health, and Computer Sciences, Northeastern University
37 |
38 | > We cannot make sense of the world without learning about networks. This comprehensive and yet accessible text is an essential resource for all interested in mastering the basics of network science. Indispensable for undergraduate and graduate education, the book is also a much-needed primer for researchers across the many disciplines where networks are on the rise.
39 |
40 | --Olaf Sporns, Distinguished Professor of Psychological and Brain Sciences, Indiana University
41 |
42 | > Buckle up! This book bounds ahead of the curve in teaching network science. Without formalism, but with remarkable clarity and insight, the authors use experiential learning to animate concepts, captivate students, and deliver skills for analyzing and simulating network data. This book will not only make students smarter, they will feel and act smarter.
43 |
44 | --Brian Uzzi, Thomas Professor of Management, Northwestern University
45 |
46 | > *A First Course in Network Science* by Menczer, Fortunato, and Davis is an easy-to-follow introduction into network science. An accessible text by some of the best-known practitioners of the field, offering a wonderful place to start one's journey into this fascinating field, and its potential applications.
47 |
48 | --Albert-László Barabási, Dodge Distinguished Professor of Network Science, Northeastern University
49 |
50 | > This is a timely book that comes from authorities in the field of Complex Networks. The book is very well written and represents the state of the art of research in the field. For these reasons, it represents both a reference guide for experts and a great textbook for the students.
51 |
52 | --Guido Caldarelli, Professor of Theoretical Physics, Scuola IMT Alti Studi Lucca
53 |
54 | > The book by Menczer, Fortunato, and Davis, *A First Course in Network Science*, is an amazing tour de force in bringing network science concepts to the layman. It is an extraordinary book with which to start thinking about networks that nowadays represent the linchpins of our world.
55 |
56 | --Alex Arenas, Professor of Computer Science and Mathematics, Universidad Rovira i Virgili
57 |
58 | > Should be titled the "Joy of Networks," clearly conveys the fun and power of the science of networks, while providing extensive hands-on exercises with network data.
59 |
60 | --David Lazer, University Distinguished Professor of Political Science and Computer and Information Science, Northeastern University
61 |
62 | > If you are looking for a sophisticated yet introductory book on network analysis from a network science perspective, look no further. This is an excellent introduction that is also eminently practical, integrating exactly the right set of tools. I highly recommend it.
63 |
64 | --Stephen Borgatti, Shellgren Chair of Management of Strategy, University of Kentucky
65 |
66 | ## Table of Contents
67 |
68 | - Chapter 0: [Introduction](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/sample/chapters/chapter0.pdf)
69 |
70 | - Chapter 1: Basic Elements ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%201%20Tutorial.ipynb))
71 |
72 | - Chapter 2: Small Worlds ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%202%20Tutorial.ipynb))
73 |
74 | - Chapter 3: Hubs ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%203%20Tutorial.ipynb))
75 |
76 | - Chapter 4: [Direction & Weights](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/sample/chapters/chapter4.pdf) ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%204%20Tutorial%20(Twitter%20API%20v2).ipynb))
77 |
78 | - Chapter 5: Network Models ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%205%20Tutorial.ipynb))
79 |
80 | - Chapter 6: Communities ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%206%20Tutorial.ipynb))
81 |
82 | - Chapter 7: Dynamics ([Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Chapter%207%20Tutorial.ipynb))
83 |
84 | - Appendix A: [Python Tutorial](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/tutorials/Appendix%20-%20Python%20Tutorial.ipynb)
85 |
86 | - Appendix B: NetLogo
87 |
88 | - References
89 |
90 | - Index
91 |
92 | ## A Note about Python, Tutorials, and Jupyter Notebooks
93 |
94 | Our tutorials use Python 3 and NetworkX (2.4 or later). They are in the form of Jupyter Notebooks. To load, view, and run these tutorials, you can follow one or both of two approaches:
95 |
96 | 1. There are several free services to run Jupyter notebooks in the cloud at the time of this writing, including:
97 | - [Google Colab](https://colab.research.google.com/)
98 | - [Binder](https://mybinder.org/)
99 | - [Kaggle Kernels](https://www.kaggle.com/kernels)
100 | - [Azure Notebooks](https://notebooks.azure.com/)
101 | - [Datalore](https://datalore.io/)
102 | - [Gryd](https://gryd.us/)
103 |
104 | Each cloud-based notebook service has [pros and cons](https://www.dataschool.io/cloud-services-for-jupyter-notebook/) and we cannot test them all extensively, so your mileage may vary. You may have to try more than one solution, read documentation, and/or seek support from the providers to install packages.
105 |
106 | 2. If you wish to run Python locally on your laptop, and don't have Jupyter/IPython installed on your machine, we recommend installing the [Anaconda](https://www.anaconda.com/distribution/) Python distribution with Python 3. This option requires that you are comfortable with managing software packages (i.e., using `pip` or `conda`). Local Python installations can present issues, especially on Windows machines. Packages are system dependent. In all cases, we are unable to provide support.
107 |
108 | ## Additional Resources
109 |
110 | * [Dataset files](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/tree/master/datasets)
111 |
112 | * [Solutions to selected exercises](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/blob/master/sample/Selected_Exercise_Solutions.pdf) (solutions to **all** exercises can be found on the [textbook website for registered instructors](https://www.cambridge.org/academic/subjects/physics/statistical-physics/first-course-network-science#resources))
113 |
114 | * [Sample slides](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/tree/master/sample/slides) (lecture slide decks for **all** chapters can be found on the [textbook website for registered instructors](https://www.cambridge.org/academic/subjects/physics/statistical-physics/first-course-network-science#resources))
115 |
116 | * [Errata](https://github.com/CambridgeUniversityPress/FirstCourseNetworkScience/issues) (submit an issue to flag errors in the book)
117 |
118 | Note: To access the resources on the CUP textbook website for instructors, one has to request an instructor account by registering and verifying their faculty status.
119 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/assets/cover.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/assets/cover.jpg
--------------------------------------------------------------------------------
/assets/css/style.scss:
--------------------------------------------------------------------------------
1 | ---
2 | ---
3 |
4 | @import "{{ site.theme }}";
5 |
6 | .page-header {
7 | background-image: url("https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/master/assets/cover.jpg")
8 | }
9 |
--------------------------------------------------------------------------------
/datasets/README.md:
--------------------------------------------------------------------------------
1 | # Network Science book datasets
2 |
3 | Repository containing the example networks for the CUP book by Menczer, Fortunato, and Davis.
4 |
5 | * Facebook ([socfb-Northwestern25](socfb-Northwestern25/))
6 | * Twitter ([icwsm\_polarization](icwsm_polarization/))
7 | * Collaboration ([IMDB](imdb/): bipartite + social)
8 | * Email ([Enron executives](ia-enron-only/); [Enron all](email-Enron/))
9 | * Wikipedia (Mathematics) ([enwiki\_math](enwiki_math/))
10 | * Internet ([tech-RL-caida](tech-RL-caida/))
11 | * Airports ([openflights](openflights/): USA and world)
12 | * brain ([c. elegans](celegansneural/))
13 | * bio ([Everglades food web](eco-everglades/), weighted & directed)
14 | * bio ([bio-yeast-protein-inter](bio-yeast-protein-inter/))
15 |
16 | Summary statistics can be viewed as a [CSV](summary_statistics.csv) or along with the code as a [notebook](summary_statistics.ipynb).
17 |
--------------------------------------------------------------------------------
/datasets/bio-yeast-protein-inter/README.md:
--------------------------------------------------------------------------------
1 | @article{jeong2001lethality,
2 | title={Lethality and centrality in protein networks},
3 | author={Jeong, H. and Mason, S.P. and Barabasi, A.L. and Oltvai, Z.N.},
4 | journal={arXiv preprint cond-mat/0105306},
5 | year={2001}
6 | }
7 |
--------------------------------------------------------------------------------
/datasets/celegansneural/README.md:
--------------------------------------------------------------------------------
1 | c.f. http://networkrepository.com/celegansneural.php
2 |
--------------------------------------------------------------------------------
/datasets/celegansneural/celegansneural.edges:
--------------------------------------------------------------------------------
1 | # Directed, weighted
2 | 135 1 3
3 | 202 1 2
4 | 1 2 1
5 | 8 2 1
6 | 17 2 6
7 | 102 2 1
8 | 103 2 4
9 | 109 2 9
10 | 114 2 11
11 | 116 2 1
12 | 117 2 5
13 | 125 2 1
14 | 128 2 2
15 | 130 2 1
16 | 131 2 4
17 | 132 2 1
18 | 136 2 7
19 | 137 2 1
20 | 139 2 1
21 | 141 2 3
22 | 142 2 3
23 | 143 2 1
24 | 194 2 1
25 | 196 2 2
26 | 215 2 1
27 | 242 2 2
28 | 1 3 2
29 | 5 3 44
30 | 8 3 2
31 | 13 3 3
32 | 17 3 4
33 | 21 3 6
34 | 22 3 3
35 | 64 3 3
36 | 68 3 1
37 | 73 3 3
38 | 85 3 25
39 | 88 3 1
40 | 90 3 1
41 | 99 3 2
42 | 100 3 1
43 | 102 3 1
44 | 110 3 5
45 | 112 3 2
46 | 115 3 1
47 | 119 3 70
48 | 122 3 2
49 | 126 3 9
50 | 130 3 18
51 | 171 3 4
52 | 173 3 10
53 | 185 3 7
54 | 194 3 7
55 | 195 3 7
56 | 202 3 3
57 | 204 3 2
58 | 205 3 6
59 | 208 3 6
60 | 213 3 11
61 | 221 3 1
62 | 225 3 4
63 | 226 3 2
64 | 227 3 1
65 | 240 3 3
66 | 249 3 27
67 | 256 3 6
68 | 258 3 7
69 | 1 4 1
70 | 6 4 4
71 | 8 4 4
72 | 9 4 1
73 | 12 4 4
74 | 13 4 4
75 | 15 4 2
76 | 28 4 4
77 | 32 4 14
78 | 51 4 1
79 | 59 4 5
80 | 63 4 1
81 | 64 4 1
82 | 66 4 3
83 | 83 4 2
84 | 87 4 3
85 | 91 4 8
86 | 92 4 6
87 | 93 4 2
88 | 94 4 2
89 | 99 4 4
90 | 102 4 1
91 | 107 4 1
92 | 109 4 4
93 | 112 4 1
94 | 115 4 1
95 | 126 4 2
96 | 138 4 8
97 | 173 4 3
98 | 214 4 2
99 | 217 4 1
100 | 225 4 3
101 | 240 4 1
102 | 1 5 2
103 | 3 5 4
104 | 9 5 2
105 | 10 5 2
106 | 15 5 5
107 | 16 5 3
108 | 19 5 19
109 | 32 5 1
110 | 42 5 2
111 | 53 5 1
112 | 54 5 5
113 | 68 5 1
114 | 72 5 5
115 | 77 5 3
116 | 83 5 2
117 | 85 5 3
118 | 88 5 3
119 | 91 5 6
120 | 93 5 2
121 | 100 5 3
122 | 103 5 4
123 | 109 5 1
124 | 110 5 2
125 | 120 5 4
126 | 126 5 1
127 | 138 5 6
128 | 150 5 1
129 | 173 5 1
130 | 188 5 1
131 | 204 5 1
132 | 205 5 3
133 | 208 5 3
134 | 214 5 1
135 | 225 5 2
136 | 227 5 1
137 | 1 6 1
138 | 9 6 2
139 | 10 6 1
140 | 60 6 1
141 | 71 6 1
142 | 104 6 1
143 | 128 6 3
144 | 202 6 2
145 | 1 7 6
146 | 8 7 2
147 | 14 7 1
148 | 31 7 2
149 | 35 7 1
150 | 44 7 1
151 | 48 7 3
152 | 49 7 7
153 | 53 7 4
154 | 60 7 9
155 | 74 7 1
156 | 75 7 1
157 | 76 7 4
158 | 78 7 7
159 | 92 7 1
160 | 100 7 10
161 | 104 7 1
162 | 106 7 12
163 | 108 7 4
164 | 109 7 7
165 | 110 7 2
166 | 111 7 1
167 | 112 7 2
168 | 136 7 1
169 | 138 7 2
170 | 202 7 2
171 | 210 7 2
172 | 1 8 6
173 | 2 8 2
174 | 10 8 1
175 | 32 8 10
176 | 59 8 1
177 | 60 8 4
178 | 61 8 1
179 | 83 8 1
180 | 91 8 6
181 | 92 8 1
182 | 100 8 12
183 | 108 8 4
184 | 131 8 1
185 | 135 8 2
186 | 1 9 1
187 | 3 9 1
188 | 6 9 7
189 | 64 9 5
190 | 66 9 2
191 | 68 9 7
192 | 124 9 1
193 | 194 9 5
194 | 196 9 2
195 | 204 9 2
196 | 1 10 4
197 | 53 10 2
198 | 64 10 6
199 | 68 10 4
200 | 106 10 2
201 | 112 10 1
202 | 194 10 5
203 | 196 10 3
204 | 2 11 1
205 | 6 11 1
206 | 116 11 4
207 | 125 11 4
208 | 127 11 7
209 | 136 11 12
210 | 137 11 2
211 | 139 11 13
212 | 209 11 1
213 | 6 12 1
214 | 15 12 1
215 | 55 12 1
216 | 66 12 7
217 | 101 12 3
218 | 104 12 1
219 | 138 12 1
220 | 2 13 2
221 | 3 13 3
222 | 4 13 44
223 | 6 13 3
224 | 12 13 2
225 | 15 13 1
226 | 17 13 2
227 | 21 13 5
228 | 22 13 5
229 | 64 13 2
230 | 68 13 5
231 | 86 13 1
232 | 87 13 25
233 | 92 13 1
234 | 94 13 1
235 | 96 13 5
236 | 112 13 1
237 | 117 13 2
238 | 118 13 70
239 | 120 13 2
240 | 126 13 7
241 | 130 13 13
242 | 131 13 2
243 | 132 13 5
244 | 133 13 1
245 | 138 13 3
246 | 139 13 1
247 | 171 13 5
248 | 173 13 8
249 | 185 13 3
250 | 194 13 5
251 | 195 13 7
252 | 202 13 5
253 | 204 13 2
254 | 212 13 15
255 | 225 13 10
256 | 227 13 3
257 | 240 13 2
258 | 242 13 2
259 | 248 13 27
260 | 256 13 9
261 | 257 13 1
262 | 258 13 7
263 | 259 13 1
264 | 262 13 5
265 | 6 14 4
266 | 11 14 5
267 | 12 14 6
268 | 15 14 3
269 | 35 14 1
270 | 48 14 5
271 | 49 14 5
272 | 54 14 1
273 | 60 14 12
274 | 64 14 1
275 | 66 14 8
276 | 71 14 1
277 | 74 14 1
278 | 75 14 2
279 | 76 14 8
280 | 78 14 3
281 | 101 14 12
282 | 103 14 7
283 | 104 14 6
284 | 115 14 1
285 | 117 14 4
286 | 121 14 3
287 | 138 14 1
288 | 139 14 2
289 | 202 14 3
290 | 210 14 2
291 | 6 15 4
292 | 9 15 1
293 | 11 15 5
294 | 12 15 9
295 | 19 15 7
296 | 54 15 2
297 | 55 15 1
298 | 60 15 5
299 | 61 15 1
300 | 72 15 2
301 | 77 15 1
302 | 91 15 3
303 | 115 15 4
304 | 128 15 1
305 | 133 15 1
306 | 135 15 1
307 | 194 15 1
308 | 19 16 2
309 | 60 16 1
310 | 91 16 2
311 | 217 16 1
312 | 13 17 1
313 | 16 17 1
314 | 242 17 1
315 | 16 18 2
316 | 19 18 1
317 | 20 18 2
318 | 43 18 1
319 | 54 18 1
320 | 71 18 6
321 | 16 19 4
322 | 64 19 2
323 | 72 19 2
324 | 73 19 1
325 | 16 20 5
326 | 17 20 1
327 | 60 20 3
328 | 63 20 8
329 | 71 20 1
330 | 101 20 1
331 | 16 21 6
332 | 20 21 1
333 | 28 21 2
334 | 59 21 4
335 | 63 21 1
336 | 66 21 1
337 | 69 21 1
338 | 72 21 1
339 | 122 21 1
340 | 16 22 4
341 | 28 22 4
342 | 33 22 1
343 | 53 22 1
344 | 56 22 1
345 | 58 22 1
346 | 59 22 2
347 | 69 22 1
348 | 70 22 1
349 | 72 22 3
350 | 84 22 1
351 | 122 22 1
352 | 240 22 1
353 | 16 23 1
354 | 17 23 1
355 | 18 23 7
356 | 20 23 2
357 | 27 23 3
358 | 41 23 3
359 | 43 23 4
360 | 55 23 9
361 | 57 23 3
362 | 60 23 5
363 | 71 23 11
364 | 72 23 2
365 | 102 23 2
366 | 117 23 1
367 | 7 24 12
368 | 14 24 10
369 | 16 24 3
370 | 18 24 11
371 | 19 24 7
372 | 42 24 3
373 | 44 24 1
374 | 47 24 10
375 | 49 24 1
376 | 51 24 3
377 | 54 24 4
378 | 59 24 1
379 | 69 24 3
380 | 76 24 2
381 | 83 24 2
382 | 91 24 1
383 | 92 24 1
384 | 210 24 1
385 | 241 24 1
386 | 10 25 4
387 | 16 25 1
388 | 59 25 4
389 | 64 25 1
390 | 242 25 2
391 | 7 26 1
392 | 16 26 2
393 | 84 26 1
394 | 94 26 1
395 | 210 26 2
396 | 16 27 2
397 | 71 27 4
398 | 7 28 1
399 | 32 28 6
400 | 60 28 2
401 | 91 28 1
402 | 241 28 1
403 | 28 29 1
404 | 111 29 1
405 | 135 29 1
406 | 151 29 2
407 | 28 30 2
408 | 31 30 5
409 | 32 30 1
410 | 33 30 1
411 | 43 30 1
412 | 92 30 1
413 | 28 31 1
414 | 30 31 1
415 | 33 31 1
416 | 28 32 5
417 | 48 32 1
418 | 59 32 6
419 | 67 32 2
420 | 68 32 2
421 | 91 32 1
422 | 122 32 1
423 | 212 32 1
424 | 28 33 3
425 | 31 33 2
426 | 53 33 1
427 | 60 33 7
428 | 67 33 7
429 | 28 34 1
430 | 30 34 8
431 | 31 34 14
432 | 33 34 1
433 | 39 34 4
434 | 43 34 3
435 | 46 34 7
436 | 53 34 3
437 | 58 34 12
438 | 60 34 5
439 | 62 34 3
440 | 107 34 1
441 | 206 34 1
442 | 7 35 2
443 | 14 35 2
444 | 28 35 1
445 | 64 35 1
446 | 78 35 1
447 | 7 36 8
448 | 14 36 6
449 | 19 36 1
450 | 28 36 2
451 | 30 36 11
452 | 32 36 10
453 | 44 36 6
454 | 48 36 1
455 | 51 36 4
456 | 56 36 4
457 | 57 36 1
458 | 77 36 4
459 | 78 36 1
460 | 84 36 1
461 | 92 36 4
462 | 217 36 1
463 | 9 37 3
464 | 28 37 2
465 | 69 37 1
466 | 72 37 4
467 | 94 37 1
468 | 237 37 1
469 | 242 37 1
470 | 28 38 2
471 | 35 38 3
472 | 53 38 1
473 | 70 38 1
474 | 214 38 1
475 | 28 39 1
476 | 31 39 3
477 | 67 39 1
478 | 28 40 1
479 | 60 40 1
480 | 93 40 3
481 | 128 40 1
482 | 135 40 1
483 | 146 40 1
484 | 149 40 1
485 | 150 40 2
486 | 151 40 1
487 | 226 40 1
488 | 42 41 1
489 | 43 41 1
490 | 55 41 7
491 | 57 41 2
492 | 72 41 4
493 | 18 42 1
494 | 41 42 1
495 | 63 42 1
496 | 64 42 1
497 | 72 42 1
498 | 84 42 1
499 | 41 43 1
500 | 78 43 1
501 | 126 43 1
502 | 138 43 2
503 | 172 43 2
504 | 173 43 1
505 | 185 43 1
506 | 186 43 2
507 | 207 43 3
508 | 218 43 2
509 | 7 44 4
510 | 14 44 7
511 | 19 44 1
512 | 33 44 3
513 | 35 44 1
514 | 36 44 10
515 | 39 44 1
516 | 41 44 6
517 | 42 44 4
518 | 51 44 1
519 | 72 44 3
520 | 77 44 5
521 | 88 44 1
522 | 92 44 3
523 | 94 44 4
524 | 18 45 10
525 | 24 45 8
526 | 25 45 8
527 | 27 45 9
528 | 30 45 10
529 | 35 45 4
530 | 36 45 10
531 | 37 45 7
532 | 39 45 9
533 | 41 45 4
534 | 42 45 10
535 | 44 45 7
536 | 46 45 8
537 | 47 45 9
538 | 48 45 11
539 | 49 45 4
540 | 50 45 14
541 | 51 45 12
542 | 52 45 11
543 | 57 45 6
544 | 61 45 10
545 | 62 45 6
546 | 65 45 5
547 | 74 45 3
548 | 75 45 3
549 | 76 45 3
550 | 78 45 2
551 | 86 45 9
552 | 88 45 3
553 | 90 45 9
554 | 94 45 5
555 | 97 45 1
556 | 98 45 29
557 | 105 45 4
558 | 113 45 4
559 | 131 45 4
560 | 133 45 4
561 | 134 45 5
562 | 143 45 24
563 | 152 45 1
564 | 153 45 15
565 | 154 45 15
566 | 155 45 15
567 | 156 45 15
568 | 157 45 15
569 | 158 45 15
570 | 159 45 15
571 | 160 45 10
572 | 161 45 29
573 | 162 45 29
574 | 163 45 29
575 | 164 45 29
576 | 165 45 29
577 | 166 45 29
578 | 167 45 29
579 | 168 45 29
580 | 169 45 22
581 | 170 45 22
582 | 176 45 10
583 | 177 45 10
584 | 178 45 14
585 | 179 45 10
586 | 180 45 31
587 | 181 45 10
588 | 182 45 10
589 | 183 45 10
590 | 184 45 8
591 | 188 45 6
592 | 189 45 10
593 | 190 45 25
594 | 192 45 25
595 | 193 45 22
596 | 196 45 5
597 | 197 45 10
598 | 198 45 8
599 | 200 45 2
600 | 201 45 8
601 | 203 45 2
602 | 205 45 7
603 | 208 45 7
604 | 210 45 5
605 | 211 45 4
606 | 215 45 5
607 | 220 45 29
608 | 222 45 8
609 | 228 45 8
610 | 231 45 22
611 | 232 45 25
612 | 233 45 22
613 | 234 45 29
614 | 235 45 25
615 | 238 45 23
616 | 239 45 10
617 | 245 45 10
618 | 246 45 8
619 | 247 45 30
620 | 250 45 8
621 | 251 45 1
622 | 252 45 1
623 | 254 45 22
624 | 255 45 18
625 | 263 45 18
626 | 264 45 18
627 | 265 45 18
628 | 266 45 18
629 | 267 45 18
630 | 268 45 18
631 | 269 45 25
632 | 270 45 25
633 | 271 45 15
634 | 272 45 25
635 | 273 45 15
636 | 274 45 25
637 | 275 45 15
638 | 276 45 29
639 | 277 45 29
640 | 278 45 29
641 | 279 45 22
642 | 280 45 10
643 | 281 45 18
644 | 282 45 18
645 | 283 45 4
646 | 284 45 8
647 | 285 45 11
648 | 286 45 1
649 | 287 45 1
650 | 288 45 1
651 | 289 45 1
652 | 290 45 1
653 | 291 45 1
654 | 292 45 1
655 | 293 45 1
656 | 294 45 1
657 | 295 45 1
658 | 32 46 3
659 | 43 46 1
660 | 51 46 1
661 | 58 46 7
662 | 59 46 5
663 | 7 47 9
664 | 14 47 10
665 | 20 47 4
666 | 24 47 7
667 | 32 47 3
668 | 42 47 2
669 | 46 47 8
670 | 51 47 4
671 | 54 47 2
672 | 59 47 2
673 | 62 47 1
674 | 83 47 4
675 | 88 47 4
676 | 210 47 1
677 | 7 48 5
678 | 14 48 6
679 | 19 48 2
680 | 32 48 2
681 | 35 48 2
682 | 42 48 1
683 | 49 48 1
684 | 51 48 4
685 | 63 48 3
686 | 64 48 2
687 | 67 48 1
688 | 70 48 1
689 | 88 48 3
690 | 91 48 2
691 | 94 48 1
692 | 131 48 2
693 | 133 48 1
694 | 215 48 5
695 | 7 49 7
696 | 14 49 5
697 | 25 49 1
698 | 32 49 1
699 | 42 49 3
700 | 48 49 2
701 | 51 49 1
702 | 53 49 1
703 | 63 49 1
704 | 68 49 2
705 | 70 49 1
706 | 88 49 3
707 | 91 49 5
708 | 93 49 1
709 | 94 49 3
710 | 131 49 1
711 | 133 49 3
712 | 210 49 1
713 | 211 49 2
714 | 215 49 1
715 | 27 50 1
716 | 31 50 2
717 | 32 50 2
718 | 33 50 1
719 | 37 50 1
720 | 39 50 2
721 | 42 50 1
722 | 55 50 4
723 | 58 50 2
724 | 60 50 1
725 | 62 50 1
726 | 63 50 2
727 | 71 50 5
728 | 7 51 1
729 | 30 51 1
730 | 39 51 1
731 | 59 51 1
732 | 67 51 1
733 | 70 51 3
734 | 19 52 2
735 | 27 52 1
736 | 31 52 3
737 | 51 52 2
738 | 55 52 4
739 | 57 52 1
740 | 58 52 3
741 | 67 52 2
742 | 71 52 2
743 | 31 53 1
744 | 51 53 1
745 | 70 53 7
746 | 88 53 1
747 | 100 53 1
748 | 104 53 2
749 | 106 53 1
750 | 18 54 1
751 | 23 56 2
752 | 55 56 2
753 | 60 56 3
754 | 63 56 6
755 | 72 56 6
756 | 55 57 3
757 | 72 57 2
758 | 226 57 1
759 | 32 59 2
760 | 58 59 1
761 | 60 59 1
762 | 68 59 1
763 | 70 59 1
764 | 91 59 2
765 | 241 59 1
766 | 8 60 1
767 | 20 60 2
768 | 31 60 4
769 | 33 60 1
770 | 54 60 1
771 | 58 60 1
772 | 63 60 9
773 | 64 60 2
774 | 67 60 5
775 | 68 60 1
776 | 71 60 2
777 | 103 60 1
778 | 196 60 1
779 | 58 61 1
780 | 62 61 1
781 | 86 61 3
782 | 90 61 4
783 | 97 61 1
784 | 58 62 3
785 | 59 62 1
786 | 96 62 1
787 | 64 63 2
788 | 63 64 2
789 | 68 64 2
790 | 96 64 1
791 | 130 64 1
792 | 226 64 4
793 | 27 65 2
794 | 31 65 3
795 | 39 65 2
796 | 60 65 1
797 | 63 65 2
798 | 67 65 1
799 | 71 65 1
800 | 105 65 5
801 | 113 65 3
802 | 196 65 1
803 | 210 65 1
804 | 63 66 2
805 | 84 66 4
806 | 94 66 1
807 | 104 66 5
808 | 202 66 1
809 | 32 67 1
810 | 60 67 1
811 | 70 67 1
812 | 3 68 1
813 | 67 68 2
814 | 96 68 1
815 | 130 68 2
816 | 207 68 3
817 | 225 68 2
818 | 34 69 2
819 | 59 69 5
820 | 60 69 3
821 | 67 69 1
822 | 59 70 2
823 | 67 70 1
824 | 20 71 1
825 | 19 72 2
826 | 60 72 1
827 | 64 72 1
828 | 84 72 1
829 | 91 72 1
830 | 94 72 1
831 | 217 72 3
832 | 2 73 2
833 | 7 73 1
834 | 19 73 1
835 | 35 73 3
836 | 96 73 1
837 | 113 73 4
838 | 133 73 1
839 | 134 73 4
840 | 138 73 1
841 | 214 73 1
842 | 223 73 3
843 | 7 74 6
844 | 8 74 1
845 | 14 74 9
846 | 17 74 2
847 | 19 74 3
848 | 21 74 3
849 | 22 74 2
850 | 32 74 1
851 | 76 74 2
852 | 77 74 1
853 | 83 74 4
854 | 91 74 1
855 | 115 74 3
856 | 131 74 2
857 | 210 74 2
858 | 213 74 6
859 | 219 74 1
860 | 2 75 1
861 | 7 75 10
862 | 14 75 8
863 | 19 75 4
864 | 21 75 4
865 | 22 75 3
866 | 32 75 1
867 | 35 75 1
868 | 65 75 1
869 | 77 75 2
870 | 78 75 4
871 | 83 75 1
872 | 91 75 1
873 | 131 75 3
874 | 133 75 5
875 | 212 75 6
876 | 219 75 2
877 | 237 75 1
878 | 7 76 7
879 | 14 76 12
880 | 15 76 2
881 | 19 76 4
882 | 21 76 1
883 | 22 76 1
884 | 32 76 3
885 | 54 76 4
886 | 74 76 1
887 | 91 76 1
888 | 107 76 2
889 | 210 76 2
890 | 219 76 1
891 | 19 77 1
892 | 72 77 2
893 | 7 78 13
894 | 14 78 3
895 | 22 78 2
896 | 32 78 3
897 | 91 78 1
898 | 92 78 3
899 | 102 78 2
900 | 133 78 1
901 | 236 78 1
902 | 237 78 1
903 | 54 79 1
904 | 56 79 3
905 | 92 79 1
906 | 94 79 2
907 | 126 79 2
908 | 207 79 1
909 | 47 80 1
910 | 69 80 2
911 | 92 80 1
912 | 173 80 1
913 | 20 81 3
914 | 33 82 3
915 | 64 82 1
916 | 59 83 1
917 | 62 83 1
918 | 64 84 1
919 | 72 84 2
920 | 2 85 3
921 | 13 85 2
922 | 17 85 1
923 | 43 85 4
924 | 53 85 1
925 | 66 85 2
926 | 84 85 1
927 | 87 85 2
928 | 99 85 4
929 | 102 85 4
930 | 107 85 3
931 | 112 85 3
932 | 117 85 6
933 | 118 85 1
934 | 120 85 1
935 | 121 85 1
936 | 122 85 1
937 | 124 85 1
938 | 126 85 4
939 | 130 85 4
940 | 131 85 2
941 | 133 85 2
942 | 138 85 1
943 | 173 85 9
944 | 194 85 1
945 | 200 85 1
946 | 202 85 4
947 | 203 85 5
948 | 204 85 5
949 | 206 85 1
950 | 207 85 6
951 | 214 85 1
952 | 216 85 10
953 | 225 85 4
954 | 227 85 4
955 | 242 85 5
956 | 22 86 1
957 | 59 86 1
958 | 64 86 1
959 | 84 86 1
960 | 109 86 5
961 | 121 86 1
962 | 138 86 2
963 | 196 86 1
964 | 199 86 2
965 | 219 86 1
966 | 236 86 2
967 | 3 87 2
968 | 15 87 1
969 | 43 87 3
970 | 53 87 1
971 | 54 87 1
972 | 70 87 1
973 | 85 87 2
974 | 88 87 1
975 | 94 87 2
976 | 99 87 1
977 | 102 87 5
978 | 107 87 4
979 | 110 87 3
980 | 111 87 2
981 | 112 87 7
982 | 115 87 3
983 | 119 87 1
984 | 120 87 5
985 | 122 87 2
986 | 126 87 16
987 | 130 87 5
988 | 131 87 5
989 | 133 87 3
990 | 150 87 2
991 | 173 87 6
992 | 199 87 2
993 | 200 87 8
994 | 202 87 5
995 | 204 87 6
996 | 205 87 3
997 | 206 87 16
998 | 207 87 5
999 | 208 87 3
1000 | 216 87 1
1001 | 225 87 2
1002 | 242 87 4
1003 | 59 88 1
1004 | 68 88 2
1005 | 70 88 1
1006 | 110 88 2
1007 | 143 88 1
1008 | 151 88 2
1009 | 215 88 1
1010 | 7 89 1
1011 | 14 89 1
1012 | 59 89 1
1013 | 70 89 1
1014 | 241 89 1
1015 | 21 90 2
1016 | 70 90 1
1017 | 72 90 1
1018 | 103 90 4
1019 | 106 90 1
1020 | 124 90 1
1021 | 138 90 3
1022 | 237 90 1
1023 | 54 91 1
1024 | 72 91 1
1025 | 120 91 2
1026 | 126 91 2
1027 | 131 91 1
1028 | 133 91 1
1029 | 240 91 2
1030 | 60 92 1
1031 | 91 92 1
1032 | 17 93 1
1033 | 37 94 1
1034 | 64 94 3
1035 | 72 94 3
1036 | 73 94 1
1037 | 132 94 1
1038 | 146 94 1
1039 | 217 94 1
1040 | 7 95 1
1041 | 64 95 1
1042 | 72 95 1
1043 | 59 96 1
1044 | 143 96 2
1045 | 205 96 3
1046 | 207 96 4
1047 | 208 96 3
1048 | 241 96 5
1049 | 126 97 5
1050 | 128 97 1
1051 | 173 97 4
1052 | 207 97 1
1053 | 97 98 1
1054 | 166 98 1
1055 | 167 98 1
1056 | 168 98 1
1057 | 177 98 8
1058 | 178 98 2
1059 | 188 98 2
1060 | 196 98 4
1061 | 251 98 1
1062 | 252 98 1
1063 | 254 98 4
1064 | 255 98 15
1065 | 279 98 9
1066 | 281 98 15
1067 | 17 99 2
1068 | 43 99 2
1069 | 66 99 2
1070 | 68 99 1
1071 | 102 99 4
1072 | 122 99 2
1073 | 124 99 2
1074 | 151 99 1
1075 | 185 99 1
1076 | 199 99 1
1077 | 203 99 4
1078 | 205 99 7
1079 | 206 99 2
1080 | 207 99 1
1081 | 208 99 7
1082 | 216 99 2
1083 | 226 99 1
1084 | 227 99 1
1085 | 257 99 1
1086 | 53 100 4
1087 | 60 100 1
1088 | 106 100 3
1089 | 135 100 1
1090 | 138 100 1
1091 | 103 101 2
1092 | 117 101 3
1093 | 121 101 8
1094 | 64 102 1
1095 | 94 102 1
1096 | 101 102 1
1097 | 114 102 1
1098 | 204 102 1
1099 | 209 102 1
1100 | 9 103 2
1101 | 11 103 13
1102 | 60 103 5
1103 | 101 103 11
1104 | 104 103 6
1105 | 114 103 2
1106 | 121 103 7
1107 | 137 103 1
1108 | 138 103 3
1109 | 143 103 1
1110 | 192 103 2
1111 | 209 103 10
1112 | 9 104 2
1113 | 10 104 1
1114 | 88 104 1
1115 | 101 104 2
1116 | 106 104 3
1117 | 111 104 2
1118 | 117 104 1
1119 | 124 104 3
1120 | 138 104 1
1121 | 140 104 1
1122 | 199 104 3
1123 | 94 105 2
1124 | 101 105 2
1125 | 103 105 7
1126 | 124 105 1
1127 | 138 105 3
1128 | 150 105 1
1129 | 224 105 6
1130 | 60 106 1
1131 | 108 106 1
1132 | 110 106 2
1133 | 111 106 4
1134 | 112 106 1
1135 | 136 106 1
1136 | 140 106 3
1137 | 199 106 3
1138 | 22 107 1
1139 | 68 107 1
1140 | 88 107 1
1141 | 106 107 1
1142 | 110 107 1
1143 | 123 107 1
1144 | 131 107 1
1145 | 100 108 1
1146 | 106 108 1
1147 | 116 108 12
1148 | 125 108 9
1149 | 129 108 11
1150 | 136 108 6
1151 | 140 108 2
1152 | 9 109 1
1153 | 10 109 2
1154 | 60 109 4
1155 | 104 109 5
1156 | 106 109 8
1157 | 108 109 6
1158 | 111 109 4
1159 | 123 109 1
1160 | 140 109 7
1161 | 143 109 1
1162 | 192 109 1
1163 | 88 110 1
1164 | 106 110 1
1165 | 122 110 3
1166 | 144 110 1
1167 | 192 110 2
1168 | 206 110 2
1169 | 106 111 2
1170 | 140 111 2
1171 | 192 111 2
1172 | 199 111 1
1173 | 106 112 1
1174 | 110 112 1
1175 | 188 112 1
1176 | 196 112 2
1177 | 199 112 1
1178 | 206 112 4
1179 | 227 112 1
1180 | 35 113 1
1181 | 106 113 2
1182 | 109 113 3
1183 | 111 113 1
1184 | 138 113 2
1185 | 199 113 2
1186 | 223 113 5
1187 | 17 114 5
1188 | 103 114 2
1189 | 116 114 4
1190 | 117 114 7
1191 | 128 114 2
1192 | 136 114 4
1193 | 139 114 2
1194 | 141 114 9
1195 | 142 114 11
1196 | 146 114 6
1197 | 150 114 5
1198 | 192 114 2
1199 | 15 115 1
1200 | 17 115 1
1201 | 29 115 2
1202 | 73 115 1
1203 | 94 115 1
1204 | 102 115 2
1205 | 103 115 7
1206 | 109 115 1
1207 | 110 115 3
1208 | 116 115 7
1209 | 121 115 1
1210 | 122 115 11
1211 | 123 115 12
1212 | 125 115 3
1213 | 130 115 2
1214 | 134 115 1
1215 | 136 115 3
1216 | 139 115 1
1217 | 143 115 1
1218 | 148 115 1
1219 | 194 115 3
1220 | 196 115 5
1221 | 211 115 1
1222 | 225 115 1
1223 | 240 115 1
1224 | 2 116 1
1225 | 17 116 3
1226 | 114 116 2
1227 | 122 116 1
1228 | 123 116 1
1229 | 128 116 3
1230 | 129 116 1
1231 | 137 116 1
1232 | 140 116 2
1233 | 17 117 2
1234 | 143 117 2
1235 | 192 117 1
1236 | 4 118 1
1237 | 13 118 2
1238 | 17 118 1
1239 | 87 118 3
1240 | 88 118 1
1241 | 110 118 5
1242 | 117 118 2
1243 | 119 118 2
1244 | 120 118 3
1245 | 122 118 5
1246 | 126 118 3
1247 | 130 118 6
1248 | 143 118 3
1249 | 150 118 1
1250 | 171 118 4
1251 | 173 118 6
1252 | 185 118 1
1253 | 192 118 3
1254 | 199 118 1
1255 | 202 118 1
1256 | 225 118 10
1257 | 227 118 1
1258 | 256 118 1
1259 | 257 118 1
1260 | 258 118 1
1261 | 262 118 4
1262 | 3 119 2
1263 | 5 119 1
1264 | 12 119 1
1265 | 15 119 1
1266 | 17 119 4
1267 | 68 119 1
1268 | 85 119 3
1269 | 99 119 4
1270 | 110 119 1
1271 | 117 119 4
1272 | 118 119 2
1273 | 122 119 2
1274 | 124 119 1
1275 | 126 119 6
1276 | 130 119 14
1277 | 150 119 1
1278 | 151 119 1
1279 | 171 119 2
1280 | 173 119 1
1281 | 185 119 3
1282 | 195 119 23
1283 | 202 119 1
1284 | 204 119 2
1285 | 205 119 6
1286 | 208 119 6
1287 | 217 119 1
1288 | 221 119 1
1289 | 225 119 2
1290 | 227 119 1
1291 | 229 119 1
1292 | 258 119 1
1293 | 17 120 1
1294 | 43 120 2
1295 | 88 120 1
1296 | 96 120 2
1297 | 99 120 1
1298 | 107 120 3
1299 | 124 120 1
1300 | 126 120 3
1301 | 131 120 1
1302 | 143 120 1
1303 | 150 120 1
1304 | 171 120 1
1305 | 192 120 2
1306 | 199 120 4
1307 | 200 120 4
1308 | 202 120 1
1309 | 205 120 2
1310 | 206 120 1
1311 | 208 120 3
1312 | 221 120 1
1313 | 17 121 2
1314 | 143 121 1
1315 | 192 121 2
1316 | 209 121 1
1317 | 123 122 1
1318 | 124 122 2
1319 | 125 122 1
1320 | 29 123 10
1321 | 109 123 1
1322 | 110 123 9
1323 | 116 123 3
1324 | 122 123 10
1325 | 125 123 2
1326 | 139 123 4
1327 | 144 123 3
1328 | 148 123 11
1329 | 149 123 7
1330 | 151 123 4
1331 | 120 124 1
1332 | 122 124 1
1333 | 150 124 2
1334 | 199 124 2
1335 | 200 124 5
1336 | 203 124 6
1337 | 204 124 2
1338 | 216 124 1
1339 | 229 124 1
1340 | 230 124 1
1341 | 260 124 1
1342 | 11 125 1
1343 | 114 125 1
1344 | 116 125 2
1345 | 122 125 3
1346 | 123 125 1
1347 | 136 125 2
1348 | 137 125 2
1349 | 144 125 2
1350 | 3 126 28
1351 | 4 126 1
1352 | 96 126 2
1353 | 99 126 2
1354 | 112 126 5
1355 | 118 126 1
1356 | 120 126 1
1357 | 122 126 2
1358 | 138 126 5
1359 | 172 126 2
1360 | 173 126 1
1361 | 178 126 2
1362 | 202 126 1
1363 | 206 126 1
1364 | 207 126 4
1365 | 217 126 4
1366 | 218 126 2
1367 | 225 126 2
1368 | 226 126 2
1369 | 227 126 1
1370 | 249 126 28
1371 | 256 126 13
1372 | 257 126 1
1373 | 258 126 6
1374 | 259 126 2
1375 | 116 127 3
1376 | 128 127 5
1377 | 209 127 5
1378 | 127 128 1
1379 | 141 128 1
1380 | 116 129 1
1381 | 135 129 5
1382 | 140 129 9
1383 | 2 130 1
1384 | 64 130 2
1385 | 68 130 1
1386 | 173 130 1
1387 | 225 130 1
1388 | 240 130 1
1389 | 2 131 12
1390 | 21 131 2
1391 | 73 131 5
1392 | 91 131 4
1393 | 107 131 4
1394 | 109 131 4
1395 | 112 131 1
1396 | 115 131 1
1397 | 132 131 5
1398 | 138 131 1
1399 | 143 131 1
1400 | 199 131 1
1401 | 206 131 4
1402 | 212 131 9
1403 | 213 131 1
1404 | 214 131 1
1405 | 216 131 1
1406 | 219 131 3
1407 | 2 132 1
1408 | 105 132 3
1409 | 115 132 1
1410 | 134 132 9
1411 | 210 132 2
1412 | 219 132 1
1413 | 224 132 5
1414 | 226 132 2
1415 | 21 133 1
1416 | 73 133 4
1417 | 91 133 2
1418 | 102 133 3
1419 | 103 133 3
1420 | 115 133 14
1421 | 117 133 1
1422 | 132 133 3
1423 | 134 133 1
1424 | 192 133 2
1425 | 212 133 2
1426 | 213 133 4
1427 | 214 133 2
1428 | 216 133 2
1429 | 219 133 3
1430 | 115 134 1
1431 | 138 134 1
1432 | 197 134 1
1433 | 203 134 1
1434 | 225 134 1
1435 | 103 136 1
1436 | 135 136 2
1437 | 137 136 1
1438 | 140 136 1
1439 | 144 136 2
1440 | 209 136 4
1441 | 103 137 1
1442 | 43 138 1
1443 | 103 138 1
1444 | 104 138 3
1445 | 109 138 2
1446 | 126 138 4
1447 | 130 138 1
1448 | 172 138 61
1449 | 173 138 4
1450 | 186 138 61
1451 | 202 138 1
1452 | 214 138 1
1453 | 218 138 3
1454 | 219 138 1
1455 | 225 138 1
1456 | 229 138 2
1457 | 230 138 2
1458 | 242 138 3
1459 | 248 138 3
1460 | 249 138 3
1461 | 259 138 5
1462 | 260 138 7
1463 | 262 138 5
1464 | 11 139 1
1465 | 116 139 1
1466 | 125 139 2
1467 | 136 139 4
1468 | 137 139 2
1469 | 144 139 1
1470 | 108 140 1
1471 | 116 140 1
1472 | 123 140 1
1473 | 148 140 1
1474 | 114 141 1
1475 | 150 141 2
1476 | 209 141 1
1477 | 94 142 1
1478 | 114 142 3
1479 | 117 142 1
1480 | 137 142 2
1481 | 141 142 1
1482 | 145 142 4
1483 | 146 142 4
1484 | 150 142 2
1485 | 192 142 1
1486 | 11 143 1
1487 | 85 143 1
1488 | 96 143 7
1489 | 110 143 1
1490 | 120 143 1
1491 | 147 143 1
1492 | 149 143 1
1493 | 151 143 2
1494 | 192 143 3
1495 | 200 143 2
1496 | 206 143 1
1497 | 239 143 1
1498 | 246 143 1
1499 | 262 143 2
1500 | 283 143 1
1501 | 285 143 1
1502 | 142 145 1
1503 | 146 145 1
1504 | 99 146 1
1505 | 112 146 1
1506 | 124 146 2
1507 | 145 146 13
1508 | 150 146 1
1509 | 200 146 1
1510 | 203 146 2
1511 | 219 146 1
1512 | 227 146 1
1513 | 229 146 2
1514 | 230 146 2
1515 | 285 146 1
1516 | 151 147 2
1517 | 192 147 1
1518 | 147 148 4
1519 | 149 148 4
1520 | 151 148 2
1521 | 120 149 1
1522 | 143 149 1
1523 | 147 149 13
1524 | 199 149 2
1525 | 204 149 1
1526 | 214 149 1
1527 | 227 149 1
1528 | 246 149 3
1529 | 114 150 2
1530 | 142 150 2
1531 | 148 151 1
1532 | 3 152 1
1533 | 4 152 5
1534 | 5 152 5
1535 | 13 152 1
1536 | 85 152 1
1537 | 87 152 1
1538 | 118 152 1
1539 | 119 152 1
1540 | 126 152 1
1541 | 173 152 1
1542 | 188 152 1
1543 | 231 152 1
1544 | 3 153 4
1545 | 13 153 4
1546 | 85 153 2
1547 | 87 153 2
1548 | 118 153 2
1549 | 119 153 2
1550 | 254 153 1
1551 | 3 154 9
1552 | 13 154 9
1553 | 118 154 2
1554 | 119 154 2
1555 | 178 154 2
1556 | 254 154 1
1557 | 3 155 3
1558 | 4 155 2
1559 | 5 155 2
1560 | 13 155 3
1561 | 126 155 2
1562 | 173 155 2
1563 | 231 155 1
1564 | 3 156 2
1565 | 4 156 1
1566 | 5 156 1
1567 | 13 156 2
1568 | 85 156 2
1569 | 87 156 2
1570 | 190 156 2
1571 | 198 156 2
1572 | 233 156 1
1573 | 3 157 2
1574 | 13 157 2
1575 | 85 157 2
1576 | 87 157 2
1577 | 118 157 1
1578 | 119 157 1
1579 | 169 157 1
1580 | 3 158 4
1581 | 13 158 4
1582 | 85 158 1
1583 | 87 158 1
1584 | 118 158 1
1585 | 119 158 1
1586 | 143 158 1
1587 | 192 158 1
1588 | 193 158 1
1589 | 3 159 2
1590 | 13 159 2
1591 | 85 159 2
1592 | 87 159 2
1593 | 193 159 1
1594 | 3 160 4
1595 | 4 160 12
1596 | 5 160 12
1597 | 13 160 4
1598 | 118 160 3
1599 | 119 160 3
1600 | 152 160 1
1601 | 207 160 2
1602 | 220 160 2
1603 | 3 161 4
1604 | 4 161 6
1605 | 5 161 6
1606 | 13 161 4
1607 | 118 161 2
1608 | 119 161 2
1609 | 126 161 1
1610 | 155 161 1
1611 | 173 161 1
1612 | 188 161 1
1613 | 3 162 9
1614 | 4 162 4
1615 | 5 162 4
1616 | 13 162 9
1617 | 118 162 6
1618 | 119 162 6
1619 | 154 162 1
1620 | 156 162 1
1621 | 234 162 2
1622 | 3 163 12
1623 | 4 163 1
1624 | 5 163 1
1625 | 13 163 12
1626 | 118 163 4
1627 | 119 163 4
1628 | 158 163 1
1629 | 162 163 1
1630 | 276 163 2
1631 | 3 164 9
1632 | 13 164 9
1633 | 85 164 1
1634 | 87 164 1
1635 | 118 164 3
1636 | 119 164 3
1637 | 143 164 2
1638 | 159 164 1
1639 | 163 164 1
1640 | 192 164 1
1641 | 3 165 2
1642 | 13 165 2
1643 | 143 165 1
1644 | 164 165 1
1645 | 273 165 1
1646 | 277 165 2
1647 | 3 166 7
1648 | 13 166 7
1649 | 153 166 1
1650 | 165 166 1
1651 | 278 166 2
1652 | 3 167 14
1653 | 13 167 14
1654 | 98 167 2
1655 | 118 167 1
1656 | 119 167 1
1657 | 154 167 1
1658 | 166 167 1
1659 | 178 167 3
1660 | 196 167 2
1661 | 227 167 2
1662 | 229 167 1
1663 | 3 168 5
1664 | 13 168 5
1665 | 43 168 1
1666 | 118 168 1
1667 | 119 168 1
1668 | 154 168 1
1669 | 167 168 1
1670 | 178 168 5
1671 | 251 168 1
1672 | 260 168 6
1673 | 3 169 2
1674 | 4 169 2
1675 | 5 169 2
1676 | 13 169 3
1677 | 43 169 1
1678 | 126 169 5
1679 | 138 169 3
1680 | 173 169 5
1681 | 3 170 2
1682 | 13 170 2
1683 | 126 170 3
1684 | 138 170 1
1685 | 143 170 1
1686 | 173 170 3
1687 | 13 171 5
1688 | 118 171 3
1689 | 173 171 1
1690 | 178 171 2
1691 | 195 171 1
1692 | 259 171 1
1693 | 13 172 2
1694 | 126 172 1
1695 | 186 172 1
1696 | 203 172 1
1697 | 218 172 10
1698 | 219 172 4
1699 | 5 173 1
1700 | 13 173 28
1701 | 43 173 1
1702 | 96 173 2
1703 | 99 173 4
1704 | 112 173 7
1705 | 119 173 1
1706 | 120 173 3
1707 | 126 173 3
1708 | 178 173 3
1709 | 185 173 3
1710 | 186 173 2
1711 | 202 173 2
1712 | 204 173 4
1713 | 205 173 2
1714 | 206 173 1
1715 | 207 173 6
1716 | 208 173 2
1717 | 217 173 2
1718 | 221 173 1
1719 | 227 173 1
1720 | 241 173 2
1721 | 248 173 28
1722 | 258 173 3
1723 | 260 173 8
1724 | 262 173 1
1725 | 3 174 1
1726 | 4 174 8
1727 | 5 174 8
1728 | 13 174 1
1729 | 43 174 1
1730 | 118 174 3
1731 | 119 174 3
1732 | 134 174 1
1733 | 143 174 1
1734 | 188 174 5
1735 | 192 174 1
1736 | 5 175 17
1737 | 13 175 2
1738 | 119 175 6
1739 | 120 175 1
1740 | 188 175 7
1741 | 3 176 10
1742 | 13 176 10
1743 | 85 176 1
1744 | 87 176 1
1745 | 247 176 1
1746 | 3 177 14
1747 | 13 177 14
1748 | 118 177 1
1749 | 119 177 1
1750 | 176 177 1
1751 | 178 177 1
1752 | 227 177 2
1753 | 3 178 2
1754 | 13 178 2
1755 | 138 178 1
1756 | 177 178 1
1757 | 184 178 1
1758 | 221 178 1
1759 | 222 178 1
1760 | 255 178 1
1761 | 256 178 2
1762 | 257 178 1
1763 | 258 178 1
1764 | 259 178 1
1765 | 260 178 1
1766 | 3 179 3
1767 | 4 179 2
1768 | 5 179 2
1769 | 13 179 3
1770 | 118 179 1
1771 | 119 179 1
1772 | 134 179 1
1773 | 174 179 1
1774 | 197 179 1
1775 | 238 179 1
1776 | 3 180 4
1777 | 4 180 5
1778 | 5 180 5
1779 | 13 180 4
1780 | 118 180 3
1781 | 119 180 3
1782 | 134 180 1
1783 | 179 180 1
1784 | 3 181 4
1785 | 4 181 1
1786 | 5 181 1
1787 | 13 181 4
1788 | 85 181 1
1789 | 87 181 1
1790 | 180 181 1
1791 | 3 182 6
1792 | 13 182 6
1793 | 118 182 1
1794 | 119 182 1
1795 | 143 182 1
1796 | 181 182 1
1797 | 3 183 4
1798 | 4 183 1
1799 | 5 183 1
1800 | 13 183 4
1801 | 118 183 2
1802 | 119 183 2
1803 | 143 183 1
1804 | 182 183 1
1805 | 192 183 1
1806 | 3 184 2
1807 | 13 184 2
1808 | 178 184 11
1809 | 285 184 1
1810 | 3 185 5
1811 | 119 185 3
1812 | 126 185 1
1813 | 260 185 1
1814 | 3 186 2
1815 | 43 186 1
1816 | 138 186 2
1817 | 172 186 1
1818 | 173 186 1
1819 | 200 186 1
1820 | 214 186 4
1821 | 262 186 5
1822 | 3 187 2
1823 | 4 187 17
1824 | 99 187 1
1825 | 118 187 6
1826 | 143 187 3
1827 | 192 187 3
1828 | 85 188 1
1829 | 87 188 1
1830 | 91 188 2
1831 | 112 188 4
1832 | 126 188 1
1833 | 146 188 1
1834 | 149 188 1
1835 | 173 188 1
1836 | 196 188 2
1837 | 200 188 1
1838 | 203 188 1
1839 | 204 188 4
1840 | 205 188 4
1841 | 208 188 4
1842 | 246 188 1
1843 | 285 188 1
1844 | 85 189 1
1845 | 87 189 1
1846 | 183 189 1
1847 | 4 190 1
1848 | 5 190 1
1849 | 85 190 1
1850 | 87 190 1
1851 | 156 190 16
1852 | 157 190 2
1853 | 161 190 6
1854 | 162 190 23
1855 | 169 190 1
1856 | 180 190 2
1857 | 205 190 2
1858 | 208 190 2
1859 | 231 190 22
1860 | 233 190 9
1861 | 234 190 1
1862 | 238 190 4
1863 | 246 190 1
1864 | 26 191 1
1865 | 38 191 1
1866 | 79 191 1
1867 | 80 191 1
1868 | 81 191 1
1869 | 82 191 1
1870 | 85 191 6
1871 | 87 191 6
1872 | 89 191 1
1873 | 95 191 1
1874 | 112 191 3
1875 | 172 191 4
1876 | 175 191 1
1877 | 186 191 4
1878 | 187 191 1
1879 | 196 191 5
1880 | 204 191 3
1881 | 205 191 2
1882 | 208 191 2
1883 | 214 191 5
1884 | 218 191 1
1885 | 219 191 5
1886 | 225 191 3
1887 | 227 191 2
1888 | 243 191 1
1889 | 244 191 1
1890 | 248 191 1
1891 | 249 191 1
1892 | 253 191 1
1893 | 296 191 1
1894 | 297 191 1
1895 | 87 192 1
1896 | 99 192 1
1897 | 104 192 1
1898 | 108 192 1
1899 | 114 192 1
1900 | 143 192 1
1901 | 146 192 3
1902 | 151 192 1
1903 | 203 192 1
1904 | 226 192 4
1905 | 261 192 2
1906 | 118 193 1
1907 | 119 193 1
1908 | 126 193 7
1909 | 138 193 1
1910 | 173 193 7
1911 | 9 194 1
1912 | 112 194 2
1913 | 118 194 1
1914 | 119 194 1
1915 | 146 194 1
1916 | 149 194 1
1917 | 196 194 5
1918 | 204 194 2
1919 | 245 194 2
1920 | 284 194 2
1921 | 118 195 1
1922 | 119 195 1
1923 | 185 195 1
1924 | 205 195 3
1925 | 208 195 3
1926 | 4 196 1
1927 | 5 196 1
1928 | 146 196 1
1929 | 149 196 1
1930 | 194 196 1
1931 | 227 196 1
1932 | 245 196 1
1933 | 284 196 2
1934 | 4 197 6
1935 | 5 197 6
1936 | 134 197 3
1937 | 201 197 2
1938 | 4 198 1
1939 | 5 198 1
1940 | 134 198 1
1941 | 155 198 1
1942 | 156 198 2
1943 | 160 198 1
1944 | 161 198 23
1945 | 179 198 3
1946 | 180 198 3
1947 | 220 198 1
1948 | 231 198 9
1949 | 233 198 1
1950 | 238 198 6
1951 | 246 198 1
1952 | 96 199 1
1953 | 99 199 1
1954 | 112 199 3
1955 | 124 199 2
1956 | 150 199 1
1957 | 206 199 1
1958 | 226 199 1
1959 | 229 199 1
1960 | 120 200 1
1961 | 149 200 1
1962 | 150 200 1
1963 | 151 200 2
1964 | 188 200 1
1965 | 199 200 5
1966 | 203 200 5
1967 | 205 200 1
1968 | 208 200 1
1969 | 245 200 1
1970 | 284 200 1
1971 | 124 201 1
1972 | 134 201 2
1973 | 146 201 1
1974 | 149 201 1
1975 | 152 201 1
1976 | 160 201 1
1977 | 161 201 1
1978 | 179 201 1
1979 | 197 201 3
1980 | 199 201 1
1981 | 220 201 1
1982 | 231 201 1
1983 | 239 201 1
1984 | 246 201 1
1985 | 283 201 1
1986 | 104 202 1
1987 | 112 202 1
1988 | 124 202 1
1989 | 138 202 3
1990 | 173 202 1
1991 | 204 202 1
1992 | 99 203 1
1993 | 124 203 5
1994 | 143 203 2
1995 | 150 203 4
1996 | 151 203 3
1997 | 192 203 6
1998 | 200 203 4
1999 | 206 203 1
2000 | 227 203 1
2001 | 229 203 3
2002 | 245 203 1
2003 | 284 203 1
2004 | 124 204 4
2005 | 202 204 1
2006 | 216 204 3
2007 | 219 204 1
2008 | 227 204 1
2009 | 96 205 1
2010 | 120 205 2
2011 | 143 205 2
2012 | 195 205 1
2013 | 208 205 4
2014 | 226 205 2
2015 | 227 205 2
2016 | 251 205 1
2017 | 120 206 1
2018 | 123 206 2
2019 | 140 206 2
2020 | 143 206 3
2021 | 149 206 1
2022 | 151 206 1
2023 | 205 206 1
2024 | 208 206 1
2025 | 99 207 1
2026 | 214 207 1
2027 | 218 207 1
2028 | 96 208 4
2029 | 99 208 1
2030 | 171 208 1
2031 | 205 208 5
2032 | 226 208 1
2033 | 227 208 2
2034 | 11 209 3
2035 | 14 210 3
2036 | 21 210 1
2037 | 64 210 1
2038 | 76 210 1
2039 | 107 210 1
2040 | 21 211 1
2041 | 131 211 2
2042 | 133 211 1
2043 | 194 211 4
2044 | 196 211 4
2045 | 212 211 2
2046 | 86 212 2
2047 | 131 212 3
2048 | 133 212 3
2049 | 138 212 1
2050 | 236 212 3
2051 | 68 213 1
2052 | 90 213 2
2053 | 131 213 3
2054 | 133 213 2
2055 | 138 213 1
2056 | 237 213 3
2057 | 9 214 1
2058 | 10 214 4
2059 | 49 214 1
2060 | 91 214 1
2061 | 131 214 1
2062 | 172 214 22
2063 | 194 214 2
2064 | 196 214 7
2065 | 211 214 1
2066 | 215 214 1
2067 | 218 214 11
2068 | 9 215 1
2069 | 48 215 1
2070 | 73 215 1
2071 | 134 215 2
2072 | 194 215 2
2073 | 196 215 2
2074 | 240 215 1
2075 | 64 216 1
2076 | 114 216 1
2077 | 150 216 1
2078 | 192 216 3
2079 | 94 217 1
2080 | 150 217 1
2081 | 216 217 2
2082 | 240 217 1
2083 | 172 218 1
2084 | 186 218 1
2085 | 214 218 1
2086 | 219 218 1
2087 | 10 219 1
2088 | 43 219 1
2089 | 68 219 1
2090 | 91 219 3
2091 | 186 219 22
2092 | 194 219 1
2093 | 196 219 7
2094 | 211 219 3
2095 | 215 219 4
2096 | 134 220 1
2097 | 146 220 1
2098 | 149 220 1
2099 | 161 220 1
2100 | 179 220 8
2101 | 180 220 18
2102 | 188 220 1
2103 | 197 220 8
2104 | 201 220 1
2105 | 205 220 2
2106 | 208 220 2
2107 | 231 220 4
2108 | 233 220 1
2109 | 238 220 19
2110 | 246 220 2
2111 | 283 220 1
2112 | 173 221 1
2113 | 188 221 1
2114 | 205 221 3
2115 | 257 221 1
2116 | 98 222 1
2117 | 167 222 1
2118 | 168 222 1
2119 | 178 222 2
2120 | 188 222 3
2121 | 205 222 1
2122 | 208 222 1
2123 | 285 222 1
2124 | 105 223 1
2125 | 113 224 3
2126 | 68 225 2
2127 | 102 225 1
2128 | 130 225 1
2129 | 64 226 1
2130 | 205 226 2
2131 | 207 226 3
2132 | 217 226 5
2133 | 195 227 1
2134 | 200 227 2
2135 | 203 227 2
2136 | 205 227 1
2137 | 208 227 1
2138 | 229 227 5
2139 | 230 227 3
2140 | 98 228 1
2141 | 154 228 16
2142 | 166 228 1
2143 | 167 228 23
2144 | 168 228 23
2145 | 177 228 2
2146 | 200 228 1
2147 | 203 228 1
2148 | 254 228 7
2149 | 285 228 1
2150 | 227 229 2
2151 | 230 229 6
2152 | 227 230 1
2153 | 229 230 5
2154 | 157 232 16
2155 | 158 232 2
2156 | 162 232 6
2157 | 163 232 23
2158 | 169 232 9
2159 | 181 232 1
2160 | 182 232 3
2161 | 193 232 1
2162 | 205 232 4
2163 | 208 232 4
2164 | 231 232 7
2165 | 233 232 22
2166 | 234 232 1
2167 | 239 232 2
2168 | 246 232 2
2169 | 43 233 1
2170 | 126 233 4
2171 | 138 233 1
2172 | 173 233 4
2173 | 112 234 1
2174 | 162 234 1
2175 | 169 234 4
2176 | 180 234 11
2177 | 181 234 8
2178 | 204 234 1
2179 | 205 234 1
2180 | 208 234 1
2181 | 233 234 4
2182 | 238 234 1
2183 | 239 234 4
2184 | 246 234 4
2185 | 263 234 15
2186 | 264 234 6
2187 | 285 234 1
2188 | 158 235 16
2189 | 159 235 2
2190 | 163 235 6
2191 | 169 235 22
2192 | 170 235 1
2193 | 182 235 2
2194 | 193 235 9
2195 | 233 235 7
2196 | 246 235 4
2197 | 276 235 1
2198 | 9 236 1
2199 | 94 236 1
2200 | 10 237 1
2201 | 88 237 1
2202 | 190 238 2
2203 | 198 238 2
2204 | 143 239 4
2205 | 192 239 2
2206 | 205 239 2
2207 | 208 239 2
2208 | 238 239 1
2209 | 246 239 1
2210 | 283 239 1
2211 | 217 240 1
2212 | 96 241 1
2213 | 96 242 1
2214 | 143 245 5
2215 | 192 245 10
2216 | 284 245 2
2217 | 285 245 1
2218 | 143 246 2
2219 | 205 246 1
2220 | 208 246 1
2221 | 245 246 1
2222 | 172 247 1
2223 | 186 247 1
2224 | 280 247 1
2225 | 249 248 1
2226 | 248 249 1
2227 | 153 250 16
2228 | 154 250 2
2229 | 166 250 23
2230 | 177 250 3
2231 | 254 250 22
2232 | 278 250 1
2233 | 285 250 1
2234 | 196 251 1
2235 | 205 253 2
2236 | 208 253 2
2237 | 221 253 3
2238 | 246 253 1
2239 | 257 253 3
2240 | 126 254 4
2241 | 138 254 2
2242 | 173 254 4
2243 | 178 254 4
2244 | 126 255 1
2245 | 138 255 2
2246 | 173 255 1
2247 | 171 256 1
2248 | 229 256 5
2249 | 230 256 1
2250 | 258 256 1
2251 | 126 257 1
2252 | 171 257 1
2253 | 185 257 1
2254 | 208 257 3
2255 | 221 257 1
2256 | 229 258 4
2257 | 230 258 5
2258 | 256 258 1
2259 | 260 259 1
2260 | 126 263 1
2261 | 173 263 1
2262 | 126 264 4
2263 | 173 264 4
2264 | 126 265 1
2265 | 173 265 1
2266 | 126 266 5
2267 | 173 266 5
2268 | 126 267 3
2269 | 173 267 3
2270 | 126 268 2
2271 | 173 268 2
2272 | 153 269 2
2273 | 165 269 1
2274 | 247 269 2
2275 | 254 269 9
2276 | 275 269 16
2277 | 278 269 1
2278 | 279 269 7
2279 | 285 269 1
2280 | 159 270 16
2281 | 163 270 1
2282 | 164 270 23
2283 | 169 270 7
2284 | 170 270 9
2285 | 189 270 3
2286 | 193 270 22
2287 | 246 270 3
2288 | 271 270 2
2289 | 276 270 1
2290 | 279 270 1
2291 | 170 271 1
2292 | 164 272 1
2293 | 170 272 22
2294 | 189 272 2
2295 | 193 272 7
2296 | 246 272 5
2297 | 271 272 16
2298 | 273 272 2
2299 | 277 272 1
2300 | 279 272 9
2301 | 285 272 1
2302 | 170 273 1
2303 | 165 274 23
2304 | 170 274 7
2305 | 247 274 3
2306 | 254 274 1
2307 | 273 274 16
2308 | 275 274 2
2309 | 277 274 1
2310 | 279 274 22
2311 | 285 274 1
2312 | 279 275 1
2313 | 163 276 1
2314 | 169 276 9
2315 | 182 276 8
2316 | 183 276 8
2317 | 193 276 4
2318 | 246 276 4
2319 | 264 276 15
2320 | 265 276 15
2321 | 266 276 6
2322 | 285 276 1
2323 | 164 277 1
2324 | 165 277 1
2325 | 170 277 4
2326 | 189 277 8
2327 | 193 277 9
2328 | 246 277 10
2329 | 266 277 15
2330 | 267 277 15
2331 | 268 277 6
2332 | 280 277 8
2333 | 284 277 2
2334 | 285 277 1
2335 | 170 278 9
2336 | 176 278 8
2337 | 247 278 8
2338 | 268 278 15
2339 | 279 278 4
2340 | 281 278 6
2341 | 282 278 15
2342 | 285 278 1
2343 | 189 280 1
2344 | 246 283 2
2345 | 245 284 1
2346 | 246 284 1
2347 |
--------------------------------------------------------------------------------
/datasets/eco-everglades/README.md:
--------------------------------------------------------------------------------
1 | eco-florida also exists and is slightly larger
2 |
3 | @article{ulanowicz1998network,
4 | title={Network analysis of trophic dynamics in south florida ecosystems},
5 | author={Ulanowicz, Robert E and DeAngelis, Donald L},
6 | journal={FY97: The Florida Bay Ecosystem},
7 | pages={20688--20038},
8 | year={1998}
9 | }
10 |
11 | @article{melian2004food,
12 | title={Food web cohesion},
13 | author={Meli{\'a}n,
14 | Carlos J and Bascompte, Jordi},
15 | journal={Ecology},
16 | volume={85},
17 | number={2},
18 | pages={352--358},
19 | year={2004},
20 | publisher={Eco Soc America}
21 | }
22 |
--------------------------------------------------------------------------------
/datasets/eco-everglades/eco-everglades.edges:
--------------------------------------------------------------------------------
1 | # directed, weighted
2 | 67 3 2.832627E+03
3 | 67 4 1.313124E+03
4 | 67 5 5.999271E+02
5 | 67 6 1.522945E+03
6 | 67 44 3.506437E+00
7 | 2 68 6.954134E+00
8 | 7 68 1.060947E-01
9 | 8 68 1.493327E-01
10 | 10 68 7.353957E-03
11 | 11 68 6.262771E-03
12 | 12 68 1.667374E-03
13 | 15 68 2.208839E-03
14 | 16 68 5.705550E-03
15 | 17 68 4.081583E-02
16 | 18 68 2.295798E-02
17 | 19 68 3.137470E-01
18 | 20 68 4.443052E-02
19 | 21 68 6.572313E-01
20 | 22 68 8.479014E-02
21 | 23 68 9.113920E-02
22 | 24 68 1.170176E-01
23 | 25 68 4.003657E-03
24 | 26 68 1.623876E-03
25 | 27 68 6.132517E-02
26 | 28 68 7.462619E-02
27 | 29 68 1.220249E-01
28 | 30 68 5.598125E-02
29 | 31 68 2.774792E-03
30 | 32 68 5.282542E-02
31 | 33 68 4.014013E-02
32 | 34 68 2.200659E-03
33 | 35 68 3.471817E-04
34 | 36 68 1.866019E-02
35 | 37 68 2.691433E-04
36 | 38 68 9.701878E-03
37 | 39 68 6.466887E-03
38 | 40 68 7.506015E-04
39 | 42 68 3.338533E-02
40 | 43 68 1.634296E-01
41 | 44 68 1.435334E+00
42 | 45 68 3.398583E-03
43 | 46 68 3.328571E-02
44 | 47 68 4.880123E-04
45 | 48 68 2.661771E-04
46 | 49 68 2.112655E-04
47 | 50 68 3.933792E-03
48 | 51 68 7.269792E-04
49 | 52 68 2.838258E-07
50 | 53 68 1.292006E-03
51 | 54 68 5.591811E-06
52 | 55 68 9.085223E-07
53 | 56 68 6.204215E-06
54 | 57 68 2.021860E-09
55 | 58 68 5.234790E-05
56 | 59 68 2.835357E-07
57 | 60 68 3.054693E-05
58 | 61 68 3.240347E-05
59 | 62 68 2.930178E-06
60 | 63 68 3.757634E-05
61 | 64 68 3.132500E+03
62 | 1 69 1.971203E+02
63 | 2 69 1.741631E+01
64 | 3 69 1.185200E+03
65 | 4 69 6.565620E+02
66 | 5 69 3.003223E+02
67 | 6 69 7.614725E+02
68 | 7 69 2.449617E-01
69 | 8 69 6.403065E-01
70 | 9 69 2.599067E-01
71 | 10 69 2.064564E+00
72 | 11 69 1.197752E+00
73 | 12 69 6.508279E-02
74 | 13 69 2.930824E-01
75 | 14 69 1.180919E-02
76 | 15 69 3.449146E-03
77 | 16 69 9.550515E-03
78 | 17 69 6.233941E-02
79 | 18 69 3.510601E-02
80 | 19 69 5.616774E-01
81 | 20 69 7.508770E-02
82 | 21 69 1.180249E+00
83 | 22 69 1.529920E-01
84 | 23 69 1.657196E-01
85 | 24 69 2.047786E-01
86 | 25 69 6.969879E-03
87 | 26 69 2.608995E-03
88 | 27 69 9.439784E-02
89 | 28 69 1.137745E-01
90 | 29 69 1.846150E-01
91 | 30 69 8.592577E-02
92 | 31 69 4.331010E-03
93 | 32 69 8.070113E-02
94 | 33 69 6.145908E-02
95 | 34 69 3.426982E-03
96 | 35 69 6.704110E-04
97 | 36 69 2.294070E-02
98 | 37 69 8.971911E-04
99 | 38 69 1.113081E-02
100 | 39 69 1.481448E-02
101 | 40 69 3.541093E-03
102 | 41 69 2.232668E-03
103 | 42 69 1.050254E-01
104 | 43 69 1.037990E-01
105 | 44 69 1.302532E+00
106 | 45 69 3.277887E-03
107 | 46 69 9.805296E-01
108 | 47 69 1.654861E-02
109 | 48 69 9.199806E-03
110 | 49 69 8.536721E-03
111 | 50 69 2.647939E-01
112 | 51 69 2.432067E-02
113 | 52 69 7.810919E-06
114 | 53 69 5.728331E-02
115 | 54 69 2.239985E-04
116 | 55 69 4.223832E-05
117 | 56 69 6.859265E-05
118 | 57 69 2.234980E-08
119 | 58 69 6.207178E-04
120 | 59 69 3.111067E-06
121 | 60 69 3.369661E-04
122 | 61 69 3.573975E-04
123 | 62 69 3.338675E-05
124 | 63 69 4.307120E-04
125 | 1 7 3.353614E-02
126 | 1 8 3.017487E-02
127 | 1 9 5.433026E-02
128 | 1 10 6.785787E-01
129 | 1 11 1.866562E-01
130 | 1 12 8.194619E-02
131 | 1 16 1.000438E-02
132 | 1 17 6.148687E-02
133 | 1 20 8.246089E-02
134 | 1 21 1.576596E+00
135 | 1 22 1.570854E-01
136 | 1 23 1.217268E-01
137 | 1 24 1.072036E-01
138 | 1 25 7.853957E-03
139 | 1 26 2.916364E-03
140 | 1 27 2.374244E-02
141 | 1 28 1.285274E-01
142 | 1 29 6.996015E-02
143 | 1 30 3.225018E-02
144 | 1 31 3.730936E-03
145 | 1 35 4.772368E-04
146 | 1 41 7.593397E-05
147 | 1 64 1.034838E+02
148 | 1 65 5.841113E+01
149 | 1 66 2.503334E+01
150 | 2 8 1.620209E-03
151 | 2 9 1.742420E-04
152 | 2 10 2.139871E-03
153 | 2 11 6.823321E-04
154 | 2 12 3.320650E-03
155 | 2 16 3.411990E-05
156 | 2 17 4.185280E-04
157 | 2 20 6.705980E-04
158 | 2 21 1.962723E-01
159 | 2 22 1.920872E-03
160 | 2 23 8.760291E-04
161 | 2 24 5.138940E-04
162 | 2 25 3.582260E-05
163 | 2 26 2.364250E-05
164 | 2 27 1.497080E-04
165 | 2 28 1.039261E-03
166 | 2 29 3.171120E-04
167 | 2 30 3.126720E-04
168 | 2 31 2.771210E-05
169 | 2 35 2.345550E-06
170 | 2 41 3.634260E-07
171 | 2 65 2.516920E+00
172 | 2 66 2.796577E-01
173 | 3 7 6.217856E-01
174 | 3 8 8.101791E-01
175 | 3 9 3.977608E-01
176 | 3 10 4.349064E+00
177 | 3 11 2.789999E+00
178 | 3 16 6.274061E-03
179 | 3 18 2.418132E-03
180 | 3 19 7.809716E-01
181 | 3 21 8.407421E-01
182 | 3 23 2.145552E-01
183 | 3 24 2.277014E-01
184 | 3 35 4.110709E-04
185 | 3 36 5.433327E-03
186 | 3 37 6.117189E-04
187 | 3 41 2.823226E-03
188 | 3 42 3.629630E-02
189 | 3 58 3.460480E-04
190 | 3 65 8.181699E+02
191 | 3 66 8.181699E+02
192 | 4 7 1.385730E-02
193 | 4 8 3.298021E-01
194 | 4 9 1.029013E-01
195 | 4 10 4.669107E-02
196 | 4 11 5.808581E-02
197 | 4 13 6.883413E-01
198 | 4 42 1.446545E-02
199 | 4 46 7.244509E-01
200 | 4 47 2.001850E-02
201 | 4 48 1.456709E-02
202 | 4 49 6.729421E-03
203 | 4 50 2.054220E-01
204 | 4 53 4.173348E-02
205 | 4 56 1.905970E-05
206 | 4 58 1.379130E-04
207 | 4 61 1.978720E-04
208 | 4 62 2.427690E-05
209 | 4 63 7.181320E-05
210 | 4 65 1.092672E+02
211 | 4 66 5.450273E+02
212 | 5 8 3.573497E-02
213 | 5 9 5.630406E-02
214 | 5 10 3.354508E-03
215 | 5 11 1.338962E-03
216 | 5 42 6.616734E-03
217 | 5 56 8.718239E-06
218 | 5 58 6.308379E-05
219 | 5 61 9.050969E-05
220 | 5 63 3.284850E-05
221 | 5 65 9.426867E+01
222 | 5 66 2.059501E+02
223 | 6 8 2.110832E-02
224 | 6 9 4.799895E-02
225 | 6 10 2.498154E-03
226 | 6 11 1.972978E-03
227 | 6 42 1.677685E-02
228 | 6 46 8.402092E-01
229 | 6 53 4.840197E-02
230 | 6 56 2.210520E-05
231 | 6 58 1.599500E-04
232 | 6 61 2.294890E-04
233 | 6 63 8.328801E-05
234 | 6 65 2.387948E+02
235 | 6 66 5.216982E+02
236 | 7 18 3.624972E-03
237 | 7 29 3.166481E-02
238 | 7 34 5.706728E-05
239 | 7 38 1.140716E-03
240 | 7 39 1.678933E-03
241 | 7 40 4.521839E-04
242 | 7 42 3.597044E-03
243 | 7 43 1.274118E-02
244 | 7 45 3.617229E-04
245 | 7 49 3.229319E-04
246 | 7 51 9.671427E-04
247 | 7 52 2.249869E-07
248 | 7 56 1.703370E-06
249 | 7 57 1.062530E-09
250 | 7 58 4.401929E-06
251 | 7 59 4.079289E-06
252 | 7 61 4.904249E-08
253 | 7 63 1.515820E-05
254 | 7 64 1.087112E-01
255 | 7 66 1.630827E-01
256 | 8 14 4.942706E-03
257 | 8 15 1.283052E-03
258 | 8 18 1.371757E-02
259 | 8 27 6.859548E-02
260 | 8 30 6.512573E-02
261 | 8 31 1.503460E-03
262 | 8 32 4.111081E-02
263 | 8 33 4.191682E-02
264 | 8 34 2.416847E-03
265 | 8 38 3.173274E-03
266 | 8 39 4.670500E-03
267 | 8 40 1.257898E-03
268 | 8 42 1.000636E-02
269 | 8 43 3.897574E-02
270 | 8 45 1.006250E-03
271 | 8 49 8.983418E-04
272 | 8 51 2.690424E-03
273 | 8 52 6.258749E-07
274 | 8 56 4.738489E-06
275 | 8 57 2.955770E-09
276 | 8 58 1.224540E-05
277 | 8 61 1.364280E-07
278 | 8 63 4.216749E-05
279 | 8 64 3.129069E-02
280 | 8 66 2.419569E-01
281 | 9 15 2.566099E-04
282 | 9 18 4.660233E-03
283 | 9 27 2.708086E-02
284 | 9 32 6.116910E-02
285 | 9 33 4.191681E-02
286 | 9 34 1.691792E-03
287 | 9 36 1.750738E-02
288 | 9 38 1.215759E-03
289 | 9 39 1.789381E-03
290 | 9 40 4.819308E-04
291 | 9 42 3.833675E-03
292 | 9 43 1.004736E-02
293 | 9 45 3.855188E-04
294 | 9 49 3.441769E-04
295 | 9 51 1.030767E-03
296 | 9 52 2.397879E-07
297 | 9 56 1.815429E-06
298 | 9 57 1.132430E-09
299 | 9 58 4.691518E-06
300 | 9 61 5.226878E-08
301 | 9 63 1.615539E-05
302 | 9 64 9.994257E-02
303 | 9 66 1.889512E-01
304 | 10 5 7.174525E-01
305 | 10 8 2.620020E-02
306 | 10 9 3.273485E-03
307 | 10 11 1.108591E-02
308 | 10 12 4.804655E-02
309 | 10 16 4.152004E-03
310 | 10 17 3.280477E-03
311 | 10 18 1.716434E-02
312 | 10 20 5.172484E-02
313 | 10 21 4.253410E-02
314 | 10 22 3.784418E-02
315 | 10 23 3.418035E-02
316 | 10 24 6.133210E-03
317 | 10 25 4.498219E-03
318 | 10 26 1.222773E-03
319 | 10 27 3.282566E-02
320 | 10 28 4.904800E-02
321 | 10 29 1.204628E-01
322 | 10 30 2.999161E-02
323 | 10 31 1.533087E-03
324 | 10 32 9.705959E-03
325 | 10 33 1.723829E-02
326 | 10 34 7.266128E-04
327 | 10 35 1.140100E-04
328 | 10 37 6.117188E-04
329 | 10 38 1.031012E-02
330 | 10 39 1.517468E-02
331 | 10 40 4.086969E-03
332 | 10 42 3.251112E-02
333 | 10 43 1.151585E-01
334 | 10 45 3.269354E-03
335 | 10 49 2.918756E-03
336 | 10 51 8.741319E-03
337 | 10 52 2.033500E-06
338 | 10 56 1.539560E-05
339 | 10 57 9.603447E-09
340 | 10 58 3.978599E-05
341 | 10 61 4.432599E-07
342 | 10 62 2.120889E-05
343 | 10 63 1.370040E-04
344 | 10 64 1.066760E+00
345 | 10 66 1.290145E+00
346 | 11 8 1.783092E-02
347 | 11 9 1.774791E-03
348 | 11 12 3.831523E-02
349 | 11 15 1.240000E-04
350 | 11 16 2.263106E-03
351 | 11 17 5.698589E-03
352 | 11 18 2.378128E-02
353 | 11 20 6.918392E-02
354 | 11 21 4.319864E-02
355 | 11 22 1.178411E-01
356 | 11 23 3.335199E-02
357 | 11 25 3.086043E-03
358 | 11 26 1.627738E-03
359 | 11 27 2.768201E-02
360 | 11 28 5.568821E-02
361 | 11 29 1.951698E-01
362 | 11 30 4.582348E-02
363 | 11 31 1.554967E-03
364 | 11 32 2.053444E-02
365 | 11 33 2.341303E-02
366 | 11 34 8.573370E-04
367 | 11 35 8.373720E-05
368 | 11 36 5.433328E-03
369 | 11 39 8.720232E-03
370 | 11 40 2.348604E-03
371 | 11 42 1.868273E-02
372 | 11 43 6.617656E-02
373 | 11 45 1.878756E-03
374 | 11 49 1.677283E-03
375 | 11 51 5.023257E-03
376 | 11 52 1.168560E-06
377 | 11 56 8.847170E-06
378 | 11 57 5.518680E-09
379 | 11 58 2.286330E-05
380 | 11 59 4.343640E-07
381 | 11 61 2.547230E-07
382 | 11 63 7.873050E-05
383 | 11 64 6.164412E-01
384 | 11 66 7.455270E-01
385 | 12 14 4.247549E-04
386 | 12 15 1.710000E-04
387 | 12 16 2.772209E-04
388 | 12 18 1.162941E-03
389 | 12 20 3.788501E-03
390 | 12 21 3.003461E-03
391 | 12 22 3.321112E-03
392 | 12 23 2.402446E-03
393 | 12 25 3.055199E-04
394 | 12 26 8.949658E-05
395 | 12 27 2.271701E-03
396 | 12 28 3.511422E-03
397 | 12 29 4.089071E-03
398 | 12 30 2.243330E-03
399 | 12 31 1.082390E-04
400 | 12 32 7.726068E-04
401 | 12 33 1.265501E-03
402 | 12 34 5.077519E-05
403 | 12 35 7.788658E-06
404 | 12 36 8.714795E-03
405 | 12 39 4.668619E-04
406 | 12 40 1.257390E-04
407 | 12 42 1.000232E-03
408 | 12 43 3.542946E-03
409 | 12 45 1.005840E-04
410 | 12 49 8.979798E-05
411 | 12 51 2.689339E-04
412 | 12 52 6.256219E-08
413 | 12 56 4.736579E-07
414 | 12 57 2.954579E-10
415 | 12 58 1.224050E-06
416 | 12 61 1.363730E-08
417 | 12 63 4.215049E-06
418 | 12 64 3.329190E-02
419 | 12 66 4.026339E-02
420 | 13 14 1.455997E-02
421 | 13 18 2.944029E-03
422 | 13 23 1.180051E-02
423 | 13 27 8.897110E-03
424 | 13 28 2.131903E-02
425 | 13 30 1.963018E-02
426 | 13 31 5.623562E-04
427 | 13 32 9.548524E-03
428 | 13 36 1.454472E-02
429 | 13 38 1.434731E-03
430 | 13 39 2.111672E-03
431 | 13 40 5.687322E-04
432 | 13 42 4.524168E-03
433 | 13 43 1.602517E-02
434 | 13 44 6.598037E-02
435 | 13 45 4.549552E-04
436 | 13 47 6.417921E-03
437 | 13 49 4.061671E-04
438 | 13 50 2.423397E-03
439 | 13 52 2.829761E-07
440 | 13 57 1.336390E-09
441 | 13 58 5.536511E-06
442 | 13 60 4.901101E-04
443 | 13 61 6.168302E-08
444 | 13 62 2.951371E-06
445 | 13 63 1.906521E-05
446 | 13 64 1.093305E-01
447 | 13 66 2.225055E-01
448 | 14 18 1.899764E-04
449 | 14 32 2.178825E-04
450 | 14 39 8.343531E-05
451 | 14 40 2.247152E-05
452 | 14 44 7.188658E-03
453 | 14 45 1.797598E-05
454 | 14 47 2.535812E-04
455 | 14 49 1.604825E-05
456 | 14 50 9.575198E-05
457 | 14 52 1.118081E-08
458 | 14 57 5.280288E-11
459 | 14 58 2.187564E-07
460 | 14 61 2.437186E-09
461 | 14 62 1.166130E-07
462 | 14 63 7.532939E-07
463 | 14 64 4.369796E-03
464 | 14 66 8.893244E-03
465 | 15 45 4.950356E-06
466 | 15 51 1.323583E-05
467 | 15 52 3.079063E-09
468 | 15 64 6.254070E-04
469 | 15 66 1.473979E-03
470 | 16 14 9.846166E-05
471 | 16 15 5.312208E-06
472 | 16 18 4.380337E-05
473 | 16 27 1.382272E-04
474 | 16 32 9.904576E-05
475 | 16 33 6.277970E-05
476 | 16 34 1.142322E-05
477 | 16 38 4.388277E-05
478 | 16 45 1.391532E-05
479 | 16 51 3.720546E-05
480 | 16 52 8.655133E-09
481 | 16 56 6.552790E-08
482 | 16 57 4.087497E-11
483 | 16 58 1.693403E-07
484 | 16 61 1.886643E-09
485 | 16 63 2.481614E-07
486 | 16 64 3.139997E-03
487 | 16 66 7.400443E-03
488 | 17 45 9.147472E-05
489 | 17 51 2.445771E-04
490 | 17 52 5.689611E-08
491 | 17 64 1.140291E-02
492 | 17 66 2.687472E-02
493 | 18 45 5.145244E-05
494 | 18 51 1.375695E-04
495 | 18 52 3.200275E-08
496 | 18 64 6.418352E-03
497 | 18 66 1.512698E-02
498 | 19 14 2.831185E-03
499 | 19 15 1.953037E-03
500 | 19 18 1.069531E-03
501 | 19 27 4.406278E-03
502 | 19 32 9.610534E-03
503 | 19 33 2.879345E-03
504 | 19 34 3.552480E-04
505 | 19 38 2.632144E-03
506 | 19 42 4.343551E-03
507 | 19 43 2.939961E-02
508 | 19 51 2.231633E-03
509 | 19 52 5.191460E-07
510 | 19 56 3.930440E-06
511 | 19 57 2.451730E-09
512 | 19 58 1.015720E-05
513 | 19 61 1.131630E-07
514 | 19 63 1.488510E-05
515 | 19 64 1.861212E-01
516 | 19 66 4.386562E-01
517 | 20 14 1.998975E-03
518 | 20 15 4.361079E-05
519 | 20 18 1.558930E-04
520 | 20 27 6.111659E-04
521 | 20 32 1.184019E-03
522 | 20 33 3.791010E-04
523 | 20 34 4.947949E-05
524 | 20 38 3.477590E-04
525 | 20 45 1.102750E-04
526 | 20 51 2.948430E-04
527 | 20 52 6.858949E-08
528 | 20 56 5.192899E-07
529 | 20 57 3.239230E-10
530 | 20 58 1.341970E-06
531 | 20 61 1.495110E-08
532 | 20 63 1.966610E-06
533 | 20 64 2.476488E-02
534 | 20 66 5.836663E-02
535 | 21 14 3.403615E-03
536 | 21 15 1.279230E-03
537 | 21 18 4.188689E-03
538 | 21 27 1.513868E-02
539 | 21 32 2.286712E-02
540 | 21 33 8.511196E-03
541 | 21 34 1.234517E-03
542 | 21 38 5.578017E-03
543 | 21 42 9.204819E-03
544 | 21 43 6.230341E-02
545 | 21 51 4.729258E-03
546 | 21 52 1.100170E-06
547 | 21 56 8.329369E-06
548 | 21 57 5.195690E-09
549 | 21 58 2.152510E-05
550 | 21 61 2.398140E-07
551 | 21 63 3.154430E-05
552 | 21 64 3.924299E-01
553 | 21 66 9.248911E-01
554 | 22 14 5.891450E-04
555 | 22 15 1.109710E-04
556 | 22 18 1.831790E-04
557 | 22 27 1.006382E-03
558 | 22 32 3.401557E-03
559 | 22 33 8.218110E-04
560 | 22 34 7.947510E-05
561 | 22 38 7.109330E-04
562 | 22 42 1.173179E-03
563 | 22 43 7.940737E-03
564 | 22 51 6.027570E-04
565 | 22 52 1.402200E-07
566 | 22 56 1.061600E-06
567 | 22 57 6.622050E-10
568 | 22 58 2.743440E-06
569 | 22 61 3.056500E-08
570 | 22 63 4.020410E-06
571 | 22 64 5.052587E-02
572 | 22 66 1.190809E-01
573 | 23 14 3.265270E-03
574 | 23 15 8.791068E-04
575 | 23 18 2.632350E-04
576 | 23 27 9.788099E-04
577 | 23 32 1.628374E-03
578 | 23 33 5.706959E-04
579 | 23 34 7.961279E-05
580 | 23 38 7.720508E-04
581 | 23 42 1.274036E-03
582 | 23 43 8.623391E-03
583 | 23 51 6.545749E-04
584 | 23 52 1.522740E-07
585 | 23 56 1.152860E-06
586 | 23 57 7.191328E-10
587 | 23 58 2.979289E-06
588 | 23 61 3.319259E-08
589 | 23 63 4.366039E-06
590 | 23 64 5.478512E-02
591 | 23 66 1.291193E-01
592 | 24 14 1.045033E-03
593 | 24 15 2.801299E-04
594 | 24 18 4.511639E-04
595 | 24 27 1.498320E-03
596 | 24 32 1.540540E-03
597 | 24 33 7.440408E-04
598 | 24 34 1.231800E-04
599 | 24 38 9.587707E-04
600 | 24 42 1.582158E-03
601 | 24 43 1.070894E-02
602 | 24 51 8.128828E-04
603 | 24 52 1.891009E-07
604 | 24 56 1.431680E-06
605 | 24 57 8.930537E-10
606 | 24 58 3.699819E-06
607 | 24 61 4.122019E-08
608 | 24 63 5.421949E-06
609 | 24 64 6.783224E-02
610 | 24 66 1.598691E-01
611 | 25 15 2.040504E-06
612 | 25 32 6.530400E-05
613 | 25 38 3.188961E-05
614 | 25 42 5.262404E-05
615 | 25 43 3.561889E-04
616 | 25 45 1.011227E-05
617 | 25 51 2.703722E-05
618 | 25 52 6.289681E-09
619 | 25 56 4.761906E-08
620 | 25 57 2.970381E-11
621 | 25 58 1.230596E-07
622 | 25 61 1.371016E-09
623 | 25 63 1.803395E-07
624 | 25 64 1.269194E-03
625 | 25 66 2.991276E-03
626 | 26 15 1.279308E-06
627 | 26 32 4.451252E-05
628 | 26 45 3.741993E-06
629 | 26 51 1.000498E-05
630 | 26 52 2.327466E-09
631 | 26 64 4.729461E-04
632 | 26 66 1.114655E-03
633 | 27 15 7.389849E-04
634 | 27 45 1.390952E-04
635 | 27 51 3.719019E-04
636 | 27 52 8.651565E-08
637 | 27 64 1.729499E-02
638 | 27 66 4.076139E-02
639 | 28 15 1.508510E-04
640 | 28 45 1.675870E-04
641 | 28 51 4.480800E-04
642 | 28 52 1.042370E-07
643 | 28 64 2.084287E-02
644 | 28 66 4.912312E-02
645 | 29 15 1.683250E-04
646 | 29 45 2.738541E-04
647 | 29 51 7.322091E-04
648 | 29 52 1.703340E-07
649 | 29 64 3.391568E-02
650 | 29 66 7.993354E-02
651 | 30 15 2.552189E-04
652 | 30 45 1.260350E-04
653 | 30 51 3.369809E-04
654 | 30 52 7.839207E-08
655 | 30 64 1.571476E-02
656 | 30 66 3.703706E-02
657 | 31 15 5.213063E-06
658 | 31 45 6.230434E-06
659 | 31 51 1.665844E-05
660 | 31 52 3.875249E-09
661 | 31 64 7.860329E-04
662 | 31 66 1.852545E-03
663 | 32 45 1.183901E-04
664 | 32 51 3.165413E-04
665 | 32 52 7.363710E-08
666 | 32 64 1.475969E-02
667 | 32 66 3.478609E-02
668 | 33 15 6.727418E-05
669 | 33 45 9.011117E-05
670 | 33 51 2.409319E-04
671 | 33 52 5.604798E-08
672 | 33 64 1.123832E-02
673 | 33 66 2.648682E-02
674 | 34 45 4.932024E-06
675 | 34 51 1.318683E-05
676 | 34 52 3.067654E-09
677 | 34 64 6.220587E-04
678 | 34 66 1.466086E-03
679 | 35 15 3.152162E-07
680 | 35 27 6.591889E-06
681 | 35 32 7.017775E-06
682 | 35 33 3.306095E-06
683 | 35 34 5.416009E-07
684 | 35 38 3.013429E-06
685 | 35 42 2.566682E-05
686 | 35 43 3.365845E-05
687 | 35 51 2.554902E-06
688 | 35 52 5.943488E-10
689 | 35 56 4.499804E-09
690 | 35 57 2.806886E-12
691 | 35 58 1.162859E-08
692 | 35 61 1.295561E-10
693 | 35 63 1.704128E-08
694 | 35 64 1.212360E-04
695 | 35 66 2.857317E-04
696 | 36 36 8.436752E-03
697 | 36 42 1.765603E-03
698 | 36 43 2.457941E-03
699 | 36 45 6.978110E-05
700 | 36 56 3.286031E-07
701 | 36 57 2.049760E-10
702 | 36 58 8.491911E-07
703 | 36 61 9.460951E-09
704 | 36 63 1.107560E-06
705 | 36 64 2.010331E-03
706 | 36 66 4.026700E-03
707 | 37 56 2.817372E-09
708 | 37 57 1.757423E-12
709 | 37 58 7.280798E-09
710 | 37 61 8.111630E-11
711 | 37 64 1.901201E-05
712 | 37 66 3.808113E-05
713 | 38 43 8.279357E-04
714 | 38 45 2.350512E-05
715 | 38 49 2.098452E-05
716 | 38 61 3.186833E-09
717 | 38 64 2.553416E-03
718 | 38 66 5.114501E-03
719 | 39 18 2.936277E-05
720 | 39 39 4.398042E-03
721 | 39 42 1.765601E-03
722 | 39 43 1.101930E-03
723 | 39 45 3.128387E-05
724 | 39 49 2.792907E-05
725 | 39 51 2.526947E-04
726 | 39 61 4.241476E-09
727 | 39 64 3.398437E-03
728 | 39 66 6.807079E-03
729 | 40 18 1.228418E-04
730 | 40 38 1.019977E-03
731 | 40 42 1.395803E-03
732 | 40 45 7.477736E-06
733 | 40 49 6.675837E-06
734 | 40 51 6.040118E-05
735 | 40 56 3.521303E-08
736 | 40 57 2.196516E-11
737 | 40 58 9.099922E-08
738 | 40 61 1.013838E-09
739 | 40 63 1.186858E-07
740 | 40 64 8.123235E-04
741 | 40 66 1.627086E-03
742 | 41 36 2.999957E-04
743 | 41 42 3.697917E-04
744 | 41 64 4.731132E-05
745 | 41 66 9.476474E-05
746 | 42 43 2.836137E-03
747 | 42 50 1.316530E-06
748 | 42 52 5.008120E-08
749 | 42 59 1.861560E-08
750 | 42 64 1.175892E-02
751 | 42 66 2.355315E-02
752 | 43 42 1.765602E-03
753 | 43 43 1.406807E-02
754 | 43 45 3.993929E-04
755 | 43 50 6.530388E-06
756 | 43 52 2.484169E-07
757 | 43 63 6.339108E-06
758 | 43 64 8.157950E-02
759 | 43 66 1.634039E-01
760 | 44 43 1.222333E-01
761 | 44 45 3.470213E-03
762 | 44 50 5.674068E-05
763 | 44 52 2.158429E-06
764 | 44 61 4.704928E-07
765 | 44 63 5.507877E-05
766 | 44 64 2.384017E-01
767 | 44 66 4.775193E-01
768 | 45 42 3.531193E-03
769 | 45 45 1.545644E-05
770 | 45 52 9.613732E-09
771 | 45 55 8.195218E-06
772 | 45 64 8.517546E-04
773 | 45 66 1.706067E-03
774 | 46 43 2.857785E-03
775 | 46 45 8.113270E-05
776 | 46 52 5.046350E-08
777 | 46 54 2.316260E-04
778 | 46 55 4.301760E-05
779 | 46 64 1.823611E-01
780 | 46 66 3.652699E-01
781 | 47 43 4.179703E-05
782 | 47 52 7.380614E-10
783 | 47 54 3.387692E-06
784 | 47 55 6.291604E-07
785 | 47 57 3.485592E-12
786 | 47 59 2.743432E-10
787 | 47 61 1.608821E-10
788 | 47 64 3.199758E-03
789 | 47 66 6.409126E-03
790 | 48 45 5.974973E-07
791 | 48 52 3.716352E-10
792 | 48 54 1.705801E-06
793 | 48 55 3.168012E-07
794 | 48 64 1.697796E-03
795 | 48 66 3.400690E-03
796 | 49 55 2.492886E-07
797 | 49 64 1.568632E-03
798 | 49 66 3.141975E-03
799 | 50 64 4.818499E-02
800 | 50 66 9.651498E-02
801 | 51 64 2.085217E-03
802 | 51 66 4.176694E-03
803 | 52 54 1.812674E-09
804 | 52 64 6.752179E-07
805 | 52 66 1.352461E-06
806 | 53 45 2.900211E-06
807 | 53 54 8.279841E-06
808 | 53 55 1.537730E-06
809 | 53 64 1.050529E-02
810 | 53 66 2.104212E-02
811 | 54 64 5.214584E-06
812 | 54 66 1.044483E-05
813 | 55 64 3.596053E-06
814 | 55 66 7.202905E-06
815 | 56 45 1.385892E-08
816 | 56 49 1.237268E-08
817 | 56 50 2.266037E-10
818 | 56 52 3.838649E-09
819 | 56 63 2.199664E-10
820 | 56 64 8.304672E-06
821 | 56 66 1.663432E-05
822 | 57 45 4.516399E-12
823 | 57 49 4.032069E-12
824 | 57 50 7.384658E-14
825 | 57 52 1.250960E-12
826 | 57 63 7.168358E-14
827 | 57 64 2.706360E-09
828 | 57 66 5.420849E-09
829 | 58 45 1.169343E-07
830 | 58 49 1.043940E-07
831 | 58 50 1.911965E-09
832 | 58 52 3.238852E-08
833 | 58 63 1.855963E-09
834 | 58 64 5.605620E-05
835 | 58 66 1.122812E-04
836 | 59 49 5.641780E-10
837 | 59 50 1.033286E-11
838 | 59 52 1.750367E-10
839 | 59 63 1.003016E-11
840 | 59 64 3.786811E-07
841 | 59 66 7.584993E-07
842 | 60 49 6.078228E-08
843 | 60 50 1.113218E-09
844 | 60 52 1.885780E-08
845 | 60 63 1.080611E-09
846 | 60 64 4.079760E-05
847 | 60 66 8.171768E-05
848 | 61 49 6.447645E-08
849 | 61 50 1.180872E-09
850 | 61 52 2.000386E-08
851 | 61 63 1.146282E-09
852 | 61 64 4.327709E-05
853 | 61 66 8.668419E-05
854 | 62 47 9.511896E-08
855 | 62 49 6.019731E-09
856 | 62 50 1.102503E-10
857 | 62 52 1.867629E-09
858 | 62 63 1.070215E-10
859 | 62 64 4.040497E-06
860 | 62 66 8.093130E-06
861 | 63 47 1.227864E-06
862 | 63 49 7.770686E-08
863 | 63 50 1.423190E-09
864 | 63 52 2.410867E-08
865 | 63 54 2.484939E-07
866 | 63 63 1.381498E-09
867 | 63 64 5.215745E-05
868 | 63 66 1.044719E-04
869 | 64 1 3.874999E+02
870 | 64 9 2.408614E-02
871 | 64 10 2.838310E-01
872 | 64 11 1.218530E-01
873 | 64 13 1.761220E-02
874 | 64 19 5.222166E-02
875 | 64 21 6.179828E-02
876 | 64 22 6.647838E-03
877 | 64 23 4.103967E-03
878 | 64 24 2.704814E-02
879 | 64 35 4.836089E-05
880 | 65 2 1.861676E+01
881 | 65 7 1.030550E-02
882 | 65 8 9.358735E-02
883 | 65 9 2.803458E-02
884 | 65 10 4.572957E-01
885 | 65 11 2.115177E-01
886 | 65 12 1.225960E-02
887 | 65 13 1.158298E-01
888 | 65 16 3.217709E-03
889 | 65 17 5.065018E-02
890 | 65 18 3.487920E-03
891 | 65 19 5.206728E-01
892 | 65 21 5.088312E-01
893 | 65 22 9.553630E-02
894 | 65 23 3.535136E-02
895 | 65 24 1.929484E-01
896 | 65 31 7.228513E-04
897 | 65 35 3.487821E-04
898 | 65 41 2.900141E-05
899 | 65 64 1.300471E+03
900 | 66 2 8.760818E+00
901 | 66 9 5.596149E-03
902 | 66 10 6.880692E-02
903 | 66 11 2.172915E-02
904 | 66 13 7.806649E-03
905 | 66 16 1.284579E-04
906 | 66 17 2.023433E-02
907 | 66 18 1.392809E-04
908 | 66 19 2.080774E-01
909 | 66 21 2.032673E-02
910 | 66 22 3.820157E-03
911 | 66 23 1.412330E-03
912 | 66 24 7.704998E-03
913 | 66 31 2.887869E-05
914 | 66 35 1.392829E-05
915 | 66 41 1.160059E-04
916 | 66 50 2.054219E-01
917 | 66 64 2.113068E+03
918 |
--------------------------------------------------------------------------------
/datasets/email-Enron/README.md:
--------------------------------------------------------------------------------
1 | Enron network
2 | =============
3 |
4 | This directory contains the edges file of the Enron email network.
5 | The network consists of 1,148,072 emails sent between employees of Enron between 1999 and 2003. Nodes in the network are individual employees and edges are individual emails. Edges are directed and weighted. The direction is from the sender to the receiver and the weight represents the number of messages. It is possible to send an email to oneself, and thus this network contains loops.
6 |
7 | The edges file contains three columns: senderID, receiverID, and weight.
8 |
9 | Sources:
10 |
11 | * http://konect.cc/networks/enron/
12 | * http://www.cs.cmu.edu/~enron/
13 | * Jérôme Kunegis. KONECT – The Koblenz Network Collection. In Proc. Int. Conf. on World Wide Web Companion, pages 1343–1350, 2013. doi:10.1145/2487788.2488173
14 | * B. Klimmt, Y. Yang. Introducing the Enron corpus. In Proc. Eur. Conf. on Mach. Learn., pages 217–226, 2004.
15 |
--------------------------------------------------------------------------------
/datasets/email-Enron/email-Enron.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/email-Enron/email-Enron.edges.gz
--------------------------------------------------------------------------------
/datasets/enwiki_math/Check subcategories.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "collapsed": true
8 | },
9 | "outputs": [],
10 | "source": [
11 | "import gzip\n",
12 | "import re\n",
13 | "\n",
14 | "from sqlalchemy import create_engine"
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": 2,
20 | "metadata": {
21 | "collapsed": true
22 | },
23 | "outputs": [],
24 | "source": [
25 | "engine = create_engine('mysql+mysqlconnector://claydavi:@/enwiki')"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 3,
31 | "metadata": {},
32 | "outputs": [
33 | {
34 | "data": {
35 | "text/plain": [
36 | "11989"
37 | ]
38 | },
39 | "execution_count": 3,
40 | "metadata": {},
41 | "output_type": "execute_result"
42 | }
43 | ],
44 | "source": [
45 | "result = engine.execute(\n",
46 | " '''select distinct(cl_from)\n",
47 | " from math_subcategories \n",
48 | " join categorylinks \n",
49 | " on categorylinks.cl_to = math_subcategories.cl_to\n",
50 | " join page\n",
51 | " on cl_from = page_id\n",
52 | " where page_namespace = 0''')\n",
53 | "page_ids = {x[0] for x in result}\n",
54 | "len(page_ids)"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": 6,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "result = engine.execute('select page_id from math_page_ids')\n",
64 | "math_page_ids = {x[0] for x in result}"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 11,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "data": {
74 | "text/plain": [
75 | "0"
76 | ]
77 | },
78 | "execution_count": 11,
79 | "metadata": {},
80 | "output_type": "execute_result"
81 | }
82 | ],
83 | "source": [
84 | "len(page_ids - math_page_ids)"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {
91 | "collapsed": true
92 | },
93 | "outputs": [],
94 | "source": []
95 | }
96 | ],
97 | "metadata": {
98 | "kernelspec": {
99 | "display_name": "Python [Root]",
100 | "language": "python",
101 | "name": "Python [Root]"
102 | },
103 | "language_info": {
104 | "codemirror_mode": {
105 | "name": "ipython",
106 | "version": 3
107 | },
108 | "file_extension": ".py",
109 | "mimetype": "text/x-python",
110 | "name": "python",
111 | "nbconvert_exporter": "python",
112 | "pygments_lexer": "ipython3",
113 | "version": "3.5.4"
114 | }
115 | },
116 | "nbformat": 4,
117 | "nbformat_minor": 2
118 | }
119 |
--------------------------------------------------------------------------------
/datasets/enwiki_math/README.md:
--------------------------------------------------------------------------------
1 | Source files come from https://dumps.wikimedia.org/simplewiki/20180220/
2 |
--------------------------------------------------------------------------------
/datasets/enwiki_math/enwiki_math.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/enwiki_math/enwiki_math.edges.gz
--------------------------------------------------------------------------------
/datasets/enwiki_math/enwiki_math.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/enwiki_math/enwiki_math.graphml.gz
--------------------------------------------------------------------------------
/datasets/friends.adjlist:
--------------------------------------------------------------------------------
1 | George Frank Dennis
2 | Dennis Claire Esther
3 | Claire Frank Alice Esther
4 | Bob Alice
5 | Frank Alice
6 | Alice
7 | Esther
8 | Shelly
9 |
--------------------------------------------------------------------------------
/datasets/ia-enron-only/ia-enron-only.edges:
--------------------------------------------------------------------------------
1 | # Unweighted, undirected
2 | 17 1
3 | 72 1
4 | 3 2
5 | 19 2
6 | 20 2
7 | 27 2
8 | 29 2
9 | 31 2
10 | 48 2
11 | 65 2
12 | 67 2
13 | 69 2
14 | 71 2
15 | 132 2
16 | 136 2
17 | 4 3
18 | 19 3
19 | 20 3
20 | 28 3
21 | 31 3
22 | 65 3
23 | 67 3
24 | 69 3
25 | 71 3
26 | 132 3
27 | 136 3
28 | 19 4
29 | 20 4
30 | 27 4
31 | 29 4
32 | 31 4
33 | 54 4
34 | 69 4
35 | 71 4
36 | 132 4
37 | 136 4
38 | 22 5
39 | 72 5
40 | 9 6
41 | 13 6
42 | 16 6
43 | 26 6
44 | 47 6
45 | 49 6
46 | 64 6
47 | 66 6
48 | 105 6
49 | 11 7
50 | 12 7
51 | 24 7
52 | 74 7
53 | 75 7
54 | 112 8
55 | 124 8
56 | 13 9
57 | 47 9
58 | 49 9
59 | 51 9
60 | 56 9
61 | 66 9
62 | 74 9
63 | 75 9
64 | 78 9
65 | 91 9
66 | 139 9
67 | 17 10
68 | 21 10
69 | 37 10
70 | 53 10
71 | 70 10
72 | 72 10
73 | 122 10
74 | 124 10
75 | 12 11
76 | 17 11
77 | 32 11
78 | 37 11
79 | 74 11
80 | 124 11
81 | 137 11
82 | 32 12
83 | 37 12
84 | 74 12
85 | 75 12
86 | 26 13
87 | 32 13
88 | 47 13
89 | 49 13
90 | 56 13
91 | 66 13
92 | 75 13
93 | 105 13
94 | 139 13
95 | 16 14
96 | 22 14
97 | 26 14
98 | 50 14
99 | 64 14
100 | 68 14
101 | 72 14
102 | 73 14
103 | 132 14
104 | 85 15
105 | 26 16
106 | 47 16
107 | 50 16
108 | 64 16
109 | 73 16
110 | 105 16
111 | 107 16
112 | 122 16
113 | 21 17
114 | 24 17
115 | 25 17
116 | 32 17
117 | 36 17
118 | 37 17
119 | 39 17
120 | 40 17
121 | 41 17
122 | 43 17
123 | 48 17
124 | 55 17
125 | 58 17
126 | 60 17
127 | 61 17
128 | 70 17
129 | 76 17
130 | 82 17
131 | 95 17
132 | 101 17
133 | 104 17
134 | 105 17
135 | 115 17
136 | 121 17
137 | 122 17
138 | 124 17
139 | 128 17
140 | 19 18
141 | 20 18
142 | 27 18
143 | 29 18
144 | 31 18
145 | 48 18
146 | 65 18
147 | 67 18
148 | 69 18
149 | 132 18
150 | 20 19
151 | 27 19
152 | 28 19
153 | 29 19
154 | 31 19
155 | 48 19
156 | 54 19
157 | 67 19
158 | 69 19
159 | 71 19
160 | 132 19
161 | 136 19
162 | 27 20
163 | 28 20
164 | 29 20
165 | 31 20
166 | 54 20
167 | 65 20
168 | 67 20
169 | 69 20
170 | 71 20
171 | 107 20
172 | 132 20
173 | 136 20
174 | 70 21
175 | 83 21
176 | 105 21
177 | 124 21
178 | 31 22
179 | 38 22
180 | 48 22
181 | 50 22
182 | 64 22
183 | 68 22
184 | 72 22
185 | 91 22
186 | 105 22
187 | 111 22
188 | 126 22
189 | 140 22
190 | 33 23
191 | 87 23
192 | 91 23
193 | 111 23
194 | 120 23
195 | 25 24
196 | 39 24
197 | 58 24
198 | 60 24
199 | 122 24
200 | 124 24
201 | 55 25
202 | 60 25
203 | 47 26
204 | 51 26
205 | 64 26
206 | 74 26
207 | 91 26
208 | 105 26
209 | 139 26
210 | 31 27
211 | 48 27
212 | 69 27
213 | 71 27
214 | 136 27
215 | 31 28
216 | 65 28
217 | 67 28
218 | 69 28
219 | 123 28
220 | 132 28
221 | 136 28
222 | 54 29
223 | 67 29
224 | 69 29
225 | 71 29
226 | 132 29
227 | 136 29
228 | 38 30
229 | 44 30
230 | 65 30
231 | 123 30
232 | 48 31
233 | 50 31
234 | 65 31
235 | 67 31
236 | 69 31
237 | 72 31
238 | 132 31
239 | 134 31
240 | 136 31
241 | 37 32
242 | 40 32
243 | 43 32
244 | 49 32
245 | 55 32
246 | 56 32
247 | 66 32
248 | 74 32
249 | 75 32
250 | 103 32
251 | 124 32
252 | 137 32
253 | 141 32
254 | 34 33
255 | 120 33
256 | 81 34
257 | 120 34
258 | 43 35
259 | 50 35
260 | 53 35
261 | 76 35
262 | 77 35
263 | 105 35
264 | 107 35
265 | 119 35
266 | 123 35
267 | 125 35
268 | 37 36
269 | 39 36
270 | 58 36
271 | 60 36
272 | 89 36
273 | 40 37
274 | 56 37
275 | 72 37
276 | 74 37
277 | 100 37
278 | 105 37
279 | 115 37
280 | 137 37
281 | 91 38
282 | 40 39
283 | 41 39
284 | 48 39
285 | 58 39
286 | 60 39
287 | 70 39
288 | 60 40
289 | 59 41
290 | 60 41
291 | 104 41
292 | 115 41
293 | 121 41
294 | 122 41
295 | 81 42
296 | 52 43
297 | 53 43
298 | 61 43
299 | 77 43
300 | 90 43
301 | 91 43
302 | 95 43
303 | 99 43
304 | 100 43
305 | 101 43
306 | 103 43
307 | 105 43
308 | 109 43
309 | 117 43
310 | 122 43
311 | 142 43
312 | 77 44
313 | 78 44
314 | 105 44
315 | 68 45
316 | 105 45
317 | 118 45
318 | 119 45
319 | 95 46
320 | 100 46
321 | 108 46
322 | 49 47
323 | 51 47
324 | 56 47
325 | 66 47
326 | 67 47
327 | 77 47
328 | 90 47
329 | 105 47
330 | 131 47
331 | 137 47
332 | 139 47
333 | 58 48
334 | 60 48
335 | 69 48
336 | 72 48
337 | 74 48
338 | 90 48
339 | 91 48
340 | 99 48
341 | 101 48
342 | 121 48
343 | 132 48
344 | 136 48
345 | 51 49
346 | 56 49
347 | 66 49
348 | 75 49
349 | 139 49
350 | 53 50
351 | 64 50
352 | 65 50
353 | 68 50
354 | 72 50
355 | 105 50
356 | 107 50
357 | 118 50
358 | 123 50
359 | 142 50
360 | 143 50
361 | 66 51
362 | 75 51
363 | 94 51
364 | 112 51
365 | 130 51
366 | 132 51
367 | 139 51
368 | 105 52
369 | 57 53
370 | 63 53
371 | 64 53
372 | 77 53
373 | 105 53
374 | 118 53
375 | 119 53
376 | 123 53
377 | 125 53
378 | 142 53
379 | 69 54
380 | 71 54
381 | 136 54
382 | 60 55
383 | 66 56
384 | 74 56
385 | 75 56
386 | 90 56
387 | 95 56
388 | 105 56
389 | 122 56
390 | 137 56
391 | 74 57
392 | 95 57
393 | 102 57
394 | 105 57
395 | 117 57
396 | 121 57
397 | 60 58
398 | 70 58
399 | 104 58
400 | 115 58
401 | 75 59
402 | 137 59
403 | 104 60
404 | 115 60
405 | 121 60
406 | 124 60
407 | 95 61
408 | 101 61
409 | 105 61
410 | 121 61
411 | 95 62
412 | 112 62
413 | 73 64
414 | 74 64
415 | 105 64
416 | 132 64
417 | 142 64
418 | 143 64
419 | 67 65
420 | 73 65
421 | 118 65
422 | 123 65
423 | 125 65
424 | 132 65
425 | 136 65
426 | 95 66
427 | 131 66
428 | 139 66
429 | 69 67
430 | 71 67
431 | 118 67
432 | 125 67
433 | 132 67
434 | 136 67
435 | 72 68
436 | 91 68
437 | 105 68
438 | 123 68
439 | 125 68
440 | 134 68
441 | 143 68
442 | 71 69
443 | 72 69
444 | 136 69
445 | 79 70
446 | 124 70
447 | 136 71
448 | 105 72
449 | 132 72
450 | 134 72
451 | 135 72
452 | 136 72
453 | 143 72
454 | 123 73
455 | 125 73
456 | 132 73
457 | 143 73
458 | 75 74
459 | 94 74
460 | 105 74
461 | 108 74
462 | 114 74
463 | 132 74
464 | 137 74
465 | 95 75
466 | 97 75
467 | 131 75
468 | 137 75
469 | 139 75
470 | 89 76
471 | 100 76
472 | 105 76
473 | 115 76
474 | 82 77
475 | 99 77
476 | 100 77
477 | 101 77
478 | 105 77
479 | 109 77
480 | 142 77
481 | 91 78
482 | 105 78
483 | 111 78
484 | 118 78
485 | 124 78
486 | 90 79
487 | 102 79
488 | 121 79
489 | 112 80
490 | 91 82
491 | 95 82
492 | 115 82
493 | 116 82
494 | 120 82
495 | 90 83
496 | 104 83
497 | 105 83
498 | 122 83
499 | 86 84
500 | 127 84
501 | 130 84
502 | 141 84
503 | 86 85
504 | 113 85
505 | 126 85
506 | 129 85
507 | 130 85
508 | 133 85
509 | 134 85
510 | 141 85
511 | 113 86
512 | 129 86
513 | 130 86
514 | 141 86
515 | 111 87
516 | 116 87
517 | 95 88
518 | 112 88
519 | 99 90
520 | 101 90
521 | 109 90
522 | 105 91
523 | 107 91
524 | 111 91
525 | 116 91
526 | 120 91
527 | 122 91
528 | 128 91
529 | 142 91
530 | 141 92
531 | 100 93
532 | 109 93
533 | 102 94
534 | 112 94
535 | 121 94
536 | 100 95
537 | 101 95
538 | 102 95
539 | 105 95
540 | 108 95
541 | 109 95
542 | 112 95
543 | 117 95
544 | 118 95
545 | 122 95
546 | 124 95
547 | 142 95
548 | 126 96
549 | 128 96
550 | 105 97
551 | 130 98
552 | 101 99
553 | 104 99
554 | 109 99
555 | 110 99
556 | 124 99
557 | 109 100
558 | 115 100
559 | 117 100
560 | 124 100
561 | 103 101
562 | 105 101
563 | 109 101
564 | 118 101
565 | 105 102
566 | 114 102
567 | 117 102
568 | 121 102
569 | 122 102
570 | 109 103
571 | 117 103
572 | 110 104
573 | 121 104
574 | 124 104
575 | 107 105
576 | 111 105
577 | 117 105
578 | 118 105
579 | 119 105
580 | 122 105
581 | 123 105
582 | 125 105
583 | 139 105
584 | 142 105
585 | 111 106
586 | 115 106
587 | 116 106
588 | 120 106
589 | 118 107
590 | 119 107
591 | 125 107
592 | 112 108
593 | 122 110
594 | 124 110
595 | 138 110
596 | 124 112
597 | 121 114
598 | 120 115
599 | 119 118
600 | 123 118
601 | 125 118
602 | 142 118
603 | 143 118
604 | 123 119
605 | 143 119
606 | 137 121
607 | 142 122
608 | 125 123
609 | 143 123
610 | 138 124
611 | 129 126
612 | 130 126
613 | 130 127
614 | 141 127
615 | 130 129
616 | 134 129
617 | 141 129
618 | 141 130
619 | 137 131
620 | 136 132
621 | 141 133
622 | 135 134
623 | 140 134
624 | 143 142
625 |
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/all.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/all.edges.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/all.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/all.graphml.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/all.nodes.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/all.nodes.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/data_format_specification.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/data_format_specification.docx
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/mention.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/mention.edges.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/mention.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/mention.graphml.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/mention.nodes.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/mention.nodes.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/multidigraph to digraph.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "collapsed": true
8 | },
9 | "outputs": [],
10 | "source": [
11 | "from collections import Counter\n",
12 | "\n",
13 | "import networkx as nx"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 2,
19 | "metadata": {},
20 | "outputs": [
21 | {
22 | "data": {
23 | "text/plain": [
24 | "61157"
25 | ]
26 | },
27 | "execution_count": 2,
28 | "metadata": {},
29 | "output_type": "execute_result"
30 | }
31 | ],
32 | "source": [
33 | "MG = nx.read_graphml('retweet.graphml.gz')\n",
34 | "MG.number_of_edges()"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": 3,
40 | "metadata": {
41 | "collapsed": true
42 | },
43 | "outputs": [],
44 | "source": [
45 | "counts = Counter(MG.edges())"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": 4,
51 | "metadata": {
52 | "collapsed": true
53 | },
54 | "outputs": [],
55 | "source": [
56 | "D = nx.DiGraph()\n",
57 | "D.add_weighted_edges_from((u,v,w) for (u, v), w in counts.items())"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": 5,
63 | "metadata": {},
64 | "outputs": [
65 | {
66 | "data": {
67 | "text/plain": [
68 | "48365"
69 | ]
70 | },
71 | "execution_count": 5,
72 | "metadata": {},
73 | "output_type": "execute_result"
74 | }
75 | ],
76 | "source": [
77 | "len(D.edges)"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": 6,
83 | "metadata": {
84 | "collapsed": true
85 | },
86 | "outputs": [],
87 | "source": [
88 | "nx.write_edgelist(D, 'retweet-digraph.edges.gz', data=['weight'])"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {
95 | "collapsed": true
96 | },
97 | "outputs": [],
98 | "source": []
99 | }
100 | ],
101 | "metadata": {
102 | "kernelspec": {
103 | "display_name": "Python 3",
104 | "language": "python",
105 | "name": "python3"
106 | },
107 | "language_info": {
108 | "codemirror_mode": {
109 | "name": "ipython",
110 | "version": 3
111 | },
112 | "file_extension": ".py",
113 | "mimetype": "text/x-python",
114 | "name": "python",
115 | "nbconvert_exporter": "python",
116 | "pygments_lexer": "ipython3",
117 | "version": "3.6.3"
118 | }
119 | },
120 | "nbformat": 4,
121 | "nbformat_minor": 2
122 | }
123 |
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/retweet-digraph.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/retweet-digraph.edges.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/retweet.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/retweet.edges.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/retweet.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/retweet.graphml.gz
--------------------------------------------------------------------------------
/datasets/icwsm_polarization/retweet.nodes.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/icwsm_polarization/retweet.nodes.gz
--------------------------------------------------------------------------------
/datasets/imdb/actors_costar.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/imdb/actors_costar.edges.gz
--------------------------------------------------------------------------------
/datasets/imdb/actors_costar.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/imdb/actors_costar.graphml.gz
--------------------------------------------------------------------------------
/datasets/imdb/actors_movies.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/imdb/actors_movies.edges.gz
--------------------------------------------------------------------------------
/datasets/imdb/actors_movies.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/imdb/actors_movies.graphml.gz
--------------------------------------------------------------------------------
/datasets/karate_club.graphml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Zachary's Karate Club
5 |
6 | Mr. Hi
7 |
8 |
9 | Mr. Hi
10 |
11 |
12 | Mr. Hi
13 |
14 |
15 | Mr. Hi
16 |
17 |
18 | Mr. Hi
19 |
20 |
21 | Mr. Hi
22 |
23 |
24 | Mr. Hi
25 |
26 |
27 | Mr. Hi
28 |
29 |
30 | Mr. Hi
31 |
32 |
33 | Officer
34 |
35 |
36 | Mr. Hi
37 |
38 |
39 | Mr. Hi
40 |
41 |
42 | Mr. Hi
43 |
44 |
45 | Mr. Hi
46 |
47 |
48 | Officer
49 |
50 |
51 | Officer
52 |
53 |
54 | Mr. Hi
55 |
56 |
57 | Mr. Hi
58 |
59 |
60 | Officer
61 |
62 |
63 | Mr. Hi
64 |
65 |
66 | Officer
67 |
68 |
69 | Mr. Hi
70 |
71 |
72 | Officer
73 |
74 |
75 | Officer
76 |
77 |
78 | Officer
79 |
80 |
81 | Officer
82 |
83 |
84 | Officer
85 |
86 |
87 | Officer
88 |
89 |
90 | Officer
91 |
92 |
93 | Officer
94 |
95 |
96 | Officer
97 |
98 |
99 | Officer
100 |
101 |
102 | Officer
103 |
104 |
105 | Officer
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/datasets/openflights/README.md:
--------------------------------------------------------------------------------
1 | Generated from the Feb 2, 2017 data: [GitHub
2 | release](https://github.com/jpatokal/openflights/tree/5d623a6969a1adee7961cf1c9a8a212c4a784713)
3 |
--------------------------------------------------------------------------------
/datasets/openflights/openflights_usa.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/openflights/openflights_usa.edges.gz
--------------------------------------------------------------------------------
/datasets/openflights/openflights_usa.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/openflights/openflights_usa.graphml.gz
--------------------------------------------------------------------------------
/datasets/openflights/openflights_world.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/openflights/openflights_world.edges.gz
--------------------------------------------------------------------------------
/datasets/openflights/openflights_world.graphml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/openflights/openflights_world.graphml.gz
--------------------------------------------------------------------------------
/datasets/repealthe19th.jsonl.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/repealthe19th.jsonl.gz
--------------------------------------------------------------------------------
/datasets/socfb-Northwestern25/socfb-Northwestern25.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/socfb-Northwestern25/socfb-Northwestern25.edges.gz
--------------------------------------------------------------------------------
/datasets/summary_statistics.csv:
--------------------------------------------------------------------------------
1 | Name,Type,File,Average Degree,Average Path Length,Clustering,Density,Heterogeneity,Links,Maximum Degree,Nodes
2 | Facebook Northwestern University,,socfb-Northwestern25/socfb-Northwestern25.edges.gz,92.42680041639065,2.718519882319446,0.2379913948280604,0.008747567709293077,1.8358284067492063,488337,2105,10567
3 | IMDB movies and actors,,imdb/actors_movies.edges.gz,3.269753994636547,12.148361857366227,0.0,5.803177602373531e-06,5.406333873585608,921160,800,563443
4 | IMDB actors costar,W,imdb/actors_costar.edges.gz,8.02522539614781,6.849723287443824,0.6675597306381564,3.172050923781141e-05,4.5702613764594275,1015187,456,252999
5 | Twitter US politics,DW,icwsm_polarization/retweet-digraph.edges.gz,2.618570655116405,5.585332875772134,0.026152964008515068,0.0001417819402846069,8.298195705450587,48365,204,18470
6 | Enron Email,DW,email-Enron/email-Enron.edges.gz,3.688632223024303,3.613747271933654,0.1193422206466295,4.226592977156824e-05,17.436859485863646,321918,1338,87273
7 | Enron Executive Email,,ia-enron-only/ia-enron-only.edges,8.713286713286713,2.946256540662135,0.43390702914792223,0.061361174037230376,1.4829476797662633,623,42,143
8 | Wikipedia math,D,enwiki_math/enwiki_math.edges.gz,12.753153745072273,3.9197899887416643,0.30743990676840693,0.0008379758029484377,38.21020457626352,194103,5171,15220
9 | Internet routers,,tech-RL-caida/tech-RL-caida.edges.gz,6.365274416753093,7.009730994060153,0.15817334505180586,3.3341230910168995e-05,5.963275114019564,607610,1071,190914
10 | US air transportation,,openflights/openflights_usa.edges.gz,10.186813186813186,3.1914250604947663,0.4930453868822472,0.018691400342776488,5.347494770144302,2781,153,546
11 | World air transportation,,openflights/openflights_world.edges.gz,11.712488203837685,3.95024508560558,0.490541745679823,0.0036854903095776227,5.50907281111172,18617,246,3179
12 | Yeast protein interactions,,bio-yeast-protein-inter/bio-yeast-protein-inter.edges,2.4352941176470586,6.785238683127573,0.06716802014455514,0.0013029931073553016,2.687747035573123,2277,56,1870
13 | C. elegans brain,DW,celegansneural/celegansneural.edges,7.895622895622895,3.9776089354177975,0.2923632978321901,0.026674401674401674,2.7137110669618707,2345,134,297
14 | Everglades ecological food web,DW,eco-everglades/eco-everglades.edges,13.27536231884058,2.1730555555555555,0.5521052773829923,0.19522591645353793,2.2363060391678267,916,63,69
15 |
--------------------------------------------------------------------------------
/datasets/summary_statistics.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import itertools\n",
10 | "import multiprocessing\n",
11 | "import random\n",
12 | "\n",
13 | "import networkx as nx\n",
14 | "import numpy as np\n",
15 | "import pandas as pd"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 2,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "df = pd.DataFrame([\n",
25 | " ('Facebook Northwestern University', '', 'socfb-Northwestern25/socfb-Northwestern25.edges.gz'),\n",
26 | " ('IMDB movies and actors', '', 'imdb/actors_movies.edges.gz'),\n",
27 | " ('IMDB actors costar', 'W', 'imdb/actors_costar.edges.gz'),\n",
28 | " ('Twitter US politics', 'DW', 'icwsm_polarization/retweet-digraph.edges.gz'),\n",
29 | " ('Enron Email', 'DW', 'email-Enron/email-Enron.edges.gz'),\n",
30 | " ('Enron Executive Email', '', 'ia-enron-only/ia-enron-only.edges'),\n",
31 | " ('Wikipedia math', 'D', 'enwiki_math/enwiki_math.edges.gz'),\n",
32 | " ('Internet routers', '', 'tech-RL-caida/tech-RL-caida.edges.gz'),\n",
33 | " ('US air transportation', '', 'openflights/openflights_usa.edges.gz'),\n",
34 | " ('World air transportation', '', 'openflights/openflights_world.edges.gz'),\n",
35 | " ('Yeast protein interactions', '', 'bio-yeast-protein-inter/bio-yeast-protein-inter.edges'),\n",
36 | " ('C. elegans brain', 'DW', 'celegansneural/celegansneural.edges'),\n",
37 | " ('Everglades ecological food web', 'DW', 'eco-everglades/eco-everglades.edges'),\n",
38 | " ],\n",
39 | " columns=['Name', 'Type', 'File'],\n",
40 | ")"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 3,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "df = df.set_index('Name')"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": 4,
55 | "metadata": {},
56 | "outputs": [
57 | {
58 | "data": {
59 | "text/html": [
60 | "
\n",
61 | "\n",
74 | "
\n",
75 | " \n",
76 | " \n",
77 | " | \n",
78 | " Type | \n",
79 | " File | \n",
80 | "
\n",
81 | " \n",
82 | " Name | \n",
83 | " | \n",
84 | " | \n",
85 | "
\n",
86 | " \n",
87 | " \n",
88 | " \n",
89 | " Facebook Northwestern University | \n",
90 | " | \n",
91 | " socfb-Northwestern25/socfb-Northwestern25.edge... | \n",
92 | "
\n",
93 | " \n",
94 | " IMDB movies and actors | \n",
95 | " | \n",
96 | " imdb/actors_movies.edges.gz | \n",
97 | "
\n",
98 | " \n",
99 | " IMDB actors costar | \n",
100 | " W | \n",
101 | " imdb/actors_costar.edges.gz | \n",
102 | "
\n",
103 | " \n",
104 | " Twitter US politics | \n",
105 | " DW | \n",
106 | " icwsm_polarization/retweet-digraph.edges.gz | \n",
107 | "
\n",
108 | " \n",
109 | " Enron Email | \n",
110 | " DW | \n",
111 | " email-Enron/email-Enron.edges.gz | \n",
112 | "
\n",
113 | " \n",
114 | "
\n",
115 | "
"
116 | ],
117 | "text/plain": [
118 | " Type \\\n",
119 | "Name \n",
120 | "Facebook Northwestern University \n",
121 | "IMDB movies and actors \n",
122 | "IMDB actors costar W \n",
123 | "Twitter US politics DW \n",
124 | "Enron Email DW \n",
125 | "\n",
126 | " File \n",
127 | "Name \n",
128 | "Facebook Northwestern University socfb-Northwestern25/socfb-Northwestern25.edge... \n",
129 | "IMDB movies and actors imdb/actors_movies.edges.gz \n",
130 | "IMDB actors costar imdb/actors_costar.edges.gz \n",
131 | "Twitter US politics icwsm_polarization/retweet-digraph.edges.gz \n",
132 | "Enron Email email-Enron/email-Enron.edges.gz "
133 | ]
134 | },
135 | "execution_count": 4,
136 | "metadata": {},
137 | "output_type": "execute_result"
138 | }
139 | ],
140 | "source": [
141 | "df.head()"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": 7,
147 | "metadata": {},
148 | "outputs": [],
149 | "source": [
150 | "def single_source_average_path_length(G, node):\n",
151 | " return np.average(list(nx.single_source_shortest_path_length(G, node).values()))\n",
152 | "\n",
153 | "def estimated_average_path_length(G, N_sample=100):\n",
154 | " if G.is_directed():\n",
155 | " components = nx.strongly_connected_component_subgraphs(G)\n",
156 | " else:\n",
157 | " components = nx.connected_component_subgraphs(G)\n",
158 | " core = max(components, key=len)\n",
159 | " \n",
160 | " if core.number_of_nodes() <= N_sample:\n",
161 | " sampled_nodes = list(core.nodes)\n",
162 | " else:\n",
163 | " sampled_nodes = random.sample(list(core.nodes), N_sample)\n",
164 | " \n",
165 | " with multiprocessing.Pool() as pool:\n",
166 | " args = ((core, node) for node in sampled_nodes)\n",
167 | " node_apls = pool.starmap(single_source_average_path_length, args)\n",
168 | " \n",
169 | " return np.average(node_apls)"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": 8,
175 | "metadata": {},
176 | "outputs": [
177 | {
178 | "name": "stdout",
179 | "output_type": "stream",
180 | "text": [
181 | "Facebook Northwestern University\n",
182 | "IMDB movies and actors\n",
183 | "IMDB actors costar\n",
184 | "Twitter US politics\n",
185 | "Enron Email\n",
186 | "Enron Executive Email\n",
187 | "Wikipedia math\n",
188 | "Internet routers\n",
189 | "US air transportation\n",
190 | "World air transportation\n",
191 | "Yeast protein interactions\n",
192 | "C. elegans brain\n",
193 | "Everglades ecological food web\n"
194 | ]
195 | }
196 | ],
197 | "source": [
198 | "updates = []\n",
199 | "for idx, row in df.iterrows():\n",
200 | " fname = row['File']\n",
201 | " print(idx)\n",
202 | " if 'graphml' in fname:\n",
203 | " G = nx.read_graphml(fname)\n",
204 | " else:\n",
205 | " graph_class = nx.DiGraph() if 'D' in row['Type'] else nx.Graph()\n",
206 | " data_spec = [('weight', float)] if 'W' in row['Type'] else False\n",
207 | " G = nx.read_edgelist(fname, create_using=graph_class, data=data_spec)\n",
208 | " \n",
209 | " N = G.number_of_nodes()\n",
210 | " \n",
211 | " if G.is_multigraph():\n",
212 | " MG = G\n",
213 | " G = nx.DiGraph() if MG.is_directed() else nx.Graph()\n",
214 | " G.add_edges_from((u,v) for u,v,i in MG.edges)\n",
215 | " \n",
216 | " L = G.number_of_edges()\n",
217 | " \n",
218 | " degree_view = G.in_degree if G.is_directed() else G.degree\n",
219 | " degrees = np.array([d for n,d in degree_view])\n",
220 | " \n",
221 | " cc = nx.average_clustering(G.to_undirected())\n",
222 | " \n",
223 | " # This corresponds to the definition of heterogeneity given in the book.\n",
224 | " # Note that this definition may differ from that from other sources.\n",
225 | " heterogeneity = (degrees ** 2).mean() / degrees.mean() ** 2\n",
226 | " \n",
227 | " updates.append({\n",
228 | " 'Name': idx,\n",
229 | " 'Nodes': N,\n",
230 | " 'Links': L,\n",
231 | " 'Density': nx.density(G),\n",
232 | " 'Average Degree': degrees.mean(),\n",
233 | " 'Maximum Degree': degrees.max(),\n",
234 | " 'Heterogeneity': heterogeneity,\n",
235 | " 'Clustering': cc,\n",
236 | " 'Average Path Length': estimated_average_path_length(G, N_sample=1000),\n",
237 | " })\n",
238 | " "
239 | ]
240 | },
241 | {
242 | "cell_type": "code",
243 | "execution_count": 9,
244 | "metadata": {},
245 | "outputs": [],
246 | "source": [
247 | "new_df = pd.DataFrame.from_records(updates, index='Name')"
248 | ]
249 | },
250 | {
251 | "cell_type": "code",
252 | "execution_count": 10,
253 | "metadata": {},
254 | "outputs": [],
255 | "source": [
256 | "df = df.join(new_df)"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": 11,
262 | "metadata": {},
263 | "outputs": [
264 | {
265 | "data": {
266 | "text/html": [
267 | "\n",
268 | "\n",
281 | "
\n",
282 | " \n",
283 | " \n",
284 | " | \n",
285 | " Type | \n",
286 | " File | \n",
287 | " Average Degree | \n",
288 | " Average Path Length | \n",
289 | " Clustering | \n",
290 | " Density | \n",
291 | " Heterogeneity | \n",
292 | " Links | \n",
293 | " Maximum Degree | \n",
294 | " Nodes | \n",
295 | "
\n",
296 | " \n",
297 | " Name | \n",
298 | " | \n",
299 | " | \n",
300 | " | \n",
301 | " | \n",
302 | " | \n",
303 | " | \n",
304 | " | \n",
305 | " | \n",
306 | " | \n",
307 | " | \n",
308 | "
\n",
309 | " \n",
310 | " \n",
311 | " \n",
312 | " Facebook Northwestern University | \n",
313 | " | \n",
314 | " socfb-Northwestern25/socfb-Northwestern25.edge... | \n",
315 | " 92.426800 | \n",
316 | " 2.718520 | \n",
317 | " 0.237991 | \n",
318 | " 0.008748 | \n",
319 | " 1.835828 | \n",
320 | " 488337 | \n",
321 | " 2105 | \n",
322 | " 10567 | \n",
323 | "
\n",
324 | " \n",
325 | " IMDB movies and actors | \n",
326 | " | \n",
327 | " imdb/actors_movies.edges.gz | \n",
328 | " 3.269754 | \n",
329 | " 12.148362 | \n",
330 | " 0.000000 | \n",
331 | " 0.000006 | \n",
332 | " 5.406334 | \n",
333 | " 921160 | \n",
334 | " 800 | \n",
335 | " 563443 | \n",
336 | "
\n",
337 | " \n",
338 | " IMDB actors costar | \n",
339 | " W | \n",
340 | " imdb/actors_costar.edges.gz | \n",
341 | " 8.025225 | \n",
342 | " 6.849723 | \n",
343 | " 0.667560 | \n",
344 | " 0.000032 | \n",
345 | " 4.570261 | \n",
346 | " 1015187 | \n",
347 | " 456 | \n",
348 | " 252999 | \n",
349 | "
\n",
350 | " \n",
351 | " Twitter US politics | \n",
352 | " DW | \n",
353 | " icwsm_polarization/retweet-digraph.edges.gz | \n",
354 | " 2.618571 | \n",
355 | " 5.585333 | \n",
356 | " 0.026153 | \n",
357 | " 0.000142 | \n",
358 | " 8.298196 | \n",
359 | " 48365 | \n",
360 | " 204 | \n",
361 | " 18470 | \n",
362 | "
\n",
363 | " \n",
364 | " Enron Email | \n",
365 | " DW | \n",
366 | " email-Enron/email-Enron.edges.gz | \n",
367 | " 3.688632 | \n",
368 | " 3.613747 | \n",
369 | " 0.119342 | \n",
370 | " 0.000042 | \n",
371 | " 17.436859 | \n",
372 | " 321918 | \n",
373 | " 1338 | \n",
374 | " 87273 | \n",
375 | "
\n",
376 | " \n",
377 | "
\n",
378 | "
"
379 | ],
380 | "text/plain": [
381 | " Type \\\n",
382 | "Name \n",
383 | "Facebook Northwestern University \n",
384 | "IMDB movies and actors \n",
385 | "IMDB actors costar W \n",
386 | "Twitter US politics DW \n",
387 | "Enron Email DW \n",
388 | "\n",
389 | " File \\\n",
390 | "Name \n",
391 | "Facebook Northwestern University socfb-Northwestern25/socfb-Northwestern25.edge... \n",
392 | "IMDB movies and actors imdb/actors_movies.edges.gz \n",
393 | "IMDB actors costar imdb/actors_costar.edges.gz \n",
394 | "Twitter US politics icwsm_polarization/retweet-digraph.edges.gz \n",
395 | "Enron Email email-Enron/email-Enron.edges.gz \n",
396 | "\n",
397 | " Average Degree Average Path Length \\\n",
398 | "Name \n",
399 | "Facebook Northwestern University 92.426800 2.718520 \n",
400 | "IMDB movies and actors 3.269754 12.148362 \n",
401 | "IMDB actors costar 8.025225 6.849723 \n",
402 | "Twitter US politics 2.618571 5.585333 \n",
403 | "Enron Email 3.688632 3.613747 \n",
404 | "\n",
405 | " Clustering Density Heterogeneity \\\n",
406 | "Name \n",
407 | "Facebook Northwestern University 0.237991 0.008748 1.835828 \n",
408 | "IMDB movies and actors 0.000000 0.000006 5.406334 \n",
409 | "IMDB actors costar 0.667560 0.000032 4.570261 \n",
410 | "Twitter US politics 0.026153 0.000142 8.298196 \n",
411 | "Enron Email 0.119342 0.000042 17.436859 \n",
412 | "\n",
413 | " Links Maximum Degree Nodes \n",
414 | "Name \n",
415 | "Facebook Northwestern University 488337 2105 10567 \n",
416 | "IMDB movies and actors 921160 800 563443 \n",
417 | "IMDB actors costar 1015187 456 252999 \n",
418 | "Twitter US politics 48365 204 18470 \n",
419 | "Enron Email 321918 1338 87273 "
420 | ]
421 | },
422 | "execution_count": 11,
423 | "metadata": {},
424 | "output_type": "execute_result"
425 | }
426 | ],
427 | "source": [
428 | "df.head()"
429 | ]
430 | },
431 | {
432 | "cell_type": "markdown",
433 | "metadata": {},
434 | "source": [
435 | "## Chapter 1\n",
436 | "* Nodes\n",
437 | "* Links\n",
438 | "* Density\n",
439 | "* Average degree"
440 | ]
441 | },
442 | {
443 | "cell_type": "code",
444 | "execution_count": 12,
445 | "metadata": {},
446 | "outputs": [
447 | {
448 | "data": {
449 | "text/html": [
450 | "\n",
451 | "\n",
464 | "
\n",
465 | " \n",
466 | " \n",
467 | " | \n",
468 | " Nodes | \n",
469 | " Links | \n",
470 | " Density | \n",
471 | " Average Degree | \n",
472 | "
\n",
473 | " \n",
474 | " Name | \n",
475 | " | \n",
476 | " | \n",
477 | " | \n",
478 | " | \n",
479 | "
\n",
480 | " \n",
481 | " \n",
482 | " \n",
483 | " Facebook Northwestern University | \n",
484 | " 10567 | \n",
485 | " 488337 | \n",
486 | " 0.008748 | \n",
487 | " 92.426800 | \n",
488 | "
\n",
489 | " \n",
490 | " IMDB movies and actors | \n",
491 | " 563443 | \n",
492 | " 921160 | \n",
493 | " 0.000006 | \n",
494 | " 3.269754 | \n",
495 | "
\n",
496 | " \n",
497 | " IMDB actors costar | \n",
498 | " 252999 | \n",
499 | " 1015187 | \n",
500 | " 0.000032 | \n",
501 | " 8.025225 | \n",
502 | "
\n",
503 | " \n",
504 | " Twitter US politics | \n",
505 | " 18470 | \n",
506 | " 48365 | \n",
507 | " 0.000142 | \n",
508 | " 2.618571 | \n",
509 | "
\n",
510 | " \n",
511 | " Enron Email | \n",
512 | " 87273 | \n",
513 | " 321918 | \n",
514 | " 0.000042 | \n",
515 | " 3.688632 | \n",
516 | "
\n",
517 | " \n",
518 | " Enron Executive Email | \n",
519 | " 143 | \n",
520 | " 623 | \n",
521 | " 0.061361 | \n",
522 | " 8.713287 | \n",
523 | "
\n",
524 | " \n",
525 | " Wikipedia math | \n",
526 | " 15220 | \n",
527 | " 194103 | \n",
528 | " 0.000838 | \n",
529 | " 12.753154 | \n",
530 | "
\n",
531 | " \n",
532 | " Internet routers | \n",
533 | " 190914 | \n",
534 | " 607610 | \n",
535 | " 0.000033 | \n",
536 | " 6.365274 | \n",
537 | "
\n",
538 | " \n",
539 | " US air transportation | \n",
540 | " 546 | \n",
541 | " 2781 | \n",
542 | " 0.018691 | \n",
543 | " 10.186813 | \n",
544 | "
\n",
545 | " \n",
546 | " World air transportation | \n",
547 | " 3179 | \n",
548 | " 18617 | \n",
549 | " 0.003685 | \n",
550 | " 11.712488 | \n",
551 | "
\n",
552 | " \n",
553 | " Yeast protein interactions | \n",
554 | " 1870 | \n",
555 | " 2277 | \n",
556 | " 0.001303 | \n",
557 | " 2.435294 | \n",
558 | "
\n",
559 | " \n",
560 | " C. elegans brain | \n",
561 | " 297 | \n",
562 | " 2345 | \n",
563 | " 0.026674 | \n",
564 | " 7.895623 | \n",
565 | "
\n",
566 | " \n",
567 | " Everglades ecological food web | \n",
568 | " 69 | \n",
569 | " 916 | \n",
570 | " 0.195226 | \n",
571 | " 13.275362 | \n",
572 | "
\n",
573 | " \n",
574 | "
\n",
575 | "
"
576 | ],
577 | "text/plain": [
578 | " Nodes Links Density Average Degree\n",
579 | "Name \n",
580 | "Facebook Northwestern University 10567 488337 0.008748 92.426800\n",
581 | "IMDB movies and actors 563443 921160 0.000006 3.269754\n",
582 | "IMDB actors costar 252999 1015187 0.000032 8.025225\n",
583 | "Twitter US politics 18470 48365 0.000142 2.618571\n",
584 | "Enron Email 87273 321918 0.000042 3.688632\n",
585 | "Enron Executive Email 143 623 0.061361 8.713287\n",
586 | "Wikipedia math 15220 194103 0.000838 12.753154\n",
587 | "Internet routers 190914 607610 0.000033 6.365274\n",
588 | "US air transportation 546 2781 0.018691 10.186813\n",
589 | "World air transportation 3179 18617 0.003685 11.712488\n",
590 | "Yeast protein interactions 1870 2277 0.001303 2.435294\n",
591 | "C. elegans brain 297 2345 0.026674 7.895623\n",
592 | "Everglades ecological food web 69 916 0.195226 13.275362"
593 | ]
594 | },
595 | "execution_count": 12,
596 | "metadata": {},
597 | "output_type": "execute_result"
598 | }
599 | ],
600 | "source": [
601 | "ch1 = df[['Nodes', 'Links', 'Density', 'Average Degree']]\n",
602 | "ch1"
603 | ]
604 | },
605 | {
606 | "cell_type": "code",
607 | "execution_count": 13,
608 | "metadata": {},
609 | "outputs": [
610 | {
611 | "name": "stdout",
612 | "output_type": "stream",
613 | "text": [
614 | "\\begin{tabular}{lrrrr}\n",
615 | "\\toprule\n",
616 | "{} & Nodes & Links & Density & Average Degree \\\\\n",
617 | "Name & & & & \\\\\n",
618 | "\\midrule\n",
619 | "Facebook Northwestern University & 10567 & 488337 & 0.008748 & 92.426800 \\\\\n",
620 | "IMDB movies and actors & 563443 & 921160 & 0.000006 & 3.269754 \\\\\n",
621 | "IMDB actors costar & 252999 & 1015187 & 0.000032 & 8.025225 \\\\\n",
622 | "Twitter US politics & 18470 & 48365 & 0.000142 & 2.618571 \\\\\n",
623 | "Enron Email & 87273 & 321918 & 0.000042 & 3.688632 \\\\\n",
624 | "Enron Executive Email & 143 & 623 & 0.061361 & 8.713287 \\\\\n",
625 | "Wikipedia math & 15220 & 194103 & 0.000838 & 12.753154 \\\\\n",
626 | "Internet routers & 190914 & 607610 & 0.000033 & 6.365274 \\\\\n",
627 | "US air transportation & 546 & 2781 & 0.018691 & 10.186813 \\\\\n",
628 | "World air transportation & 3179 & 18617 & 0.003685 & 11.712488 \\\\\n",
629 | "Yeast protein interactions & 1870 & 2277 & 0.001303 & 2.435294 \\\\\n",
630 | "C. elegans brain & 297 & 2345 & 0.026674 & 7.895623 \\\\\n",
631 | "Everglades ecological food web & 69 & 916 & 0.195226 & 13.275362 \\\\\n",
632 | "\\bottomrule\n",
633 | "\\end{tabular}\n",
634 | "\n"
635 | ]
636 | }
637 | ],
638 | "source": [
639 | "print(ch1.to_latex())"
640 | ]
641 | },
642 | {
643 | "cell_type": "markdown",
644 | "metadata": {},
645 | "source": [
646 | "# Chapter 2\n",
647 | "\n",
648 | "* Nodes\n",
649 | "* Links\n",
650 | "* APL\n",
651 | "* CC"
652 | ]
653 | },
654 | {
655 | "cell_type": "code",
656 | "execution_count": 14,
657 | "metadata": {},
658 | "outputs": [
659 | {
660 | "data": {
661 | "text/html": [
662 | "\n",
663 | "\n",
676 | "
\n",
677 | " \n",
678 | " \n",
679 | " | \n",
680 | " Nodes | \n",
681 | " Links | \n",
682 | " Clustering | \n",
683 | " Average Path Length | \n",
684 | "
\n",
685 | " \n",
686 | " Name | \n",
687 | " | \n",
688 | " | \n",
689 | " | \n",
690 | " | \n",
691 | "
\n",
692 | " \n",
693 | " \n",
694 | " \n",
695 | " Facebook Northwestern University | \n",
696 | " 10567 | \n",
697 | " 488337 | \n",
698 | " 0.237991 | \n",
699 | " 2.718520 | \n",
700 | "
\n",
701 | " \n",
702 | " IMDB movies and actors | \n",
703 | " 563443 | \n",
704 | " 921160 | \n",
705 | " 0.000000 | \n",
706 | " 12.148362 | \n",
707 | "
\n",
708 | " \n",
709 | " IMDB actors costar | \n",
710 | " 252999 | \n",
711 | " 1015187 | \n",
712 | " 0.667560 | \n",
713 | " 6.849723 | \n",
714 | "
\n",
715 | " \n",
716 | " Twitter US politics | \n",
717 | " 18470 | \n",
718 | " 48365 | \n",
719 | " 0.026153 | \n",
720 | " 5.585333 | \n",
721 | "
\n",
722 | " \n",
723 | " Enron Email | \n",
724 | " 87273 | \n",
725 | " 321918 | \n",
726 | " 0.119342 | \n",
727 | " 3.613747 | \n",
728 | "
\n",
729 | " \n",
730 | " Enron Executive Email | \n",
731 | " 143 | \n",
732 | " 623 | \n",
733 | " 0.433907 | \n",
734 | " 2.946257 | \n",
735 | "
\n",
736 | " \n",
737 | " Wikipedia math | \n",
738 | " 15220 | \n",
739 | " 194103 | \n",
740 | " 0.307440 | \n",
741 | " 3.919790 | \n",
742 | "
\n",
743 | " \n",
744 | " Internet routers | \n",
745 | " 190914 | \n",
746 | " 607610 | \n",
747 | " 0.158173 | \n",
748 | " 7.009731 | \n",
749 | "
\n",
750 | " \n",
751 | " US air transportation | \n",
752 | " 546 | \n",
753 | " 2781 | \n",
754 | " 0.493045 | \n",
755 | " 3.191425 | \n",
756 | "
\n",
757 | " \n",
758 | " World air transportation | \n",
759 | " 3179 | \n",
760 | " 18617 | \n",
761 | " 0.490542 | \n",
762 | " 3.950245 | \n",
763 | "
\n",
764 | " \n",
765 | " Yeast protein interactions | \n",
766 | " 1870 | \n",
767 | " 2277 | \n",
768 | " 0.067168 | \n",
769 | " 6.785239 | \n",
770 | "
\n",
771 | " \n",
772 | " C. elegans brain | \n",
773 | " 297 | \n",
774 | " 2345 | \n",
775 | " 0.292363 | \n",
776 | " 3.977609 | \n",
777 | "
\n",
778 | " \n",
779 | " Everglades ecological food web | \n",
780 | " 69 | \n",
781 | " 916 | \n",
782 | " 0.552105 | \n",
783 | " 2.173056 | \n",
784 | "
\n",
785 | " \n",
786 | "
\n",
787 | "
"
788 | ],
789 | "text/plain": [
790 | " Nodes Links Clustering \\\n",
791 | "Name \n",
792 | "Facebook Northwestern University 10567 488337 0.237991 \n",
793 | "IMDB movies and actors 563443 921160 0.000000 \n",
794 | "IMDB actors costar 252999 1015187 0.667560 \n",
795 | "Twitter US politics 18470 48365 0.026153 \n",
796 | "Enron Email 87273 321918 0.119342 \n",
797 | "Enron Executive Email 143 623 0.433907 \n",
798 | "Wikipedia math 15220 194103 0.307440 \n",
799 | "Internet routers 190914 607610 0.158173 \n",
800 | "US air transportation 546 2781 0.493045 \n",
801 | "World air transportation 3179 18617 0.490542 \n",
802 | "Yeast protein interactions 1870 2277 0.067168 \n",
803 | "C. elegans brain 297 2345 0.292363 \n",
804 | "Everglades ecological food web 69 916 0.552105 \n",
805 | "\n",
806 | " Average Path Length \n",
807 | "Name \n",
808 | "Facebook Northwestern University 2.718520 \n",
809 | "IMDB movies and actors 12.148362 \n",
810 | "IMDB actors costar 6.849723 \n",
811 | "Twitter US politics 5.585333 \n",
812 | "Enron Email 3.613747 \n",
813 | "Enron Executive Email 2.946257 \n",
814 | "Wikipedia math 3.919790 \n",
815 | "Internet routers 7.009731 \n",
816 | "US air transportation 3.191425 \n",
817 | "World air transportation 3.950245 \n",
818 | "Yeast protein interactions 6.785239 \n",
819 | "C. elegans brain 3.977609 \n",
820 | "Everglades ecological food web 2.173056 "
821 | ]
822 | },
823 | "execution_count": 14,
824 | "metadata": {},
825 | "output_type": "execute_result"
826 | }
827 | ],
828 | "source": [
829 | "ch2 = df[['Nodes', 'Links', 'Clustering', 'Average Path Length']]\n",
830 | "ch2"
831 | ]
832 | },
833 | {
834 | "cell_type": "code",
835 | "execution_count": 15,
836 | "metadata": {},
837 | "outputs": [
838 | {
839 | "name": "stdout",
840 | "output_type": "stream",
841 | "text": [
842 | "\\begin{tabular}{lrrrr}\n",
843 | "\\toprule\n",
844 | "{} & Nodes & Links & Clustering & Average Path Length \\\\\n",
845 | "Name & & & & \\\\\n",
846 | "\\midrule\n",
847 | "Facebook Northwestern University & 10567 & 488337 & 0.237991 & 2.718520 \\\\\n",
848 | "IMDB movies and actors & 563443 & 921160 & 0.000000 & 12.148362 \\\\\n",
849 | "IMDB actors costar & 252999 & 1015187 & 0.667560 & 6.849723 \\\\\n",
850 | "Twitter US politics & 18470 & 48365 & 0.026153 & 5.585333 \\\\\n",
851 | "Enron Email & 87273 & 321918 & 0.119342 & 3.613747 \\\\\n",
852 | "Enron Executive Email & 143 & 623 & 0.433907 & 2.946257 \\\\\n",
853 | "Wikipedia math & 15220 & 194103 & 0.307440 & 3.919790 \\\\\n",
854 | "Internet routers & 190914 & 607610 & 0.158173 & 7.009731 \\\\\n",
855 | "US air transportation & 546 & 2781 & 0.493045 & 3.191425 \\\\\n",
856 | "World air transportation & 3179 & 18617 & 0.490542 & 3.950245 \\\\\n",
857 | "Yeast protein interactions & 1870 & 2277 & 0.067168 & 6.785239 \\\\\n",
858 | "C. elegans brain & 297 & 2345 & 0.292363 & 3.977609 \\\\\n",
859 | "Everglades ecological food web & 69 & 916 & 0.552105 & 2.173056 \\\\\n",
860 | "\\bottomrule\n",
861 | "\\end{tabular}\n",
862 | "\n"
863 | ]
864 | }
865 | ],
866 | "source": [
867 | "print(ch2.to_latex())"
868 | ]
869 | },
870 | {
871 | "cell_type": "markdown",
872 | "metadata": {},
873 | "source": [
874 | "## Chapter 3\n",
875 | "* Nodes\n",
876 | "* Links\n",
877 | "* Density\n",
878 | "* Average degree\n",
879 | "* Maximum degree\n",
880 | "* Heterogeneity"
881 | ]
882 | },
883 | {
884 | "cell_type": "code",
885 | "execution_count": 16,
886 | "metadata": {},
887 | "outputs": [
888 | {
889 | "data": {
890 | "text/html": [
891 | "\n",
892 | "\n",
905 | "
\n",
906 | " \n",
907 | " \n",
908 | " | \n",
909 | " Nodes | \n",
910 | " Links | \n",
911 | " Average Degree | \n",
912 | " Maximum Degree | \n",
913 | " Heterogeneity | \n",
914 | "
\n",
915 | " \n",
916 | " Name | \n",
917 | " | \n",
918 | " | \n",
919 | " | \n",
920 | " | \n",
921 | " | \n",
922 | "
\n",
923 | " \n",
924 | " \n",
925 | " \n",
926 | " Facebook Northwestern University | \n",
927 | " 10567 | \n",
928 | " 488337 | \n",
929 | " 92.426800 | \n",
930 | " 2105 | \n",
931 | " 1.835828 | \n",
932 | "
\n",
933 | " \n",
934 | " IMDB movies and actors | \n",
935 | " 563443 | \n",
936 | " 921160 | \n",
937 | " 3.269754 | \n",
938 | " 800 | \n",
939 | " 5.406334 | \n",
940 | "
\n",
941 | " \n",
942 | " IMDB actors costar | \n",
943 | " 252999 | \n",
944 | " 1015187 | \n",
945 | " 8.025225 | \n",
946 | " 456 | \n",
947 | " 4.570261 | \n",
948 | "
\n",
949 | " \n",
950 | " Twitter US politics | \n",
951 | " 18470 | \n",
952 | " 48365 | \n",
953 | " 2.618571 | \n",
954 | " 204 | \n",
955 | " 8.298196 | \n",
956 | "
\n",
957 | " \n",
958 | " Enron Email | \n",
959 | " 87273 | \n",
960 | " 321918 | \n",
961 | " 3.688632 | \n",
962 | " 1338 | \n",
963 | " 17.436859 | \n",
964 | "
\n",
965 | " \n",
966 | " Enron Executive Email | \n",
967 | " 143 | \n",
968 | " 623 | \n",
969 | " 8.713287 | \n",
970 | " 42 | \n",
971 | " 1.482948 | \n",
972 | "
\n",
973 | " \n",
974 | " Wikipedia math | \n",
975 | " 15220 | \n",
976 | " 194103 | \n",
977 | " 12.753154 | \n",
978 | " 5171 | \n",
979 | " 38.210205 | \n",
980 | "
\n",
981 | " \n",
982 | " Internet routers | \n",
983 | " 190914 | \n",
984 | " 607610 | \n",
985 | " 6.365274 | \n",
986 | " 1071 | \n",
987 | " 5.963275 | \n",
988 | "
\n",
989 | " \n",
990 | " US air transportation | \n",
991 | " 546 | \n",
992 | " 2781 | \n",
993 | " 10.186813 | \n",
994 | " 153 | \n",
995 | " 5.347495 | \n",
996 | "
\n",
997 | " \n",
998 | " World air transportation | \n",
999 | " 3179 | \n",
1000 | " 18617 | \n",
1001 | " 11.712488 | \n",
1002 | " 246 | \n",
1003 | " 5.509073 | \n",
1004 | "
\n",
1005 | " \n",
1006 | " Yeast protein interactions | \n",
1007 | " 1870 | \n",
1008 | " 2277 | \n",
1009 | " 2.435294 | \n",
1010 | " 56 | \n",
1011 | " 2.687747 | \n",
1012 | "
\n",
1013 | " \n",
1014 | " C. elegans brain | \n",
1015 | " 297 | \n",
1016 | " 2345 | \n",
1017 | " 7.895623 | \n",
1018 | " 134 | \n",
1019 | " 2.713711 | \n",
1020 | "
\n",
1021 | " \n",
1022 | " Everglades ecological food web | \n",
1023 | " 69 | \n",
1024 | " 916 | \n",
1025 | " 13.275362 | \n",
1026 | " 63 | \n",
1027 | " 2.236306 | \n",
1028 | "
\n",
1029 | " \n",
1030 | "
\n",
1031 | "
"
1032 | ],
1033 | "text/plain": [
1034 | " Nodes Links Average Degree \\\n",
1035 | "Name \n",
1036 | "Facebook Northwestern University 10567 488337 92.426800 \n",
1037 | "IMDB movies and actors 563443 921160 3.269754 \n",
1038 | "IMDB actors costar 252999 1015187 8.025225 \n",
1039 | "Twitter US politics 18470 48365 2.618571 \n",
1040 | "Enron Email 87273 321918 3.688632 \n",
1041 | "Enron Executive Email 143 623 8.713287 \n",
1042 | "Wikipedia math 15220 194103 12.753154 \n",
1043 | "Internet routers 190914 607610 6.365274 \n",
1044 | "US air transportation 546 2781 10.186813 \n",
1045 | "World air transportation 3179 18617 11.712488 \n",
1046 | "Yeast protein interactions 1870 2277 2.435294 \n",
1047 | "C. elegans brain 297 2345 7.895623 \n",
1048 | "Everglades ecological food web 69 916 13.275362 \n",
1049 | "\n",
1050 | " Maximum Degree Heterogeneity \n",
1051 | "Name \n",
1052 | "Facebook Northwestern University 2105 1.835828 \n",
1053 | "IMDB movies and actors 800 5.406334 \n",
1054 | "IMDB actors costar 456 4.570261 \n",
1055 | "Twitter US politics 204 8.298196 \n",
1056 | "Enron Email 1338 17.436859 \n",
1057 | "Enron Executive Email 42 1.482948 \n",
1058 | "Wikipedia math 5171 38.210205 \n",
1059 | "Internet routers 1071 5.963275 \n",
1060 | "US air transportation 153 5.347495 \n",
1061 | "World air transportation 246 5.509073 \n",
1062 | "Yeast protein interactions 56 2.687747 \n",
1063 | "C. elegans brain 134 2.713711 \n",
1064 | "Everglades ecological food web 63 2.236306 "
1065 | ]
1066 | },
1067 | "execution_count": 16,
1068 | "metadata": {},
1069 | "output_type": "execute_result"
1070 | }
1071 | ],
1072 | "source": [
1073 | "ch3 = df[['Nodes', 'Links', 'Average Degree', 'Maximum Degree', 'Heterogeneity']]\n",
1074 | "ch3"
1075 | ]
1076 | },
1077 | {
1078 | "cell_type": "code",
1079 | "execution_count": 17,
1080 | "metadata": {},
1081 | "outputs": [
1082 | {
1083 | "name": "stdout",
1084 | "output_type": "stream",
1085 | "text": [
1086 | "\\begin{tabular}{lrrrrr}\n",
1087 | "\\toprule\n",
1088 | "{} & Nodes & Links & Average Degree & Maximum Degree & Heterogeneity \\\\\n",
1089 | "Name & & & & & \\\\\n",
1090 | "\\midrule\n",
1091 | "Facebook Northwestern University & 10567 & 488337 & 92.426800 & 2105 & 1.835828 \\\\\n",
1092 | "IMDB movies and actors & 563443 & 921160 & 3.269754 & 800 & 5.406334 \\\\\n",
1093 | "IMDB actors costar & 252999 & 1015187 & 8.025225 & 456 & 4.570261 \\\\\n",
1094 | "Twitter US politics & 18470 & 48365 & 2.618571 & 204 & 8.298196 \\\\\n",
1095 | "Enron Email & 87273 & 321918 & 3.688632 & 1338 & 17.436859 \\\\\n",
1096 | "Enron Executive Email & 143 & 623 & 8.713287 & 42 & 1.482948 \\\\\n",
1097 | "Wikipedia math & 15220 & 194103 & 12.753154 & 5171 & 38.210205 \\\\\n",
1098 | "Internet routers & 190914 & 607610 & 6.365274 & 1071 & 5.963275 \\\\\n",
1099 | "US air transportation & 546 & 2781 & 10.186813 & 153 & 5.347495 \\\\\n",
1100 | "World air transportation & 3179 & 18617 & 11.712488 & 246 & 5.509073 \\\\\n",
1101 | "Yeast protein interactions & 1870 & 2277 & 2.435294 & 56 & 2.687747 \\\\\n",
1102 | "C. elegans brain & 297 & 2345 & 7.895623 & 134 & 2.713711 \\\\\n",
1103 | "Everglades ecological food web & 69 & 916 & 13.275362 & 63 & 2.236306 \\\\\n",
1104 | "\\bottomrule\n",
1105 | "\\end{tabular}\n",
1106 | "\n"
1107 | ]
1108 | }
1109 | ],
1110 | "source": [
1111 | "print(ch3.to_latex())"
1112 | ]
1113 | },
1114 | {
1115 | "cell_type": "code",
1116 | "execution_count": null,
1117 | "metadata": {},
1118 | "outputs": [],
1119 | "source": []
1120 | },
1121 | {
1122 | "cell_type": "code",
1123 | "execution_count": 18,
1124 | "metadata": {},
1125 | "outputs": [],
1126 | "source": [
1127 | "df.to_csv('summary_statistics.csv')"
1128 | ]
1129 | },
1130 | {
1131 | "cell_type": "code",
1132 | "execution_count": null,
1133 | "metadata": {},
1134 | "outputs": [],
1135 | "source": []
1136 | }
1137 | ],
1138 | "metadata": {
1139 | "kernelspec": {
1140 | "display_name": "Python 3",
1141 | "language": "python",
1142 | "name": "python3"
1143 | },
1144 | "language_info": {
1145 | "codemirror_mode": {
1146 | "name": "ipython",
1147 | "version": 3
1148 | },
1149 | "file_extension": ".py",
1150 | "mimetype": "text/x-python",
1151 | "name": "python",
1152 | "nbconvert_exporter": "python",
1153 | "pygments_lexer": "ipython3",
1154 | "version": "3.6.5"
1155 | }
1156 | },
1157 | "nbformat": 4,
1158 | "nbformat_minor": 2
1159 | }
1160 |
--------------------------------------------------------------------------------
/datasets/tech-RL-caida/README.md:
--------------------------------------------------------------------------------
1 | Number of nodes: 190914
2 | Number of edges: 607610
3 | Average degree: 6.3653
4 |
--------------------------------------------------------------------------------
/datasets/tech-RL-caida/tech-RL-caida.edges.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/datasets/tech-RL-caida/tech-RL-caida.edges.gz
--------------------------------------------------------------------------------
/sample/Selected_Exercise_Solutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/Selected_Exercise_Solutions.pdf
--------------------------------------------------------------------------------
/sample/chapters/chapter0.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/chapters/chapter0.pdf
--------------------------------------------------------------------------------
/sample/chapters/chapter4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/chapters/chapter4.pdf
--------------------------------------------------------------------------------
/sample/slides/chapter0.key:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/slides/chapter0.key
--------------------------------------------------------------------------------
/sample/slides/chapter0.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/slides/chapter0.pptx
--------------------------------------------------------------------------------
/sample/slides/chapter4.key:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/slides/chapter4.key
--------------------------------------------------------------------------------
/sample/slides/chapter4.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CambridgeUniversityPress/FirstCourseNetworkScience/de9b42e3953ed90616940a801f64489067c1b888/sample/slides/chapter4.pptx
--------------------------------------------------------------------------------
/tutorials/Appendix - Python Tutorial.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Appendix: Python Tutorial\n",
8 | "\n",
9 | "This optional tutorial demonstrates the features of the Python language and of Jupyter Notebook that are used in the examples and tutorials of the textbook. Special attention is given to the most important data types used in data analysis workflows, as well as common idioms and patterns employed in these use-cases. This appendix may be especially useful for readers more experienced in programming languages other than Python.\n",
10 | "\n",
11 | "Contents:\n",
12 | "\n",
13 | "1. [Jupyter Notebook](#1.-Jupyter-Notebook)\n",
14 | "2. [Conditionals](#2.-Conditionals)\n",
15 | "3. [Lists](#3.-Lists)\n",
16 | "4. [Loops](#4.-Loops)\n",
17 | "5. [Tuples](#5.-Tuples)\n",
18 | "6. [Dictionaries](#6.-Dictionaries)\n",
19 | "7. [Combining Data Types](#7.-Combining-Data-Types)"
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {},
25 | "source": [
26 | "# 1. Jupyter Notebook\n",
27 | "\n",
28 | "Even if you're well-versed in Python, you may not have used Jupyter Notebook before. The main idea is that we can mix text and code, and that code is executed in \"cells.\" By clicking on a cell and pressing Shift + Enter, you execute the cell and move to the next cell. Ctrl + Enter executes the cell but does not move to the next cell. You can run many cells at once by using the different options in the \"Cell\" menu.\n",
29 | "\n",
30 | "Try executing the code in the next cell and observe that the output is printed below the cell."
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 1,
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "name": "stdout",
40 | "output_type": "stream",
41 | "text": [
42 | "Hello from Jupyter\n"
43 | ]
44 | }
45 | ],
46 | "source": [
47 | "print('Hello from Jupyter')"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "## 1.1 Printing and inspecting variables\n",
55 | "\n",
56 | "In Jupyter notebooks, we have two different ways of inspecting variables. Python's `print()` function is useful as always:"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 2,
62 | "metadata": {},
63 | "outputs": [
64 | {
65 | "name": "stdout",
66 | "output_type": "stream",
67 | "text": [
68 | "Hello\n",
69 | "16\n"
70 | ]
71 | }
72 | ],
73 | "source": [
74 | "my_str = 'Hello'\n",
75 | "my_int = 16\n",
76 | "\n",
77 | "print(my_str)\n",
78 | "print(my_int)"
79 | ]
80 | },
81 | {
82 | "cell_type": "markdown",
83 | "metadata": {},
84 | "source": [
85 | "We can also just execute a cell with the name of a variable:"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": 3,
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "data": {
95 | "text/plain": [
96 | "'Hello'"
97 | ]
98 | },
99 | "execution_count": 3,
100 | "metadata": {},
101 | "output_type": "execute_result"
102 | }
103 | ],
104 | "source": [
105 | "my_str"
106 | ]
107 | },
108 | {
109 | "cell_type": "markdown",
110 | "metadata": {},
111 | "source": [
112 | "The big difference here between the two approaches is that `print()` statements can output multiple items per cell, while the latter approach will only display the last variable named. Observe:"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": 4,
118 | "metadata": {},
119 | "outputs": [
120 | {
121 | "data": {
122 | "text/plain": [
123 | "16"
124 | ]
125 | },
126 | "execution_count": 4,
127 | "metadata": {},
128 | "output_type": "execute_result"
129 | }
130 | ],
131 | "source": [
132 | "my_str\n",
133 | "my_int"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "As opposed to the first example using `print()`, this only outputs the last value."
141 | ]
142 | },
143 | {
144 | "cell_type": "markdown",
145 | "metadata": {},
146 | "source": [
147 | "## Nota Bene\n",
148 | "One key advantage of presenting information in this notebook format is that it allows you to change and re-run the code cells, then see how the output differs. Don't be afraid to experiment!"
149 | ]
150 | },
151 | {
152 | "cell_type": "markdown",
153 | "metadata": {},
154 | "source": [
155 | "# 2. Conditionals\n",
156 | "\n",
157 | "\"Conditionals\" is a fancy word for if-statements. If you've ever done any programming, you are surely aware of the if-then-else construction. In Python it's done as follows:"
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": 5,
163 | "metadata": {},
164 | "outputs": [
165 | {
166 | "name": "stdout",
167 | "output_type": "stream",
168 | "text": [
169 | "You have many apples!\n"
170 | ]
171 | }
172 | ],
173 | "source": [
174 | "number_of_apples = 5\n",
175 | "\n",
176 | "if number_of_apples < 1:\n",
177 | " print('You have no apples')\n",
178 | "elif number_of_apples == 1:\n",
179 | " print('You have one apple')\n",
180 | "elif number_of_apples < 4:\n",
181 | " print('You have a few apples')\n",
182 | "else:\n",
183 | " print('You have many apples!')"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {},
189 | "source": [
190 | "You can change `number_of_apples` and re-run the previous cell in order to get the different possible outputs.\n"
191 | ]
192 | },
193 | {
194 | "cell_type": "markdown",
195 | "metadata": {},
196 | "source": [
197 | "# 3. Lists\n",
198 | "\n",
199 | "One of Python's most versatile and ubiquitous data types is the List ([Python documentation](https://docs.python.org/3/library/stdtypes.html#list)). This is an **ordered**, **mutable**, **collection** of **non-unique** items.\n",
200 | "\n",
201 | "## 3.1 Ordered\n",
202 | "\n",
203 | "By *ordered*, we mean that the items are addressed by their *index* in the collection:"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": 6,
209 | "metadata": {},
210 | "outputs": [
211 | {
212 | "data": {
213 | "text/plain": [
214 | "'Bob'"
215 | ]
216 | },
217 | "execution_count": 6,
218 | "metadata": {},
219 | "output_type": "execute_result"
220 | }
221 | ],
222 | "source": [
223 | "student_names = ['Alice', 'Bob', 'Carol', 'Dave']\n",
224 | "student_names[1]"
225 | ]
226 | },
227 | {
228 | "cell_type": "markdown",
229 | "metadata": {},
230 | "source": [
231 | "Indices in Python start at zero, so the head of the list has index 0:"
232 | ]
233 | },
234 | {
235 | "cell_type": "code",
236 | "execution_count": 7,
237 | "metadata": {
238 | "scrolled": true
239 | },
240 | "outputs": [
241 | {
242 | "data": {
243 | "text/plain": [
244 | "'Alice'"
245 | ]
246 | },
247 | "execution_count": 7,
248 | "metadata": {},
249 | "output_type": "execute_result"
250 | }
251 | ],
252 | "source": [
253 | "student_names[0]"
254 | ]
255 | },
256 | {
257 | "cell_type": "markdown",
258 | "metadata": {},
259 | "source": [
260 | "We can get the last item in a list by using negative indexing:"
261 | ]
262 | },
263 | {
264 | "cell_type": "code",
265 | "execution_count": 8,
266 | "metadata": {},
267 | "outputs": [
268 | {
269 | "data": {
270 | "text/plain": [
271 | "'Dave'"
272 | ]
273 | },
274 | "execution_count": 8,
275 | "metadata": {},
276 | "output_type": "execute_result"
277 | }
278 | ],
279 | "source": [
280 | "student_names[-1]"
281 | ]
282 | },
283 | {
284 | "cell_type": "markdown",
285 | "metadata": {},
286 | "source": [
287 | "Lists can also be *sliced* to get a subset of the list items:"
288 | ]
289 | },
290 | {
291 | "cell_type": "code",
292 | "execution_count": 9,
293 | "metadata": {},
294 | "outputs": [
295 | {
296 | "data": {
297 | "text/plain": [
298 | "['Alice', 'Bob']"
299 | ]
300 | },
301 | "execution_count": 9,
302 | "metadata": {},
303 | "output_type": "execute_result"
304 | }
305 | ],
306 | "source": [
307 | "student_names[0:2]"
308 | ]
309 | },
310 | {
311 | "cell_type": "code",
312 | "execution_count": 10,
313 | "metadata": {},
314 | "outputs": [
315 | {
316 | "data": {
317 | "text/plain": [
318 | "['Bob', 'Carol']"
319 | ]
320 | },
321 | "execution_count": 10,
322 | "metadata": {},
323 | "output_type": "execute_result"
324 | }
325 | ],
326 | "source": [
327 | "student_names[1:3]"
328 | ]
329 | },
330 | {
331 | "cell_type": "markdown",
332 | "metadata": {},
333 | "source": [
334 | "When slicing from the beginning of the list, or to the end of the list, we can leave out the index:"
335 | ]
336 | },
337 | {
338 | "cell_type": "code",
339 | "execution_count": 11,
340 | "metadata": {},
341 | "outputs": [
342 | {
343 | "data": {
344 | "text/plain": [
345 | "['Alice', 'Bob']"
346 | ]
347 | },
348 | "execution_count": 11,
349 | "metadata": {},
350 | "output_type": "execute_result"
351 | }
352 | ],
353 | "source": [
354 | "student_names[:2]"
355 | ]
356 | },
357 | {
358 | "cell_type": "code",
359 | "execution_count": 12,
360 | "metadata": {},
361 | "outputs": [
362 | {
363 | "data": {
364 | "text/plain": [
365 | "['Carol', 'Dave']"
366 | ]
367 | },
368 | "execution_count": 12,
369 | "metadata": {},
370 | "output_type": "execute_result"
371 | }
372 | ],
373 | "source": [
374 | "student_names[2:]"
375 | ]
376 | },
377 | {
378 | "cell_type": "markdown",
379 | "metadata": {},
380 | "source": [
381 | "## 3.2 Mutable\n",
382 | "\n",
383 | "By *mutable*, we mean that the list can be changed by adding or removing items. We most often add items to the end of the list with `.append()`:"
384 | ]
385 | },
386 | {
387 | "cell_type": "code",
388 | "execution_count": 13,
389 | "metadata": {},
390 | "outputs": [
391 | {
392 | "data": {
393 | "text/plain": [
394 | "['Alice', 'Bob', 'Carol', 'Dave', 'Esther']"
395 | ]
396 | },
397 | "execution_count": 13,
398 | "metadata": {},
399 | "output_type": "execute_result"
400 | }
401 | ],
402 | "source": [
403 | "student_names.append('Esther')\n",
404 | "student_names"
405 | ]
406 | },
407 | {
408 | "cell_type": "markdown",
409 | "metadata": {},
410 | "source": [
411 | "But we can also add items at any arbitrary index with `.insert()`:"
412 | ]
413 | },
414 | {
415 | "cell_type": "code",
416 | "execution_count": 14,
417 | "metadata": {},
418 | "outputs": [
419 | {
420 | "data": {
421 | "text/plain": [
422 | "['Alice', 'Bob', 'Xavier', 'Carol', 'Dave', 'Esther']"
423 | ]
424 | },
425 | "execution_count": 14,
426 | "metadata": {},
427 | "output_type": "execute_result"
428 | }
429 | ],
430 | "source": [
431 | "student_names.insert(2, 'Xavier')\n",
432 | "student_names"
433 | ]
434 | },
435 | {
436 | "cell_type": "markdown",
437 | "metadata": {},
438 | "source": [
439 | "We can delete items with the `del` keyword:"
440 | ]
441 | },
442 | {
443 | "cell_type": "code",
444 | "execution_count": 15,
445 | "metadata": {},
446 | "outputs": [
447 | {
448 | "data": {
449 | "text/plain": [
450 | "['Alice', 'Bob', 'Carol', 'Dave', 'Esther']"
451 | ]
452 | },
453 | "execution_count": 15,
454 | "metadata": {},
455 | "output_type": "execute_result"
456 | }
457 | ],
458 | "source": [
459 | "del student_names[2]\n",
460 | "student_names"
461 | ]
462 | },
463 | {
464 | "cell_type": "markdown",
465 | "metadata": {},
466 | "source": [
467 | "## 3.3 Non-unique\n",
468 | "\n",
469 | "Note that nothing stops us from repeatedly adding the same name to this list:"
470 | ]
471 | },
472 | {
473 | "cell_type": "code",
474 | "execution_count": 16,
475 | "metadata": {},
476 | "outputs": [
477 | {
478 | "data": {
479 | "text/plain": [
480 | "['Alice', 'Bob', 'Carol', 'Dave', 'Esther', 'Esther', 'Esther']"
481 | ]
482 | },
483 | "execution_count": 16,
484 | "metadata": {},
485 | "output_type": "execute_result"
486 | }
487 | ],
488 | "source": [
489 | "student_names.append('Esther')\n",
490 | "student_names.append('Esther')\n",
491 | "student_names"
492 | ]
493 | },
494 | {
495 | "cell_type": "markdown",
496 | "metadata": {},
497 | "source": [
498 | "If you want a collection where uniqueness is enforced, you should look towards\n",
499 | "[sets](https://docs.python.org/3/library/stdtypes.html#set)\n",
500 | "or\n",
501 | "[dictionaries](https://docs.python.org/3/library/stdtypes.html#dict).\n",
502 | "\n",
503 | "## 3.4 Collection\n",
504 | "\n",
505 | "A collection refers to a data type consisting of more than one values. Lists are one type of collection, but there are others such as tuples, sets, and dictionaries.\n",
506 | "\n",
507 | "When naming your variables that contain lists, you should use plural nouns, *e.g.* `student_names` in the previous example. In contrast, single values should be named with singular nouns, *e.g.* `my_str` in the first section. This helps you and others reading your code keep straight which variables are collections and which are single items, and also helps when writing loops as shown in the next section."
508 | ]
509 | },
510 | {
511 | "cell_type": "markdown",
512 | "metadata": {},
513 | "source": [
514 | "# 4. Loops\n",
515 | "\n",
516 | "If you're coming from another programming language, you're probably aware of more than one type of loop. In Python, we focus on one type of loop in particular: the for-loop. The for-loop iterates through a collection of items, executing its code for each item:"
517 | ]
518 | },
519 | {
520 | "cell_type": "code",
521 | "execution_count": 17,
522 | "metadata": {},
523 | "outputs": [
524 | {
525 | "name": "stdout",
526 | "output_type": "stream",
527 | "text": [
528 | "Hello Alice!\n",
529 | "Hello Bob!\n",
530 | "Hello Carol!\n",
531 | "Hello Dave!\n"
532 | ]
533 | }
534 | ],
535 | "source": [
536 | "student_names = ['Alice', 'Bob', 'Carol', 'Dave']\n",
537 | "\n",
538 | "for student_name in student_names:\n",
539 | " print('Hello ' + student_name + '!')"
540 | ]
541 | },
542 | {
543 | "cell_type": "markdown",
544 | "metadata": {},
545 | "source": [
546 | "## 4.1 Naming conventions\n",
547 | "\n",
548 | "Note the naming convention being used in the for-in construction:\n",
549 | "\n",
550 | " for student_name in student_names:\n",
551 | " \n",
552 | "By using a plural noun for the collection `student_names`, we automatically have good name for the individual items in the collection: `student_name`. The tutorials in this book use this naming convention when possible as it makes clear to the reader which variable is the \"loop variable\" that changes value between iterations of the loop body."
553 | ]
554 | },
555 | {
556 | "cell_type": "markdown",
557 | "metadata": {},
558 | "source": [
559 | "## 4.2 Loops, lists, and conditionals\n",
560 | "\n",
561 | "One extremely common type of task when working with data is the *filtering task*. In abstract, this task involves looping over one collection, checking each item for some criterion, then adding items that meet the criterion to another collection.\n",
562 | "\n",
563 | "In the following example, we'll create a list of just the \"long\" names from the `student_names` list. Long names are those that contain more than four characters. You will often see and write code that looks like the following in this book's tutorials:"
564 | ]
565 | },
566 | {
567 | "cell_type": "code",
568 | "execution_count": 18,
569 | "metadata": {},
570 | "outputs": [
571 | {
572 | "data": {
573 | "text/plain": [
574 | "['Alice', 'Carol']"
575 | ]
576 | },
577 | "execution_count": 18,
578 | "metadata": {},
579 | "output_type": "execute_result"
580 | }
581 | ],
582 | "source": [
583 | "# Initialize an empty list and add to it the\n",
584 | "# student names containing more than four characters\n",
585 | "long_names = []\n",
586 | "for student_name in student_names:\n",
587 | " # This is our criterion\n",
588 | " if len(student_name) > 4:\n",
589 | " long_names.append(student_name)\n",
590 | "\n",
591 | "long_names"
592 | ]
593 | },
594 | {
595 | "cell_type": "markdown",
596 | "metadata": {},
597 | "source": [
598 | "## 4.3 Nested loops\n",
599 | "\n",
600 | "Loops can be \"nested\" inside one another. This often occurs when we want to match up items from one collection to items from the same or another collection. Here let's create a list of all possible pairs of students:"
601 | ]
602 | },
603 | {
604 | "cell_type": "code",
605 | "execution_count": 19,
606 | "metadata": {},
607 | "outputs": [
608 | {
609 | "data": {
610 | "text/plain": [
611 | "[('Alice', 'Alice'),\n",
612 | " ('Alice', 'Bob'),\n",
613 | " ('Alice', 'Carol'),\n",
614 | " ('Alice', 'Dave'),\n",
615 | " ('Bob', 'Alice'),\n",
616 | " ('Bob', 'Bob'),\n",
617 | " ('Bob', 'Carol'),\n",
618 | " ('Bob', 'Dave'),\n",
619 | " ('Carol', 'Alice'),\n",
620 | " ('Carol', 'Bob'),\n",
621 | " ('Carol', 'Carol'),\n",
622 | " ('Carol', 'Dave'),\n",
623 | " ('Dave', 'Alice'),\n",
624 | " ('Dave', 'Bob'),\n",
625 | " ('Dave', 'Carol'),\n",
626 | " ('Dave', 'Dave')]"
627 | ]
628 | },
629 | "execution_count": 19,
630 | "metadata": {},
631 | "output_type": "execute_result"
632 | }
633 | ],
634 | "source": [
635 | "student_names = ['Alice', 'Bob', 'Carol', 'Dave']\n",
636 | "\n",
637 | "student_pairs = []\n",
638 | "for student_name_0 in student_names:\n",
639 | " for student_name_1 in student_names:\n",
640 | " student_pairs.append(\n",
641 | " (student_name_0, student_name_1)\n",
642 | " )\n",
643 | "\n",
644 | "student_pairs"
645 | ]
646 | },
647 | {
648 | "cell_type": "markdown",
649 | "metadata": {},
650 | "source": [
651 | "Note here that instead of just adding names to the `student_pairs` list, we are adding *tuples* `(student_name, language)`. This means each item in the list is a 2-tuple:"
652 | ]
653 | },
654 | {
655 | "cell_type": "code",
656 | "execution_count": 20,
657 | "metadata": {},
658 | "outputs": [
659 | {
660 | "data": {
661 | "text/plain": [
662 | "('Alice', 'Alice')"
663 | ]
664 | },
665 | "execution_count": 20,
666 | "metadata": {},
667 | "output_type": "execute_result"
668 | }
669 | ],
670 | "source": [
671 | "student_pairs[0]"
672 | ]
673 | },
674 | {
675 | "cell_type": "markdown",
676 | "metadata": {},
677 | "source": [
678 | "We'll talk more about tuples in the next section. The second thing to notice is that we're including pairs with two of the same student. Suppose we wish to exclude those. We can accomplish this by adding an if-statement in the second for-loop to *filter* out those repeats:"
679 | ]
680 | },
681 | {
682 | "cell_type": "code",
683 | "execution_count": 21,
684 | "metadata": {},
685 | "outputs": [
686 | {
687 | "data": {
688 | "text/plain": [
689 | "[('Alice', 'Bob'),\n",
690 | " ('Alice', 'Carol'),\n",
691 | " ('Alice', 'Dave'),\n",
692 | " ('Bob', 'Alice'),\n",
693 | " ('Bob', 'Carol'),\n",
694 | " ('Bob', 'Dave'),\n",
695 | " ('Carol', 'Alice'),\n",
696 | " ('Carol', 'Bob'),\n",
697 | " ('Carol', 'Dave'),\n",
698 | " ('Dave', 'Alice'),\n",
699 | " ('Dave', 'Bob'),\n",
700 | " ('Dave', 'Carol')]"
701 | ]
702 | },
703 | "execution_count": 21,
704 | "metadata": {},
705 | "output_type": "execute_result"
706 | }
707 | ],
708 | "source": [
709 | "student_names = ['Alice', 'Bob', 'Carol', 'Dave']\n",
710 | "\n",
711 | "student_pairs = []\n",
712 | "for student_name_0 in student_names:\n",
713 | " for student_name_1 in student_names:\n",
714 | " # This is the criterion we added\n",
715 | " if student_name_0 != student_name_1:\n",
716 | " student_pairs.append(\n",
717 | " (student_name_0, student_name_1)\n",
718 | " )\n",
719 | "\n",
720 | "student_pairs"
721 | ]
722 | },
723 | {
724 | "cell_type": "markdown",
725 | "metadata": {},
726 | "source": [
727 | "And now the list has no repeats."
728 | ]
729 | },
730 | {
731 | "cell_type": "markdown",
732 | "metadata": {},
733 | "source": [
734 | "# 5. Tuples\n",
735 | "\n",
736 | "Even experienced Python users often are confused about the difference between tuples and lists, so definitely read this short section even if you have some experience.\n",
737 | "\n",
738 | "Tuples ([documentation](https://docs.python.org/3/library/stdtypes.html#tuple)) are superficially similar to lists as they are an ordered collection of non-unique items:"
739 | ]
740 | },
741 | {
742 | "cell_type": "code",
743 | "execution_count": 22,
744 | "metadata": {},
745 | "outputs": [
746 | {
747 | "data": {
748 | "text/plain": [
749 | "('Alice', 'Spanish', 'A-')"
750 | ]
751 | },
752 | "execution_count": 22,
753 | "metadata": {},
754 | "output_type": "execute_result"
755 | }
756 | ],
757 | "source": [
758 | "student_grade = ('Alice', 'Spanish', 'A-')\n",
759 | "student_grade"
760 | ]
761 | },
762 | {
763 | "cell_type": "code",
764 | "execution_count": 23,
765 | "metadata": {},
766 | "outputs": [
767 | {
768 | "data": {
769 | "text/plain": [
770 | "'Alice'"
771 | ]
772 | },
773 | "execution_count": 23,
774 | "metadata": {},
775 | "output_type": "execute_result"
776 | }
777 | ],
778 | "source": [
779 | "student_grade[0]"
780 | ]
781 | },
782 | {
783 | "cell_type": "markdown",
784 | "metadata": {},
785 | "source": [
786 | "## 5.1 Immutable\n",
787 | "\n",
788 | "The big difference from lists is that tuples are **immutable**. Each of the following cells should raise an exception."
789 | ]
790 | },
791 | {
792 | "cell_type": "code",
793 | "execution_count": 24,
794 | "metadata": {
795 | "tags": [
796 | "raises-exception"
797 | ]
798 | },
799 | "outputs": [
800 | {
801 | "ename": "AttributeError",
802 | "evalue": "'tuple' object has no attribute 'append'",
803 | "output_type": "error",
804 | "traceback": [
805 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
806 | "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
807 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mstudent_grade\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'IU Bloomington'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
808 | "\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
809 | ]
810 | }
811 | ],
812 | "source": [
813 | "student_grade.append('IU Bloomington')"
814 | ]
815 | },
816 | {
817 | "cell_type": "code",
818 | "execution_count": 25,
819 | "metadata": {
820 | "tags": [
821 | "raises-exception"
822 | ]
823 | },
824 | "outputs": [
825 | {
826 | "ename": "TypeError",
827 | "evalue": "'tuple' object doesn't support item deletion",
828 | "output_type": "error",
829 | "traceback": [
830 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
831 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
832 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mdel\u001b[0m \u001b[0mstudent_grade\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
833 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object doesn't support item deletion"
834 | ]
835 | }
836 | ],
837 | "source": [
838 | "del student_grade[2]"
839 | ]
840 | },
841 | {
842 | "cell_type": "code",
843 | "execution_count": 26,
844 | "metadata": {
845 | "tags": [
846 | "raises-exception"
847 | ]
848 | },
849 | "outputs": [
850 | {
851 | "ename": "TypeError",
852 | "evalue": "'tuple' object does not support item assignment",
853 | "output_type": "error",
854 | "traceback": [
855 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
856 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
857 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mstudent_grade\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'C'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
858 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
859 | ]
860 | }
861 | ],
862 | "source": [
863 | "student_grade[2] = 'C'"
864 | ]
865 | },
866 | {
867 | "cell_type": "markdown",
868 | "metadata": {},
869 | "source": [
870 | "This immutability makes tuples useful when **index matters**. In this example, the index matters semantically: index 0 is the student's name, index 1 is the course name, and index 2 is their grade in the course. The inability to insert or append items to the tuple means that we are certain that, say, the course name won't move around to a different index.\n",
871 | "\n",
872 | "## 5.2 Unpacking\n",
873 | "\n",
874 | "Tuples' immutability makes them useful for *unpacking*. At its simplest, tuple unpacking allows the following:"
875 | ]
876 | },
877 | {
878 | "cell_type": "code",
879 | "execution_count": 27,
880 | "metadata": {},
881 | "outputs": [
882 | {
883 | "name": "stdout",
884 | "output_type": "stream",
885 | "text": [
886 | "Alice\n",
887 | "Spanish\n",
888 | "A-\n"
889 | ]
890 | }
891 | ],
892 | "source": [
893 | "student_grade = ('Alice', 'Spanish', 'A-')\n",
894 | "student_name, subject, grade = student_grade\n",
895 | "\n",
896 | "print(student_name)\n",
897 | "print(subject)\n",
898 | "print(grade)"
899 | ]
900 | },
901 | {
902 | "cell_type": "markdown",
903 | "metadata": {},
904 | "source": [
905 | "While occasionally useful on its own, tuple unpacking is most useful when used with loops. Consider the following piece of code, which congratulates students on getting good grades:"
906 | ]
907 | },
908 | {
909 | "cell_type": "code",
910 | "execution_count": 28,
911 | "metadata": {},
912 | "outputs": [
913 | {
914 | "name": "stdout",
915 | "output_type": "stream",
916 | "text": [
917 | "Congratulations Alice on getting an A in Spanish\n",
918 | "Congratulations Dave on getting an A- in Italian\n"
919 | ]
920 | }
921 | ],
922 | "source": [
923 | "student_grades = [\n",
924 | " ('Alice', 'Spanish', 'A'),\n",
925 | " ('Bob', 'French', 'C'),\n",
926 | " ('Carol', 'Italian', 'B+'),\n",
927 | " ('Dave', 'Italian', 'A-'),\n",
928 | "]\n",
929 | "\n",
930 | "for student_name, subject, grade in student_grades:\n",
931 | " if grade.startswith('A'):\n",
932 | " print('Congratulations', student_name,\n",
933 | " 'on getting an', grade,\n",
934 | " 'in', subject)"
935 | ]
936 | },
937 | {
938 | "cell_type": "markdown",
939 | "metadata": {},
940 | "source": [
941 | "Compare this to the same code using indices:"
942 | ]
943 | },
944 | {
945 | "cell_type": "code",
946 | "execution_count": 29,
947 | "metadata": {},
948 | "outputs": [
949 | {
950 | "name": "stdout",
951 | "output_type": "stream",
952 | "text": [
953 | "Congratulations Alice on getting an A in Spanish\n",
954 | "Congratulations Dave on getting an A- in Italian\n"
955 | ]
956 | }
957 | ],
958 | "source": [
959 | "for student_grade in student_grades:\n",
960 | " if student_grade[2].startswith('A'):\n",
961 | " print('Congratulations', student_grade[0],\n",
962 | " 'on getting an', student_grade[2],\n",
963 | " 'in', student_grade[1])"
964 | ]
965 | },
966 | {
967 | "cell_type": "markdown",
968 | "metadata": {},
969 | "source": [
970 | "Tuple unpacking allows us to easily refer to this structured data by semantic names instead of having to keep the indices straight. The second example, while functionally identical, is more difficult to write and harder still to read."
971 | ]
972 | },
973 | {
974 | "cell_type": "markdown",
975 | "metadata": {},
976 | "source": [
977 | "# 6. Dictionaries\n",
978 | "\n",
979 | "The next type of collection is much different than the previous two, but is among the most powerful tools in Python: the dictionary ([documentation](https://docs.python.org/3/library/stdtypes.html#dict)). The dictionary is an **unordered**, **mutable**, collection of **unique** items. In other languages these are called maps, mappings, hashmaps, hashes, or associative arrays.\n",
980 | "\n",
981 | "## 6.1 Unordered\n",
982 | "\n",
983 | "By unordered, we mean that dictionary items aren't referred to by their position, or index, in the collection. Instead, dictionary items have *keys*, each of which is associated with a value. Here's a very basic example:"
984 | ]
985 | },
986 | {
987 | "cell_type": "code",
988 | "execution_count": 30,
989 | "metadata": {},
990 | "outputs": [],
991 | "source": [
992 | "foreign_languages = {\n",
993 | " 'Alice': 'Spanish',\n",
994 | " 'Bob': 'French',\n",
995 | " 'Carol': 'Italian',\n",
996 | " 'Dave': 'Italian',\n",
997 | "}"
998 | ]
999 | },
1000 | {
1001 | "cell_type": "markdown",
1002 | "metadata": {},
1003 | "source": [
1004 | "Here the student names are the keys and the students' foreign language courses are the values. So to see Carol's foreign language, we use the key -- her name -- instead of an index:"
1005 | ]
1006 | },
1007 | {
1008 | "cell_type": "code",
1009 | "execution_count": 31,
1010 | "metadata": {},
1011 | "outputs": [
1012 | {
1013 | "data": {
1014 | "text/plain": [
1015 | "'Italian'"
1016 | ]
1017 | },
1018 | "execution_count": 31,
1019 | "metadata": {},
1020 | "output_type": "execute_result"
1021 | }
1022 | ],
1023 | "source": [
1024 | "foreign_languages['Carol']"
1025 | ]
1026 | },
1027 | {
1028 | "cell_type": "markdown",
1029 | "metadata": {},
1030 | "source": [
1031 | "Trying to get the value for a key that does not exist in the dictionary results in a `KeyError`:"
1032 | ]
1033 | },
1034 | {
1035 | "cell_type": "code",
1036 | "execution_count": 32,
1037 | "metadata": {
1038 | "tags": [
1039 | "raises-exception"
1040 | ]
1041 | },
1042 | "outputs": [
1043 | {
1044 | "ename": "KeyError",
1045 | "evalue": "'Zeke'",
1046 | "output_type": "error",
1047 | "traceback": [
1048 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1049 | "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
1050 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mforeign_languages\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Zeke'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
1051 | "\u001b[0;31mKeyError\u001b[0m: 'Zeke'"
1052 | ]
1053 | }
1054 | ],
1055 | "source": [
1056 | "foreign_languages['Zeke']"
1057 | ]
1058 | },
1059 | {
1060 | "cell_type": "markdown",
1061 | "metadata": {},
1062 | "source": [
1063 | "We can check if a particular key is in a dictionary with the `in` keyword:"
1064 | ]
1065 | },
1066 | {
1067 | "cell_type": "code",
1068 | "execution_count": 33,
1069 | "metadata": {},
1070 | "outputs": [
1071 | {
1072 | "data": {
1073 | "text/plain": [
1074 | "False"
1075 | ]
1076 | },
1077 | "execution_count": 33,
1078 | "metadata": {},
1079 | "output_type": "execute_result"
1080 | }
1081 | ],
1082 | "source": [
1083 | "'Zeke' in foreign_languages"
1084 | ]
1085 | },
1086 | {
1087 | "cell_type": "code",
1088 | "execution_count": 34,
1089 | "metadata": {},
1090 | "outputs": [
1091 | {
1092 | "data": {
1093 | "text/plain": [
1094 | "True"
1095 | ]
1096 | },
1097 | "execution_count": 34,
1098 | "metadata": {},
1099 | "output_type": "execute_result"
1100 | }
1101 | ],
1102 | "source": [
1103 | "'Alice' in foreign_languages"
1104 | ]
1105 | },
1106 | {
1107 | "cell_type": "markdown",
1108 | "metadata": {},
1109 | "source": [
1110 | "Note that keys are case-sensitive:"
1111 | ]
1112 | },
1113 | {
1114 | "cell_type": "code",
1115 | "execution_count": 35,
1116 | "metadata": {},
1117 | "outputs": [
1118 | {
1119 | "data": {
1120 | "text/plain": [
1121 | "False"
1122 | ]
1123 | },
1124 | "execution_count": 35,
1125 | "metadata": {},
1126 | "output_type": "execute_result"
1127 | }
1128 | ],
1129 | "source": [
1130 | "'alice' in foreign_languages"
1131 | ]
1132 | },
1133 | {
1134 | "cell_type": "markdown",
1135 | "metadata": {},
1136 | "source": [
1137 | "## 6.2 Mutable\n",
1138 | "\n",
1139 | "We can add, delete, and change entries in a dictionary:"
1140 | ]
1141 | },
1142 | {
1143 | "cell_type": "code",
1144 | "execution_count": 36,
1145 | "metadata": {},
1146 | "outputs": [
1147 | {
1148 | "data": {
1149 | "text/plain": [
1150 | "{'Alice': 'Spanish',\n",
1151 | " 'Bob': 'French',\n",
1152 | " 'Carol': 'Italian',\n",
1153 | " 'Dave': 'Italian',\n",
1154 | " 'Esther': 'French'}"
1155 | ]
1156 | },
1157 | "execution_count": 36,
1158 | "metadata": {},
1159 | "output_type": "execute_result"
1160 | }
1161 | ],
1162 | "source": [
1163 | "# Add an entry that doesn't exist\n",
1164 | "foreign_languages['Esther'] = 'French'\n",
1165 | "foreign_languages"
1166 | ]
1167 | },
1168 | {
1169 | "cell_type": "code",
1170 | "execution_count": 37,
1171 | "metadata": {},
1172 | "outputs": [
1173 | {
1174 | "data": {
1175 | "text/plain": [
1176 | "{'Alice': 'Spanish', 'Carol': 'Italian', 'Dave': 'Italian', 'Esther': 'French'}"
1177 | ]
1178 | },
1179 | "execution_count": 37,
1180 | "metadata": {},
1181 | "output_type": "execute_result"
1182 | }
1183 | ],
1184 | "source": [
1185 | "# Delete an entry that exists\n",
1186 | "del foreign_languages['Bob']\n",
1187 | "foreign_languages"
1188 | ]
1189 | },
1190 | {
1191 | "cell_type": "code",
1192 | "execution_count": 38,
1193 | "metadata": {},
1194 | "outputs": [
1195 | {
1196 | "data": {
1197 | "text/plain": [
1198 | "{'Alice': 'Spanish',\n",
1199 | " 'Carol': 'Italian',\n",
1200 | " 'Dave': 'Italian',\n",
1201 | " 'Esther': 'Italian'}"
1202 | ]
1203 | },
1204 | "execution_count": 38,
1205 | "metadata": {},
1206 | "output_type": "execute_result"
1207 | }
1208 | ],
1209 | "source": [
1210 | "# Change an entry that does exist\n",
1211 | "foreign_languages['Esther'] = 'Italian'\n",
1212 | "foreign_languages"
1213 | ]
1214 | },
1215 | {
1216 | "cell_type": "markdown",
1217 | "metadata": {},
1218 | "source": [
1219 | "## 6.3 Unique\n",
1220 | "Note that the syntax for adding an entry that does not exist and changing an existing entry are the same. When assigning a value to a key in a dictionary, it adds the key if it doesn't exist, or else updates the value for the key if it does exist. As a consequence, keys are necessarily *unique* -- there can't be more than one element with the same key in a dictionary."
1221 | ]
1222 | },
1223 | {
1224 | "cell_type": "markdown",
1225 | "metadata": {},
1226 | "source": [
1227 | "## 6.4 Looping over dictionaries\n",
1228 | "\n",
1229 | "While not performed as often as with lists, it is possible to loop over entries in a dictionary. There are two ways to accomplish this task:"
1230 | ]
1231 | },
1232 | {
1233 | "cell_type": "code",
1234 | "execution_count": 39,
1235 | "metadata": {},
1236 | "outputs": [
1237 | {
1238 | "name": "stdout",
1239 | "output_type": "stream",
1240 | "text": [
1241 | "Alice is taking Spanish\n",
1242 | "Carol is taking Italian\n",
1243 | "Dave is taking Italian\n",
1244 | "Esther is taking Italian\n"
1245 | ]
1246 | }
1247 | ],
1248 | "source": [
1249 | "for key in foreign_languages:\n",
1250 | " value = foreign_languages[key]\n",
1251 | " print(key, 'is taking', value)"
1252 | ]
1253 | },
1254 | {
1255 | "cell_type": "code",
1256 | "execution_count": 40,
1257 | "metadata": {},
1258 | "outputs": [
1259 | {
1260 | "name": "stdout",
1261 | "output_type": "stream",
1262 | "text": [
1263 | "Alice is taking Spanish\n",
1264 | "Carol is taking Italian\n",
1265 | "Dave is taking Italian\n",
1266 | "Esther is taking Italian\n"
1267 | ]
1268 | }
1269 | ],
1270 | "source": [
1271 | "for key, value in foreign_languages.items():\n",
1272 | " print(key, 'is taking', value)"
1273 | ]
1274 | },
1275 | {
1276 | "cell_type": "markdown",
1277 | "metadata": {},
1278 | "source": [
1279 | "Here I'm using variables named `key` and `value` to show the general principle. When you write loops over dictionaries in your own code, you should use descriptive names as opposed to `key` and `value`."
1280 | ]
1281 | },
1282 | {
1283 | "cell_type": "markdown",
1284 | "metadata": {},
1285 | "source": [
1286 | "## 6.5 Dictionaries as records\n",
1287 | "\n",
1288 | "In `foreign_languages` we have paired data -- every name is associated with a subject. Dictionaries are also often used to contain several different data about a single entity. To illustrate this subtle difference, let's take a look at one item from `student_grades`:"
1289 | ]
1290 | },
1291 | {
1292 | "cell_type": "code",
1293 | "execution_count": 41,
1294 | "metadata": {},
1295 | "outputs": [],
1296 | "source": [
1297 | "student_grade = ('Alice', 'Spanish', 'A')"
1298 | ]
1299 | },
1300 | {
1301 | "cell_type": "markdown",
1302 | "metadata": {},
1303 | "source": [
1304 | "Here we know that the items in each of these tuples is a name, subject, and grade:"
1305 | ]
1306 | },
1307 | {
1308 | "cell_type": "code",
1309 | "execution_count": 42,
1310 | "metadata": {},
1311 | "outputs": [
1312 | {
1313 | "name": "stdout",
1314 | "output_type": "stream",
1315 | "text": [
1316 | "Alice got a grade of A in Spanish\n"
1317 | ]
1318 | }
1319 | ],
1320 | "source": [
1321 | "student_name, subject, grade = student_grades[0]\n",
1322 | "print(student_name, 'got a grade of', grade, 'in', subject)"
1323 | ]
1324 | },
1325 | {
1326 | "cell_type": "markdown",
1327 | "metadata": {},
1328 | "source": [
1329 | "We could instead represent this data as a dictionary and use it as such. A dictionary of information describing a single item is often referred to as a *record*:"
1330 | ]
1331 | },
1332 | {
1333 | "cell_type": "code",
1334 | "execution_count": 43,
1335 | "metadata": {},
1336 | "outputs": [
1337 | {
1338 | "name": "stdout",
1339 | "output_type": "stream",
1340 | "text": [
1341 | "Alice got a grade of A in Spanish\n"
1342 | ]
1343 | }
1344 | ],
1345 | "source": [
1346 | "record = {\n",
1347 | " 'name': 'Alice',\n",
1348 | " 'subject': 'Spanish',\n",
1349 | " 'grade': 'A',\n",
1350 | "}\n",
1351 | "print(record['name'],\n",
1352 | " 'got a grade of', record['grade'],\n",
1353 | " 'in', record['subject'])"
1354 | ]
1355 | },
1356 | {
1357 | "cell_type": "markdown",
1358 | "metadata": {},
1359 | "source": [
1360 | "While the code is slightly longer, there is absolutely no ambiguity here about matching up indices and what each value represents. This is also useful in contexts where some of the fields might be optional."
1361 | ]
1362 | },
1363 | {
1364 | "cell_type": "markdown",
1365 | "metadata": {},
1366 | "source": [
1367 | "# 7. Combining Data Types\n",
1368 | "\n",
1369 | "In most of these simple examples we've worked with collections of simple values like strings and numbers, however data analysis often involves working with complex data, where each item of interest has several data associated with it. These complex data are often represented as collections of collections, *e.g.,* lists of dictionaries.\n",
1370 | "\n",
1371 | "Choosing the appropriate data types for a given problem will make it easier for you to write bug-free code and will make your code easier for others to read, but identifying the best data types is a skill gained through experience. Some of the commonly-used combination data types are illustrated below, but this is hardly exhaustive.\n",
1372 | "\n",
1373 | "## 7.1 List of tuples\n",
1374 | "\n",
1375 | "We've actually seen this one before. Consider the `student_grades` data from the earlier example on tuple unpacking:"
1376 | ]
1377 | },
1378 | {
1379 | "cell_type": "code",
1380 | "execution_count": 44,
1381 | "metadata": {},
1382 | "outputs": [],
1383 | "source": [
1384 | "student_grades = [\n",
1385 | " ('Alice', 'Spanish', 'A'),\n",
1386 | " ('Bob', 'French', 'C'),\n",
1387 | " ('Carol', 'Italian', 'B+'),\n",
1388 | " ('Dave', 'Italian', 'A-'),\n",
1389 | "]"
1390 | ]
1391 | },
1392 | {
1393 | "cell_type": "markdown",
1394 | "metadata": {},
1395 | "source": [
1396 | "This is a list of tuples:"
1397 | ]
1398 | },
1399 | {
1400 | "cell_type": "code",
1401 | "execution_count": 45,
1402 | "metadata": {},
1403 | "outputs": [
1404 | {
1405 | "data": {
1406 | "text/plain": [
1407 | "('Bob', 'French', 'C')"
1408 | ]
1409 | },
1410 | "execution_count": 45,
1411 | "metadata": {},
1412 | "output_type": "execute_result"
1413 | }
1414 | ],
1415 | "source": [
1416 | "student_grades[1]"
1417 | ]
1418 | },
1419 | {
1420 | "cell_type": "markdown",
1421 | "metadata": {},
1422 | "source": [
1423 | "and we can work with the individual tuples as such:"
1424 | ]
1425 | },
1426 | {
1427 | "cell_type": "code",
1428 | "execution_count": 46,
1429 | "metadata": {},
1430 | "outputs": [
1431 | {
1432 | "data": {
1433 | "text/plain": [
1434 | "'C'"
1435 | ]
1436 | },
1437 | "execution_count": 46,
1438 | "metadata": {},
1439 | "output_type": "execute_result"
1440 | }
1441 | ],
1442 | "source": [
1443 | "student_grades[1][2]"
1444 | ]
1445 | },
1446 | {
1447 | "cell_type": "markdown",
1448 | "metadata": {},
1449 | "source": [
1450 | "## 7.2 List of dictionaries\n",
1451 | "\n",
1452 | "In the section on dictionaries, we explored how dictionaries are often used to contain several data about a single entity, and each such dictionary is sometimes called a *record*. Let's convert the list of tuples `student_grades` into a list of records `student_grade_records`:"
1453 | ]
1454 | },
1455 | {
1456 | "cell_type": "code",
1457 | "execution_count": 47,
1458 | "metadata": {},
1459 | "outputs": [
1460 | {
1461 | "data": {
1462 | "text/plain": [
1463 | "[{'name': 'Alice', 'subject': 'Spanish', 'grade': 'A'},\n",
1464 | " {'name': 'Bob', 'subject': 'French', 'grade': 'C'},\n",
1465 | " {'name': 'Carol', 'subject': 'Italian', 'grade': 'B+'},\n",
1466 | " {'name': 'Dave', 'subject': 'Italian', 'grade': 'A-'}]"
1467 | ]
1468 | },
1469 | "execution_count": 47,
1470 | "metadata": {},
1471 | "output_type": "execute_result"
1472 | }
1473 | ],
1474 | "source": [
1475 | "student_grade_records = []\n",
1476 | "for student_name, subject, grade in student_grades:\n",
1477 | " record = {\n",
1478 | " 'name': student_name,\n",
1479 | " 'subject': subject,\n",
1480 | " 'grade': grade,\n",
1481 | " }\n",
1482 | " student_grade_records.append(record)\n",
1483 | " \n",
1484 | "student_grade_records"
1485 | ]
1486 | },
1487 | {
1488 | "cell_type": "markdown",
1489 | "metadata": {},
1490 | "source": [
1491 | "Now each item in the list is a dictionary:"
1492 | ]
1493 | },
1494 | {
1495 | "cell_type": "code",
1496 | "execution_count": 48,
1497 | "metadata": {},
1498 | "outputs": [
1499 | {
1500 | "data": {
1501 | "text/plain": [
1502 | "{'name': 'Bob', 'subject': 'French', 'grade': 'C'}"
1503 | ]
1504 | },
1505 | "execution_count": 48,
1506 | "metadata": {},
1507 | "output_type": "execute_result"
1508 | }
1509 | ],
1510 | "source": [
1511 | "student_grade_records[1]"
1512 | ]
1513 | },
1514 | {
1515 | "cell_type": "markdown",
1516 | "metadata": {},
1517 | "source": [
1518 | "and we can work with the individual records as such:"
1519 | ]
1520 | },
1521 | {
1522 | "cell_type": "code",
1523 | "execution_count": 49,
1524 | "metadata": {},
1525 | "outputs": [
1526 | {
1527 | "data": {
1528 | "text/plain": [
1529 | "'C'"
1530 | ]
1531 | },
1532 | "execution_count": 49,
1533 | "metadata": {},
1534 | "output_type": "execute_result"
1535 | }
1536 | ],
1537 | "source": [
1538 | "student_grade_records[1]['grade']"
1539 | ]
1540 | },
1541 | {
1542 | "cell_type": "markdown",
1543 | "metadata": {},
1544 | "source": [
1545 | "This list-of-dicts is often used to represent data from a database or an API. Let's use this data to write our code congratulating students for good grades, as we did in the section on tuple unpacking:"
1546 | ]
1547 | },
1548 | {
1549 | "cell_type": "code",
1550 | "execution_count": 50,
1551 | "metadata": {},
1552 | "outputs": [
1553 | {
1554 | "name": "stdout",
1555 | "output_type": "stream",
1556 | "text": [
1557 | "Congratulations Alice on getting an A in Spanish\n",
1558 | "Congratulations Dave on getting an A- in Italian\n"
1559 | ]
1560 | }
1561 | ],
1562 | "source": [
1563 | "for record in student_grade_records:\n",
1564 | " if record['grade'].startswith('A'):\n",
1565 | " print('Congratulations', record['name'], \n",
1566 | " 'on getting an', record['grade'], \n",
1567 | " 'in', record['subject'])"
1568 | ]
1569 | },
1570 | {
1571 | "cell_type": "markdown",
1572 | "metadata": {},
1573 | "source": [
1574 | "## 7.3 Dictionary of dictionaries\n",
1575 | "\n",
1576 | "The list of dictionaries is very useful when dealing with non-unique data; in the previous example each student might have several grades from different classes. But sometimes we want to refer to the data by a particular name or key. In this case, we can use a dictionary whose values are records, *i.e.*, other dictionaries.\n",
1577 | "\n",
1578 | "Let's use data from `student_grades` again, but assume we just want the foreign language grade so we can use the students name as a key:"
1579 | ]
1580 | },
1581 | {
1582 | "cell_type": "code",
1583 | "execution_count": 51,
1584 | "metadata": {},
1585 | "outputs": [
1586 | {
1587 | "data": {
1588 | "text/plain": [
1589 | "{'Alice': {'subject': 'Spanish', 'grade': 'A'},\n",
1590 | " 'Bob': {'subject': 'French', 'grade': 'C'},\n",
1591 | " 'Carol': {'subject': 'Italian', 'grade': 'B+'},\n",
1592 | " 'Dave': {'subject': 'Italian', 'grade': 'A-'}}"
1593 | ]
1594 | },
1595 | "execution_count": 51,
1596 | "metadata": {},
1597 | "output_type": "execute_result"
1598 | }
1599 | ],
1600 | "source": [
1601 | "foreign_language_grades = {}\n",
1602 | "for student_name, subject, grade in student_grades:\n",
1603 | " record = {\n",
1604 | " 'subject': subject,\n",
1605 | " 'grade': grade,\n",
1606 | " }\n",
1607 | " foreign_language_grades[student_name] = record\n",
1608 | " \n",
1609 | "foreign_language_grades"
1610 | ]
1611 | },
1612 | {
1613 | "cell_type": "markdown",
1614 | "metadata": {},
1615 | "source": [
1616 | "Now we can refer to these by student name:"
1617 | ]
1618 | },
1619 | {
1620 | "cell_type": "code",
1621 | "execution_count": 52,
1622 | "metadata": {},
1623 | "outputs": [
1624 | {
1625 | "data": {
1626 | "text/plain": [
1627 | "{'subject': 'Spanish', 'grade': 'A'}"
1628 | ]
1629 | },
1630 | "execution_count": 52,
1631 | "metadata": {},
1632 | "output_type": "execute_result"
1633 | }
1634 | ],
1635 | "source": [
1636 | "foreign_language_grades['Alice']"
1637 | ]
1638 | },
1639 | {
1640 | "cell_type": "markdown",
1641 | "metadata": {},
1642 | "source": [
1643 | "And we can get the individual data that we care about:"
1644 | ]
1645 | },
1646 | {
1647 | "cell_type": "code",
1648 | "execution_count": 53,
1649 | "metadata": {},
1650 | "outputs": [
1651 | {
1652 | "data": {
1653 | "text/plain": [
1654 | "'A'"
1655 | ]
1656 | },
1657 | "execution_count": 53,
1658 | "metadata": {},
1659 | "output_type": "execute_result"
1660 | }
1661 | ],
1662 | "source": [
1663 | "foreign_language_grades['Alice']['grade']"
1664 | ]
1665 | },
1666 | {
1667 | "cell_type": "markdown",
1668 | "metadata": {},
1669 | "source": [
1670 | "## 7.4 Dictionary with tuple keys\n",
1671 | "\n",
1672 | "It is occasionally useful to key dictionaries on more than one data. Dictionaries can use any immutable object as a key, which includes tuples. Continuing with our student grades example, we may want the keys to be the student name and subject:"
1673 | ]
1674 | },
1675 | {
1676 | "cell_type": "code",
1677 | "execution_count": 54,
1678 | "metadata": {},
1679 | "outputs": [
1680 | {
1681 | "data": {
1682 | "text/plain": [
1683 | "{('Alice', 'Spanish'): 'A',\n",
1684 | " ('Bob', 'French'): 'C',\n",
1685 | " ('Carol', 'Italian'): 'B+',\n",
1686 | " ('Dave', 'Italian'): 'A-'}"
1687 | ]
1688 | },
1689 | "execution_count": 54,
1690 | "metadata": {},
1691 | "output_type": "execute_result"
1692 | }
1693 | ],
1694 | "source": [
1695 | "student_course_grades = {}\n",
1696 | "for student_name, subject, grade in student_grades:\n",
1697 | " student_course_grades[student_name, subject] = grade\n",
1698 | " \n",
1699 | "student_course_grades"
1700 | ]
1701 | },
1702 | {
1703 | "cell_type": "markdown",
1704 | "metadata": {},
1705 | "source": [
1706 | "Now we can represent all of a student's grades:"
1707 | ]
1708 | },
1709 | {
1710 | "cell_type": "code",
1711 | "execution_count": 55,
1712 | "metadata": {},
1713 | "outputs": [],
1714 | "source": [
1715 | "student_course_grades['Alice', 'Math'] = 'A'\n",
1716 | "student_course_grades['Alice', 'History'] = 'B'"
1717 | ]
1718 | },
1719 | {
1720 | "cell_type": "code",
1721 | "execution_count": 56,
1722 | "metadata": {},
1723 | "outputs": [
1724 | {
1725 | "data": {
1726 | "text/plain": [
1727 | "{('Alice', 'Spanish'): 'A',\n",
1728 | " ('Bob', 'French'): 'C',\n",
1729 | " ('Carol', 'Italian'): 'B+',\n",
1730 | " ('Dave', 'Italian'): 'A-',\n",
1731 | " ('Alice', 'Math'): 'A',\n",
1732 | " ('Alice', 'History'): 'B'}"
1733 | ]
1734 | },
1735 | "execution_count": 56,
1736 | "metadata": {},
1737 | "output_type": "execute_result"
1738 | }
1739 | ],
1740 | "source": [
1741 | "student_course_grades"
1742 | ]
1743 | },
1744 | {
1745 | "cell_type": "markdown",
1746 | "metadata": {},
1747 | "source": [
1748 | "## 7.5 Another dictionary of dictionaries\n",
1749 | "\n",
1750 | "Let's take advantage of the fact that, for a particular student, we often want to get subject-grade pairs, *i.e.* a report card. We can create a dictionary with student names as keys and the values being dictionaries of subject-grade pairs. In this case we need to do a bit of checking; that step is commented below:"
1751 | ]
1752 | },
1753 | {
1754 | "cell_type": "code",
1755 | "execution_count": 57,
1756 | "metadata": {},
1757 | "outputs": [],
1758 | "source": [
1759 | "student_report_cards = {}\n",
1760 | "for student_name, subject, grade in student_grades:\n",
1761 | " # If there is no report card for a student,\n",
1762 | " # we need to create a blank one\n",
1763 | " if student_name not in student_report_cards:\n",
1764 | " student_report_cards[student_name] = {}\n",
1765 | " student_report_cards[student_name][subject] = grade"
1766 | ]
1767 | },
1768 | {
1769 | "cell_type": "code",
1770 | "execution_count": 58,
1771 | "metadata": {},
1772 | "outputs": [
1773 | {
1774 | "data": {
1775 | "text/plain": [
1776 | "{'Alice': {'Spanish': 'A'},\n",
1777 | " 'Bob': {'French': 'C'},\n",
1778 | " 'Carol': {'Italian': 'B+'},\n",
1779 | " 'Dave': {'Italian': 'A-'}}"
1780 | ]
1781 | },
1782 | "execution_count": 58,
1783 | "metadata": {},
1784 | "output_type": "execute_result"
1785 | }
1786 | ],
1787 | "source": [
1788 | "student_report_cards"
1789 | ]
1790 | },
1791 | {
1792 | "cell_type": "markdown",
1793 | "metadata": {},
1794 | "source": [
1795 | "The advantage of this extra work is that we can now easily have multiple grades per student:"
1796 | ]
1797 | },
1798 | {
1799 | "cell_type": "code",
1800 | "execution_count": 59,
1801 | "metadata": {},
1802 | "outputs": [],
1803 | "source": [
1804 | "student_report_cards['Alice']['Math'] = 'A'\n",
1805 | "student_report_cards['Alice']['History'] = 'B'"
1806 | ]
1807 | },
1808 | {
1809 | "cell_type": "code",
1810 | "execution_count": 60,
1811 | "metadata": {},
1812 | "outputs": [
1813 | {
1814 | "data": {
1815 | "text/plain": [
1816 | "{'Alice': {'Spanish': 'A', 'Math': 'A', 'History': 'B'},\n",
1817 | " 'Bob': {'French': 'C'},\n",
1818 | " 'Carol': {'Italian': 'B+'},\n",
1819 | " 'Dave': {'Italian': 'A-'}}"
1820 | ]
1821 | },
1822 | "execution_count": 60,
1823 | "metadata": {},
1824 | "output_type": "execute_result"
1825 | }
1826 | ],
1827 | "source": [
1828 | "student_report_cards"
1829 | ]
1830 | },
1831 | {
1832 | "cell_type": "markdown",
1833 | "metadata": {},
1834 | "source": [
1835 | "And we can easily fetch a student's \"report card\":"
1836 | ]
1837 | },
1838 | {
1839 | "cell_type": "code",
1840 | "execution_count": 61,
1841 | "metadata": {},
1842 | "outputs": [
1843 | {
1844 | "data": {
1845 | "text/plain": [
1846 | "{'Spanish': 'A', 'Math': 'A', 'History': 'B'}"
1847 | ]
1848 | },
1849 | "execution_count": 61,
1850 | "metadata": {},
1851 | "output_type": "execute_result"
1852 | }
1853 | ],
1854 | "source": [
1855 | "student_report_cards['Alice']"
1856 | ]
1857 | },
1858 | {
1859 | "cell_type": "code",
1860 | "execution_count": null,
1861 | "metadata": {},
1862 | "outputs": [],
1863 | "source": []
1864 | }
1865 | ],
1866 | "metadata": {
1867 | "kernelspec": {
1868 | "display_name": "Python 3",
1869 | "language": "python",
1870 | "name": "python3"
1871 | },
1872 | "language_info": {
1873 | "codemirror_mode": {
1874 | "name": "ipython",
1875 | "version": 3
1876 | },
1877 | "file_extension": ".py",
1878 | "mimetype": "text/x-python",
1879 | "name": "python",
1880 | "nbconvert_exporter": "python",
1881 | "pygments_lexer": "ipython3",
1882 | "version": "3.6.8"
1883 | }
1884 | },
1885 | "nbformat": 4,
1886 | "nbformat_minor": 2
1887 | }
1888 |
--------------------------------------------------------------------------------
/tutorials/simulation.py:
--------------------------------------------------------------------------------
1 | '''
2 | Simulation class for Chapter 7 Tutorial of Intro Network Science book
3 |
4 | Copyright 2018 Indiana University and Cambridge University Press
5 | '''
6 |
7 | from collections import Counter
8 | from operator import itemgetter
9 |
10 | import matplotlib as mpl
11 | import matplotlib.pyplot as plt
12 | import networkx as nx
13 |
14 |
15 | class StopCondition(StopIteration):
16 | pass
17 |
18 | class Simulation:
19 | '''Simulate state transitions on a network'''
20 |
21 | def __init__(self, G, initial_state, state_transition,
22 | stop_condition=None, name=''):
23 | '''
24 | Create a Simulation instance.
25 |
26 | Args:
27 | G: a networkx.Graph instance.
28 | initial_state: function with signature `initial_state(G)`, that
29 | accepts a single argument, the Graph, and returns a dictionary
30 | of all node states. The keys in this dict should be node names
31 | and the values the corresponding initial node state.
32 | state_transition: function with signature
33 | `state_transition(G, current_state)` that accepts two
34 | arguments, the Graph and a dictionary of current node states,
35 | and returns a dictionary of updated node states. The keys in
36 | this dict should be node names and the values the corresponding
37 | updated node state.
38 | stop_condition (optional): function with signature
39 | `stop_condition(G, current_state)` that accepts two arguments,
40 | the Graph and a dictionary of current node states, and returns
41 | True if the simulation should be stopped at its current state.
42 |
43 | Keyword Args:
44 | name (optional): a string used in titles of plots and drawings.
45 |
46 | Raises:
47 | ValueError: if not all graph nodes have an initial state.
48 | '''
49 | self.G = G.copy()
50 | self._initial_state = initial_state
51 | self._state_transition = state_transition
52 | self._stop_condition = stop_condition
53 | # It's okay to specify stop_condition=False
54 | if stop_condition and not callable(stop_condition):
55 | raise TypeError("'stop_condition' should be a function")
56 | self.name = name or 'Simulation'
57 |
58 | self._states = []
59 | self._value_index = {}
60 | self._cmap = plt.cm.get_cmap('tab10')
61 |
62 | self._initialize()
63 |
64 | self._pos = nx.layout.spring_layout(G)
65 |
66 | def _append_state(self, state):
67 | self._states.append(state)
68 | # Update self._value_index
69 | for value in set(state.values()):
70 | if value not in self._value_index:
71 | self._value_index[value] = len(self._value_index)
72 |
73 | def _initialize(self):
74 | if self._initial_state:
75 | if callable(self._initial_state):
76 | state = self._initial_state(self.G)
77 | else:
78 | state = self._initial_state
79 | nx.set_node_attributes(self.G, state, 'state')
80 |
81 | if any(self.G.nodes[n].get('state') is None for n in self.G.nodes):
82 | raise ValueError('All nodes must have an initial state')
83 |
84 | self._append_state(state)
85 |
86 | def _step(self):
87 | # We're choosing to use the node attributes as the source of truth.
88 | # This allows the user to manually perturb the network in between steps.
89 | state = nx.get_node_attributes(self.G, 'state')
90 | if self._stop_condition and self._stop_condition(self.G, state):
91 | raise StopCondition
92 | state = nx.get_node_attributes(self.G, 'state')
93 | new_state = self._state_transition(self.G, state)
94 | state.update(new_state)
95 | nx.set_node_attributes(self.G, state, 'state')
96 | self._append_state(state)
97 |
98 | def _categorical_color(self, value):
99 | index = self._value_index[value]
100 | node_color = self._cmap(index)
101 | return node_color
102 |
103 | @property
104 | def steps(self):
105 | ''' Returns the number of steps the sumulation has run '''
106 | return len(self._states) - 1
107 |
108 | def state(self, step=-1):
109 | '''
110 | Get a state of the simulation; by default returns the current state.
111 |
112 | Args:
113 | step: the step of the simulation to return. Default is -1, the
114 | current state.
115 |
116 | Returns:
117 | Dictionary of node states.
118 |
119 | Raises:
120 | IndexError: if `step` argument is greater than the number of steps.
121 | '''
122 | try:
123 | return self._states[step]
124 | except IndexError:
125 | raise IndexError('Simulation step %i out of range' % step)
126 |
127 | def draw(self, step=-1, labels=None, **kwargs):
128 | '''
129 | Use networkx.draw to draw a simulation state with nodes colored by
130 | their state value. By default, draws the current state.
131 |
132 | Args:
133 | step: the step of the simulation to draw. Default is -1, the
134 | current state.
135 | kwargs: keyword arguments are passed to networkx.draw()
136 |
137 | Raises:
138 | IndexError: if `step` argument is greater than the number of steps.
139 | '''
140 | state = self.state(step)
141 | node_colors = [self._categorical_color(state[n]) for n in self.G.nodes]
142 | nx.draw(self.G, pos=self._pos, node_color=node_colors, **kwargs)
143 |
144 | if labels is None:
145 | labels = sorted(set(state.values()), key=self._value_index.get)
146 | patches = [mpl.patches.Patch(color=self._categorical_color(l), label=l)
147 | for l in labels]
148 | plt.legend(handles=patches)
149 |
150 | if step == -1:
151 | step = self.steps
152 | if step == 0:
153 | title = 'initial state'
154 | else:
155 | title = 'step %i' % (step)
156 | if self.name:
157 | title = '{}: {}'.format(self.name, title)
158 | plt.title(title)
159 |
160 | def plot(self, min_step=None, max_step=None, labels=None, **kwargs):
161 | '''
162 | Use pyplot to plot the relative number of nodes with each state at each
163 | simulation step. By default, plots all simulation steps.
164 |
165 | Args:
166 | min_step: the first step of the simulation to draw. Default is
167 | None, which plots starting from the initial state.
168 | max_step: the last step, not inclusive, of the simulation to draw.
169 | Default is None, which plots up to the current step.
170 | labels: ordered sequence of state values to plot. Default is all
171 | observed state values, approximately ordered by appearance.
172 | kwargs: keyword arguments are passed along to plt.plot()
173 |
174 | Returns:
175 | Axes object for the current plot
176 | '''
177 | x_range = range(min_step or 0, max_step or len(self._states))
178 | counts = [Counter(s.values()) for s in self._states[min_step:max_step]]
179 | if labels is None:
180 | labels = {k for count in counts for k in count}
181 | labels = sorted(labels, key=self._value_index.get)
182 |
183 | for label in labels:
184 | series = [count.get(label, 0) / sum(count.values()) for count in counts]
185 | plt.plot(x_range, series, label=label, **kwargs)
186 |
187 | title = 'node state proportions'
188 | if self.name:
189 | title = '{}: {}'.format(self.name, title)
190 | plt.title(title)
191 | plt.xlabel('Simulation step')
192 | plt.ylabel('Proportion of nodes')
193 | plt.legend()
194 | plt.xlim(x_range.start)
195 |
196 | return plt.gca()
197 |
198 | def run(self, steps=1):
199 | '''
200 | Run the simulation one or more steps, as specified by the `steps`
201 | argument. Default is to run a single step.
202 |
203 | Args:
204 | steps: number of steps to advance the simulation.
205 | '''
206 | for _ in range(steps):
207 | try:
208 | self._step()
209 | except StopCondition as e:
210 | print(
211 | "Stop condition met at step %i." % self.steps
212 | )
213 | break
214 |
215 |
--------------------------------------------------------------------------------