Skip to content

Commit 92f5a84

Browse files
AllenDowneyclaude
andcommitted
Fix typos and small errors reported in issues and pull requests
Applied by hand rather than merged, because most of the PRs edit files that have moved (code/ is now soln/ and notebooks/) or the generated LaTeX. Thanks to everyone who reported these. book/book.tex: - #71, #50 (@alexalekseyenko): the WS graphs in Figure 3.2 have n=10, not n=20 (caption and text) - #48 (@reflectionalist): list(G.nodes()) returns a list, not a NodeView - #52 (@alexalekseyenko): "there are are" - #46 (@mark-summerfield): "larger numbers of interactions" - #45 (@ahmedhindi): "an edge" (the prob_connected fix was already in) - #47 (@link2xt): "repository", "exercises" - path_lengths: nx.shortest_path_length returns an iterator in NetworkX 2, so wrap it in dict() #38 (@gwtaylor): the loop version of the Game of Life skipped the cells on the edges of the array, so its output did not match the cross-correlation version. It now visits every cell and clips the neighborhood at the edges, which matches correlate2d exactly (book text, soln/chap06 and notebooks/chap06; soln/chap06 re-executed). #47 (@link2xt), notebooks: "initial" (chap09), "lengths" (fof_model), "achieved" (nkmodel), "source" (sspile). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4d40581 commit 92f5a84

8 files changed

Lines changed: 436 additions & 179 deletions

File tree

‎book/book.tex‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
\usepackage{amsmath}
4141
\usepackage{amsthm}
4242

43-
% format end of chapter excercises
43+
% format end of chapter exercises
4444
\newtheoremstyle{exercise}
4545
{12pt} % space above
4646
{12pt} % space below
@@ -785,7 +785,7 @@ \section{The axes of scientific models}
785785
\item[One, two \myrightarrow~many] Classical models are often limited to
786786
small numbers of components. For example, in celestial mechanics the
787787
two-body problem can be solved analytically; the three-body problem
788-
cannot. Complexity science often works with large numbers of components and larger number of interactions.
788+
cannot. Complexity science often works with large numbers of components and larger numbers of interactions.
789789

790790
\index{one, two, many}
791791

@@ -1206,7 +1206,7 @@ \section{NetworkX}
12061206

12071207
\begin{code}
12081208
>>> list(G.nodes())
1209-
NodeView(('Alice', 'Bob', 'Chuck'))
1209+
['Alice', 'Bob', 'Chuck']
12101210
\end{code}
12111211

12121212
The \py{nodes} method returns a \py{NodeView}, which can be used in a for loop or, as in this example, used to make a list.
@@ -2125,7 +2125,7 @@ \section{WS graphs}
21252125

21262126
\begin{figure}
21272127
\centerline{\includegraphics[width=3.5in]{figs/chap03-2.pdf}}
2128-
\caption{WS graphs with $n=20$, $k=4$, and $p=0$ (left), $p=0.2$ (middle),
2128+
\caption{WS graphs with $n=10$, $k=4$, and $p=0$ (left), $p=0.2$ (middle),
21292129
and $p=1$ (right).}
21302130
\label{chap03-2}
21312131
\end{figure}
@@ -2135,7 +2135,7 @@ \section{WS graphs}
21352135
consider the edges in a particular order and rewire each one with
21362136
probability $p$. If an edge is rewired, they leave the first node
21372137
unchanged and choose the second node at random. They don't allow self
2138-
loops or multiple edges; that is, you can't have a edge from a node to
2138+
loops or multiple edges; that is, you can't have an edge from a node to
21392139
itself, and you can't have more than one edge between the same two
21402140
nodes.
21412141

@@ -2188,7 +2188,7 @@ \section{WS graphs}
21882188
by Watts and Strogatz, but that doesn't seem to affect
21892189
the results.
21902190

2191-
Figure~\ref{chap03-2} shows WS graphs with $n=20$, $k=4$, and
2191+
Figure~\ref{chap03-2} shows WS graphs with $n=10$, $k=4$, and
21922192
a range of values of $p$. When $p=0$, the graph is a ring lattice.
21932193
When $p=1$, it is completely random. As we'll see, the interesting
21942194
things happen in between.
@@ -2294,7 +2294,7 @@ \section{Shortest path lengths}
22942294

22952295
\begin{code}
22962296
def path_lengths(G):
2297-
length_map = nx.shortest_path_length(G)
2297+
length_map = dict(nx.shortest_path_length(G))
22982298
lengths = [length_map[u][v] for u, v in all_pairs(G)]
22992299
return lengths
23002300
\end{code}
@@ -2853,7 +2853,7 @@ \section{Exercises}
28532853

28542854
Of course, one option is to run Dijkstra's algorithm $n$ times,
28552855
once for each starting node. And for some applications, that's
2856-
probably good enough. But there are are more efficient alternatives.
2856+
probably good enough. But there are more efficient alternatives.
28572857

28582858
Find an algorithm for the all-pairs shortest path problem and
28592859
implement it. See
@@ -2890,7 +2890,7 @@ \chapter{Scale-free networks}
28902890
The chapter ends with a discussion of WS and BA graphs as explanatory
28912891
models for small world networks.
28922892

2893-
The code for this chapter is in {\tt chap04.ipynb} in the respository
2893+
The code for this chapter is in {\tt chap04.ipynb} in the repository
28942894
for this book. More information about working with the code is
28952895
in Section~\ref{code}.
28962896

@@ -5197,10 +5197,10 @@ \section{Implementing Life}
51975197
\begin{code}
51985198
b = np.zeros_like(a)
51995199
rows, cols = a.shape
5200-
for i in range(1, rows-1):
5201-
for j in range(1, cols-1):
5200+
for i in range(rows):
5201+
for j in range(cols):
52025202
state = a[i, j]
5203-
neighbors = a[i-1:i+2, j-1:j+2]
5203+
neighbors = a[max(i-1, 0):i+2, max(j-1, 0):j+2]
52045204
k = np.sum(neighbors) - state
52055205
if state:
52065206
if k==2 or k==3:
@@ -5212,7 +5212,8 @@ \section{Implementing Life}
52125212

52135213
Initially, \py{b} is an array of zeros with the same size as \py{a}.
52145214
Each time through the loop, \py{state} is the condition of the center
5215-
cell and \py{neighbors} is the 3x3 neighborhood. \py{k} is the number
5215+
cell and \py{neighbors} is the 3x3 neighborhood (smaller at the edges
5216+
of the array, where some neighbors are missing). \py{k} is the number
52165217
of live neighbors (not including the center cell). The nested \py{if}
52175218
statements evaluate the GoL rules and turn on cells in \py{b}
52185219
accordingly.

‎examples/fof_model.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"\n",
5959
"I propose a new model that generates graphs with\n",
6060
"\n",
61-
"1. Low path lenths,\n",
61+
"1. Low path lengths,\n",
6262
"2. Clustering coefficients similar to the HK model (but still lower than observed values), and\n",
6363
"3. A degree distribution that fits observed data well.\n",
6464
"\n",

‎examples/sspile.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"from scipy.ndimage import imread\n",
199199
"\n",
200200
"def read_pile(k):\n",
201-
" \"\"\"Reads an image of a single souce sand pile model.\n",
201+
" \"\"\"Reads an image of a single source sand pile model.\n",
202202
" \n",
203203
" Images generated by Wesley Pegden,\n",
204204
" available from http://math.cmu.edu/~wes/piles/\n",

‎notebooks/chap06.ipynb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,10 @@
447447
"source": [
448448
"b = np.zeros_like(a)\n",
449449
"rows, cols = a.shape\n",
450-
"for i in range(1, rows-1):\n",
451-
" for j in range(1, cols-1):\n",
450+
"for i in range(rows):\n",
451+
" for j in range(cols):\n",
452452
" state = a[i, j]\n",
453-
" neighbors = a[i-1:i+2, j-1:j+2]\n",
453+
" neighbors = a[max(i-1, 0):i+2, max(j-1, 0):j+2]\n",
454454
" k = np.sum(neighbors) - state\n",
455455
" if state:\n",
456456
" if k==2 or k==3:\n",

‎notebooks/nkmodel.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@
13361336
" \n",
13371337
" returns: Cdf of component (neutral network) sizes,\n",
13381338
" float fraction of locations in a common network,\n",
1339-
" float maximum fitness acheived by the agents\n",
1339+
" float maximum fitness achieved by the agents\n",
13401340
" \"\"\"\n",
13411341
" nkqland = NKqLandscape(N, K, F=F)\n",
13421342
" \n",

0 commit comments

Comments
 (0)