@@ -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
4149Previously in {doc}` intro:ar1_processes ` , we learned about linear scalar-valued stochastic processes (AR(1) models).
@@ -60,15 +68,6 @@ import quantecon as qe
6068import 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-
7271Additional technical background related to this lecture can be found in the
7372monograph 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)?
502501The empirical findings are that
503502
5045031 . 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
507506Also, Gibrat's law is generally found to be a reasonable approximation for
508507large 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
729728generate_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
734744def 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