Skip to content

Commit cd4d521

Browse files
committed
apply suggestions
1 parent 5b0ce92 commit cd4d521

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lectures/kesten_processes.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ In addition to what's in Anaconda, this lecture will need the following librarie
3636
!pip install --upgrade quantecon yfinance
3737
```
3838

39+
Later in the exercise, we will use JAX to optimize our code
40+
41+
```{code-cell} ipython3
42+
:tags: [no-execute]
43+
44+
!pip install --upgrade jax
45+
```
46+
3947
## Overview
4048

4149
Previously in {doc}`intro:ar1_processes`, we learned about linear scalar-valued stochastic processes (AR(1) models).
@@ -60,15 +68,6 @@ import quantecon as qe
6068
import yfinance as yf
6169
```
6270

63-
The following two lines are only added to avoid a `FutureWarning` caused by
64-
compatibility issues between pandas and matplotlib.
65-
66-
```{code-cell} ipython3
67-
from pandas.plotting import register_matplotlib_converters
68-
69-
register_matplotlib_converters()
70-
```
71-
7271
Additional technical background related to this lecture can be found in the
7372
monograph by {cite}`buraczewski2016stochastic`.
7473

@@ -344,7 +343,7 @@ def kesten_ts(ts_length=100):
344343
for t in range(ts_length - 1):
345344
a = np.exp(μ + σ * np.random.randn())
346345
b = np.exp(np.random.randn())
347-
x[t + 1] = a * x[t] + b
346+
x[t+1] = a * x[t] + b
348347
return x
349348
350349
@@ -502,7 +501,7 @@ In what sense is this true (or false)?
502501
The empirical findings are that
503502

504503
1. small firms grow faster than large firms and
505-
1. the growth rate of small firms is more volatile than that of large firms.
504+
2. the growth rate of small firms is more volatile than that of large firms.
506505

507506
Also, Gibrat's law is generally found to be a reasonable approximation for
508507
large firms than for small firms
@@ -729,6 +728,17 @@ def generate_single_draw(key, μ_a, σ_a, μ_b, σ_b, μ_e, σ_e, s_bar, T, s_in
729728
generate_single_draw = jax.jit(generate_single_draw, static_argnums=(8,))
730729
```
731730

731+
```{code-cell} ipython3
732+
# Use vmap to vectorize over the first argument (key)
733+
in_axes = [None] * 10
734+
in_axes[0] = 0
735+
736+
vectorized_single_draw = vmap(
737+
generate_single_draw,
738+
in_axes=in_axes,
739+
)
740+
```
741+
732742
```{code-cell} ipython3
733743
@jit
734744
def generate_draws(
@@ -752,12 +762,6 @@ def generate_draws(
752762
# Create M different random keys for parallel execution
753763
keys = random.split(key, M)
754764
755-
# Use vmap to parallelize over the M dimension
756-
vectorized_single_draw = vmap(
757-
generate_single_draw,
758-
in_axes=(0, None, None, None, None, None, None, None, None, None),
759-
)
760-
761765
draws = vectorized_single_draw(
762766
keys, μ_a, σ_a, μ_b, σ_b, μ_e, σ_e, s_bar, T, s_init
763767
)

0 commit comments

Comments
 (0)