Skip to content

Commit

Permalink
deploy: da95c81
Browse files Browse the repository at this point in the history
  • Loading branch information
jstac committed Jun 9, 2023
1 parent 3a84277 commit 65a0459
Show file tree
Hide file tree
Showing 26 changed files with 7,979 additions and 7,963 deletions.
2 changes: 1 addition & 1 deletion _images/ch_intro_11_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_intro_46_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_mcs_18_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_mcs_32_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_mcs_44_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_opt_10_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_opt_16_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_opt_julia_5_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_production_17_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_production_26_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_production_30_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_production_36_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/ch_production_48_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion _sources/ch_fpms.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kernelspec:
---
tags: [hide-output]
---
pip install --upgrade quantecon_book_networks
! pip install --upgrade quantecon_book_networks
```

We begin with some imports
Expand Down
20 changes: 9 additions & 11 deletions _sources/ch_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kernelspec:
---
tags: [hide-output]
---
pip install --upgrade quantecon_book_networks kaleido
! pip install --upgrade quantecon_book_networks kaleido
```

We begin by importing the `quantecon` package as well as some functions and data that have been packaged for release with this text.
Expand All @@ -31,7 +31,8 @@ import quantecon_book_networks.input_output as qbn_io
import quantecon_book_networks.data as qbn_data
import quantecon_book_networks.plotting as qbn_plot
ch1_data = qbn_data.introduction()
export_figures = False
default_figsize = [6, 4]
export_figures = True
```

Next we import some common python libraries.
Expand Down Expand Up @@ -315,7 +316,7 @@ def Ge(x):
We then plot our distribution on a log-log scale.

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
ax.plot(np.log(x), np.log(Gp(x)), label="Pareto")
ax.plot(np.log(x), np.log(Ge(x)), label="Exponential")
Expand Down Expand Up @@ -360,7 +361,7 @@ b, a = results.params
Finally we produce our plot.

```{code-cell} ipython3
fig, ax = plt.subplots(figsize=(6.4, 3.5))
fig, ax = plt.subplots(figsize=[7.3,4])
ax.scatter(x, y, alpha=0.3, label="firm size (market value)")
ax.plot(x, x * a + b, 'k-', alpha=0.6, label=f"slope = ${a: 1.2f}$")
Expand Down Expand Up @@ -402,7 +403,7 @@ x_grid = np.linspace(1, 10, 200)
Then we can produce our plot

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
ax.plot(k_grid, z(k_grid), '-o', label='zeta distribution with $\gamma=2$')
ax.plot(x_grid, p(x_grid), label='density of Pareto with tail index $\\alpha$')
ax.legend(fontsize=12)
Expand Down Expand Up @@ -466,11 +467,8 @@ G.add_edge(3, 2)
list(nx.strongly_connected_components(G))
```

Like `NetworkX`, the QuantEcon Python library `quantecon` supplies a graph
object that implements certain graph-theoretic algorithms.

The set of available algorithms is more limited but each one is faster, accelerated by
just-in-time compilation.
Like `NetworkX`, the Python library `quantecon`
provides access to some graph-theoretic algorithms.

In the case of QuantEcon's `DiGraph` object, an instance is created via the adjacency matrix.

Expand Down Expand Up @@ -683,7 +681,7 @@ def plot_degree_dist(G, ax, loglog=True, label=None):
```

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
plot_degree_dist(DG, ax, loglog=False, label='degree distribution')
Expand Down
33 changes: 22 additions & 11 deletions _sources/ch_mcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kernelspec:
---
tags: [hide-output]
---
pip install --upgrade quantecon_book_networks
! pip install --upgrade quantecon_book_networks
```

We begin with some imports.
Expand All @@ -31,7 +31,7 @@ import quantecon_book_networks.input_output as qbn_io
import quantecon_book_networks.plotting as qbn_plt
import quantecon_book_networks.data as qbn_data
ch4_data = qbn_data.markov_chains_and_networks()
export_figures = False
export_figures = True
```

```{code-cell} ipython3
Expand Down Expand Up @@ -68,7 +68,7 @@ P_Q = [
[0, 0, 0, 0.01, 0.99]
]
P_Q = np.array(P_Q)
codes_Q = ( '1','2','3','4','5')
codes_Q = ('1', '2', '3', '4', '5')
```

Second, [Benhabib et al. (2015)](https://www.economicdynamics.org/meetpapers/2015/paper_364.pdf) estimate the following transition matrix for intergenerational social mobility.
Expand All @@ -90,7 +90,7 @@ P_B = [
]
P_B = np.array(P_B)
codes_B = ( '1','2','3','4','5','6','7','8')
codes_B = ('1', '2', '3', '4', '5', '6', '7', '8')
```


Expand Down Expand Up @@ -176,17 +176,21 @@ minimum initial value and one at the maximum.
def sim_fig(ax, mc, T=100, seed=14, title=None):
X1 = mc.simulate(T, init=1, random_state=seed)
X2 = mc.simulate(T, init=max(mc.state_values), random_state=seed+1)
ax.plot(X1, label="low initial state")
ax.plot(X2, label="high initial state")
ax.plot(X1)
ax.plot(X2)
ax.set_xlabel("time")
ax.set_ylabel("state")
ax.set_title(title, fontsize=12)
```

Finally, we produce the figure.

```{code-cell}
fig, axes = plt.subplots(2, 1)
fig, axes = plt.subplots(2, 1, figsize=(6, 4))
ax = axes[0]
sim_fig(axes[0], mc_B, title="$P_B$")
sim_fig(axes[1], mc_Q, title="$P_Q$")
axes[1].set_yticks((1, 2, 3, 4, 5))
plt.tight_layout()
if export_figures:
Expand Down Expand Up @@ -256,12 +260,19 @@ Now, calculate the true 2019 distribution.
Finally we produce the plot.

```{code-cell}
states = np.arange(1, 6)
states = np.arange(0, 5)
ticks = range(5)
codes_S = ('1', '2', '3', '4', '5')
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(6, 4))
width = 0.4
ax.plot(states, ψ_2019_predicted, '-o', alpha=0.7, label='predicted')
ax.plot(states, ψ_2019, '-o', alpha=0.7, label='realized')
ax.set_xlabel("state")
ax.set_ylabel("probability")
ax.set_yticks((0.15, 0.2, 0.25, 0.3))
ax.set_xticks(ticks)
ax.set_xticklabels(codes_S)
ax.legend(loc='upper center', fontsize=12)
if export_figures:
Expand Down Expand Up @@ -364,6 +375,7 @@ def transition(P, n, ax=None):
ax.set(ylim=(0, 0.25),
xticks=((1, nstates)))
ax.set_title(f"t = {n}")
ax.set_xlabel("Quantile")
return ax
```
Expand All @@ -372,12 +384,11 @@ We now generate the marginal distributions after 0, 1, 2, and 100 iterations for

```{code-cell}
ns = (0, 1, 2, 100)
fig, axes = plt.subplots(1, len(ns))
fig, axes = plt.subplots(1, len(ns), figsize=(6, 4))
for n, ax in zip(ns, axes):
ax = transition(P_B, n, ax=ax)
axes[-1].set_xlabel("Quantile")
plt.tight_layout()
if export_figures:
Expand Down
10 changes: 5 additions & 5 deletions _sources/ch_opt.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kernelspec:
---
tags: [hide-output]
---
pip install --upgrade quantecon_book_networks
! pip install --upgrade quantecon_book_networks
```

We begin with some imports
Expand All @@ -31,7 +31,7 @@ import quantecon_book_networks.input_output as qbn_io
import quantecon_book_networks.plotting as qbn_plt
import quantecon_book_networks.data as qbn_data
ch3_data = qbn_data.optimal_flows()
export_figures = False
export_figures = True
```

```{code-cell}
Expand Down Expand Up @@ -64,7 +64,7 @@ bc_dict = nx.betweenness_centrality(G)
And we produce the plot.

```{code-cell}
fig, ax = plt.subplots(figsize=(10, 10))
fig, ax = plt.subplots(figsize=(9.4, 9.4))
plt.axis("off")
nx.draw_networkx(
Expand Down Expand Up @@ -111,8 +111,8 @@ plt.rcParams['font.size'] = '14'
ax.plot(np.linspace(-1, 17.5, 100), 6-0.4*np.linspace(-1, 17.5, 100))
ax.plot(np.linspace(-1, 5.5, 100), 10-2*np.linspace(-1, 5.5, 100))
ax.text(1.5, 8, "$2q_1 + 5q_2 \leq 30$")
ax.text(10, 2.5, "$4q_1 + 2q_2 \leq 20$")
ax.text(10, 2.5, "$2q_1 + 5q_2 \leq 30$")
ax.text(1.5, 8, "$4q_1 + 2q_2 \leq 20$")
ax.text(-2, 2, "$q_2 \geq 0$")
ax.text(2.5, -0.7, "$q_1 \geq 0$")
Expand Down
6 changes: 4 additions & 2 deletions _sources/ch_opt_julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ $T^2_q$, $T^3_q$ and plot them. By $T^3_q$ has already converged on $q^∗$.

```{code-cell}
using PyPlot
export_figures = false
fig, ax = plt.subplots()
export_figures = true
fig, ax = plt.subplots(figsize=[6, 4])
n = 7
q = zeros(n)
ax.plot(1:n, q)
ax.set_xlabel("cost-to-go")
ax.set_ylabel("nodes")
for i in 1:3
new_q = T(q)
Expand Down
34 changes: 21 additions & 13 deletions _sources/ch_production.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kernelspec:
---
tags: [hide-output]
---
pip install --upgrade quantecon_book_networks
! pip install --upgrade quantecon_book_networks
```

We begin with some imports.
Expand All @@ -31,7 +31,8 @@ import quantecon_book_networks.input_output as qbn_io
import quantecon_book_networks.plotting as qbn_plt
import quantecon_book_networks.data as qbn_data
ch2_data = qbn_data.production()
export_figures = False
default_figsize = [6, 4]
export_figures = True
```

```{code-cell} ipython3
Expand Down Expand Up @@ -104,9 +105,10 @@ fig, ax = plt.subplots(figsize=(8, 10))
plt.axis("off")
color_list = qbn_io.colorise_weights(centrality, beta=False)
# Remove self-loops
for i in range(A.shape[0]):
A[i][i] = 0
qbn_plt.plot_graph(A, X, ax, codes,
A1 = A.copy()
for i in range(A1.shape[0]):
A1[i][i] = 0
qbn_plt.plot_graph(A1, X, ax, codes,
layout_type='spring',
layout_seed=5432167,
tol=0.0,
Expand All @@ -122,7 +124,7 @@ plt.show()
Now we plot a bar chart of hub-based eigenvector centrality by sector.

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
ax.bar(codes, centrality, color=color_list, alpha=0.6)
ax.set_ylabel("eigenvector centrality", fontsize=12)
if export_figures:
Expand All @@ -143,7 +145,7 @@ omult = qbn_io.katz_centrality(A, authority=True)
```

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
omult_color_list = qbn_io.colorise_weights(omult,beta=False)
ax.bar(codes, omult, color=omult_color_list, alpha=0.6)
ax.set_ylabel("Output multipliers", fontsize=12)
Expand Down Expand Up @@ -188,7 +190,7 @@ plt.show()
Here we produce a barplot of upstreamness.

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
ax.bar(codes, upstreamness, color=upstreamness_color_list, alpha=0.6)
ax.set_ylabel("upstreamness", fontsize=12)
if export_figures:
Expand All @@ -205,7 +207,7 @@ kcentral = qbn_io.katz_centrality(A)
```

```{code-cell} ipython3
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=default_figsize)
kcentral_color_list = qbn_io.colorise_weights(kcentral,beta=False)
ax.bar(codes, kcentral, color=kcentral_color_list, alpha=0.6)
ax.set_ylabel("Katz hub centrality", fontsize=12)
Expand Down Expand Up @@ -264,11 +266,12 @@ d[6] = 1 # positive shock to agriculture
Now we simulate the demand shock propagating through the economy.

```{code-cell} ipython3
sim_length = 6
sim_length = 11
x = d
x_vecs = []
for i in range(sim_length):
x_vecs.append(x)
if i % 2 ==0:
x_vecs.append(x)
x = A @ x
```

Expand All @@ -279,8 +282,13 @@ fig, axes = plt.subplots(3, 2, figsize=(8, 10))
axes = axes.flatten()
for ax, x_vec, i in zip(axes, x_vecs, range(sim_length)):
ax.set_title(f"round {i}")
if i % 2 != 0:
pass
ax.set_title(f"round {i*2}")
x_vec_cols = qbn_io.colorise_weights(x_vec,beta=False)
# remove self-loops
for i in range(len(A)):
A[i][i] = 0
qbn_plt.plot_graph(A, X, ax, codes,
layout_type='spring',
layout_seed=342156,
Expand Down Expand Up @@ -356,7 +364,7 @@ color_list_114 = qbn_io.colorise_weights(centrality_114,beta=False)
Finally we produce the plot.

```{code-cell} ipython3
fig, ax = plt.subplots(figsize=(10, 12))
fig, ax = plt.subplots(figsize=(11, 13.2))
plt.axis("off")
# Remove self-loops
for i in range(A_114.shape[0]):
Expand Down
27 changes: 13 additions & 14 deletions ch_fpms.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,40 +222,39 @@
<h1>Chapter 5 - Nonlinear Interactions (Python Code)<a class="headerlink" href="#chapter-5-nonlinear-interactions-python-code" title="Permalink to this headline"></a></h1>
<div class="cell tag_hide-output docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="o">--</span><span class="n">upgrade</span> <span class="n">quantecon_book_networks</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="o">!</span> pip install --upgrade quantecon_book_networks
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: quantecon_book_networks in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (0.5.1)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: numpy in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.22.4)
Requirement already satisfied: scipy in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.7.1)
Requirement already satisfied: networkx in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (2.6.3)
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: networkx in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (2.6.3)
Requirement already satisfied: pandas in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.3.4)
Requirement already satisfied: matplotlib in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (3.4.3)
Requirement already satisfied: scipy in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.7.1)
Requirement already satisfied: numpy in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.22.4)
Requirement already satisfied: pandas-datareader in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (0.10.0)
Requirement already satisfied: pandas in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from quantecon_book_networks) (1.3.4)
Requirement already satisfied: pillow&gt;=6.2.0 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (8.4.0)
Requirement already satisfied: python-dateutil&gt;=2.7 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (2.8.2)
Requirement already satisfied: pyparsing&gt;=2.2.1 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (3.0.4)
Requirement already satisfied: cycler&gt;=0.10 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (0.10.0)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: pyparsing&gt;=2.2.1 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (3.0.4)
Requirement already satisfied: kiwisolver&gt;=1.0.1 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from matplotlib-&gt;quantecon_book_networks) (1.3.1)
Requirement already satisfied: six in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from cycler&gt;=0.10-&gt;matplotlib-&gt;quantecon_book_networks) (1.16.0)
Requirement already satisfied: pytz&gt;=2017.3 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-&gt;quantecon_book_networks) (2021.3)
Requirement already satisfied: requests&gt;=2.19.0 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-datareader-&gt;quantecon_book_networks) (2.26.0)
Requirement already satisfied: lxml in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-datareader-&gt;quantecon_book_networks) (4.6.3)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: pytz&gt;=2017.3 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-&gt;quantecon_book_networks) (2021.3)
Requirement already satisfied: lxml in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-datareader-&gt;quantecon_book_networks) (4.6.3)
Requirement already satisfied: requests&gt;=2.19.0 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from pandas-datareader-&gt;quantecon_book_networks) (2.26.0)
Requirement already satisfied: certifi&gt;=2017.4.17 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (2021.10.8)
Requirement already satisfied: urllib3&lt;1.27,&gt;=1.21.1 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (1.26.7)
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Requirement already satisfied: urllib3&lt;1.27,&gt;=1.21.1 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (1.26.7)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (2.0.4)
Requirement already satisfied: certifi&gt;=2017.4.17 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (2021.10.8)
Requirement already satisfied: idna&lt;4,&gt;=2.5 in /usr/share/miniconda3/envs/networks/lib/python3.8/site-packages (from requests&gt;=2.19.0-&gt;pandas-datareader-&gt;quantecon_book_networks) (3.2)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Note: you may need to restart the kernel to use updated packages.
</pre></div>
</div>
</div>
</div>
<p>We begin with some imports</p>
Expand Down
Loading

0 comments on commit 65a0459

Please sign in to comment.