You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[stationary_densities] Fix typos and align with style manual (#331)
* [stationary_densities] Fix typos and minor code issues
- Fix "for all s" -> "for all x" in state space remark
- Correct off-by-one comment on density dates (1,...,T)
- Remove stray trailing comma in boxplot data display
- "discrete-time" -> "discrete time" (noun usage)
- Add missing period after Markov operator definition
- Initialize X[0] in exercise 1 solution (was uninitialized np.empty)
- Boxplot titles: label initial condition as X_0, not t
- Comments: B ~ N(0, a_σ**2) since a_σ is the std dev
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [stationary_densities] Align lecture with QuantEcon style manual
- Links: use intersphinx {doc} links for finite_markov references,
normalize outdated python-intro.quantecon.org domain, auto-title
link for arma
- Citation: use {cite:t} for in-sentence Hopenhayn-Rogerson reference
- Definitions: bold (not italic) for stochastic kernel, Markov
operator, look-ahead, stationary, global stability, ergodicity
- Math: square brackets for expectation, \mathrm{LN} for lognormal,
"CDFs" capitalization
- Figures: replace ax.set_title with mystnb caption on the main
example, caption the static stability figure, drop unneeded
figsize settings, format ex-3 panel titles to one decimal
- RNG: migrate to np.random.default_rng Generator API; seed scipy
.rvs calls via random_state for reproducibility
Verified by executing the full lecture via jupytext --to py and
inspecting all five generated figures.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* FIX: disambiguate arma cross-reference to fix build
The auto-title link `[](arma)` was ambiguous: MyST found both a doc
target (Covariance Stationary Processes) and an equation labelled
`arma`, raising myst.xref_ambiguous. With warnings treated as errors
the book build failed. Use the explicit `{doc}` role to resolve to the
document while keeping the auto-generated title.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Matt McKay <mmcky@users.noreply.github.com>
Copy file name to clipboardExpand all lines: lectures/stationary_densities.md
+50-38Lines changed: 50 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,20 +34,20 @@ tags: [hide-output]
34
34
35
35
## Overview
36
36
37
-
In a [previous lecture](https://python-intro.quantecon.org/finite_markov.html), we learned about finite Markov chains, a relatively elementary class of stochastic dynamic models.
37
+
In {doc}`intermediate:finite_markov`, we learned about finite Markov chains, a relatively elementary class of stochastic dynamic models.
38
38
39
39
The present lecture extends this analysis to continuous (i.e., uncountable) state Markov chains.
40
40
41
41
Most stochastic dynamic models studied by economists either fit directly into this class or can be represented as continuous state Markov chains after minor modifications.
42
42
43
43
In this lecture, our focus will be on continuous Markov models that
44
44
45
-
* evolve in discrete-time
45
+
* evolve in discretetime
46
46
* are often nonlinear
47
47
48
48
The fact that we accommodate nonlinear models here is significant, because
49
49
linear stochastic models have their own highly developed toolset, as we'll
50
-
see {doc}`later on <arma>`.
50
+
see later in {doc}`arma`.
51
51
52
52
The question that interests us most is: Given a particular stochastic dynamic
53
53
model, how will the state of the system evolve over time?
@@ -96,7 +96,7 @@ Once we've built some intuition we'll cover the general case.
96
96
97
97
### Definitions and basic properties
98
98
99
-
In our [lecture on finite Markov chains](https://python-intro.quantecon.org/finite_markov.html), we studied discrete-time Markov chains that evolve on a finite state space $S$.
99
+
In our lecture {doc}`intermediate:finite_markov`, we studied discrete-time Markov chains that evolve on a finite state space $S$.
100
100
101
101
In this setting, the dynamics of the model are described by a stochastic matrix --- a nonnegative square matrix $P = P[i, j]$ such that each row $P[i, \cdot]$ sums to one.
102
102
@@ -127,7 +127,7 @@ The family of discrete distributions $P[i, \cdot]$ will be replaced by a family
127
127
128
128
Analogous to the finite state case, $p(x, \cdot)$ is to be understood as the distribution (density) of $X_{t+1}$ given $X_t = x$.
129
129
130
-
More formally, a *stochastic kernel on* $S$ is a function $p \colon S \times S \to \mathbb R$ with the property that
130
+
More formally, a **stochastic kernel on** $S$ is a function $p \colon S \times S \to \mathbb R$ with the property that
131
131
132
132
1. $p(x, y) \geq 0$ for all $x, y \in S$
133
133
1. $\int p(x, y) dy = 1$ for all $x \in S$
@@ -274,7 +274,7 @@ p(x, y)
274
274
where $\phi$ is the density of $A_{t+1}$.
275
275
276
276
(Regarding the state space $S$ for this model, a natural choice is $(0, \infty)$ --- in which case
277
-
$\sigma(x) = s f(x)$ is strictly positive for all $s$ as required)
277
+
$\sigma(x) = s f(x)$ is strictly positive for all $x$ as required)
278
278
279
279
### Distribution dynamics
280
280
@@ -322,7 +322,7 @@ defined by
322
322
(\psi P)(y) = \int p(x,y) \psi(x) dx
323
323
```
324
324
325
-
This operator is usually called the *Markov operator* corresponding to $p$
325
+
This operator is usually called the **Markov operator** corresponding to $p$.
326
326
327
327
```{note}
328
328
Unlike most operators, we write $P$ to the right of its argument,
@@ -368,7 +368,7 @@ $y$.
368
368
369
369
Another possibility is to discretize the model, but this introduces errors of unknown size.
370
370
371
-
A nicer alternative in the present setting is to combine simulation with an elegant estimator called the *look-ahead* estimator.
371
+
A nicer alternative in the present setting is to combine simulation with an elegant estimator called the **look-ahead** estimator.
372
372
373
373
Let's go over the ideas with reference to the growth model {ref}`discussed above <solow_swan>`, the dynamics of which we repeat here for convenience:
374
374
@@ -412,12 +412,12 @@ where $p$ is the growth model stochastic kernel in {eq}`statd_sssk`.
412
412
413
413
What is the justification for this slightly surprising estimator?
414
414
415
-
The idea is that, by the strong [law of large numbers](https://python-intro.quantecon.org/lln_clt.html#lln-ksl),
415
+
The idea is that, by the strong [law of large numbers](https://python.quantecon.org/lln_clt.html#lln-ksl),
416
416
417
417
$$
418
418
\frac{1}{n} \sum_{i=1}^n p(k_{t-1}^i, y)
419
419
\to
420
-
\mathbb E p(k_{t-1}^i, y)
420
+
\mathbb E \left[ p(k_{t-1}^i, y) \right]
421
421
= \int p(x, y) \psi_{t-1}(x) \, dx
422
422
= \psi_t(y)
423
423
$$
@@ -462,13 +462,20 @@ The following code is an example of usage for the stochastic growth model {ref}`
462
462
463
463
(stoch_growth)=
464
464
```{code-cell} python3
465
+
---
466
+
mystnb:
467
+
figure:
468
+
caption: Density of $k_1$ (lighter) to $k_T$ (darker)
469
+
name: fig-statd-density-sequence
470
+
---
465
471
# == Define parameters == #
466
472
s = 0.2
467
473
δ = 0.1
468
-
a_σ = 0.4 # A = exp(B) where B ~ N(0, a_σ)
474
+
a_σ = 0.4 # A = exp(B) where B ~ N(0, a_σ**2)
469
475
α = 0.4 # We set f(k) = k**α
470
476
ψ_0 = beta(5, 5, scale=0.5) # Initial distribution
471
477
ϕ = lognorm(a_σ)
478
+
rng = np.random.default_rng(1234)
472
479
473
480
474
481
def p(x, y):
@@ -480,12 +487,12 @@ def p(x, y):
480
487
return ϕ.pdf((y - (1 - δ) * x) / d) / d
481
488
482
489
n = 10000 # Number of observations at each date t
483
-
T = 30 # Compute density of k_t at 1,...,T+1
490
+
T = 30 # Compute density of k_t at 1,...,T
484
491
485
492
# == Generate matrix s.t. t-th column is n observations of k_t == #
486
493
k = np.empty((n, T))
487
-
A = ϕ.rvs((n, T))
488
-
k[:, 0] = ψ_0.rvs(n) # Draw first column from initial distribution
494
+
A = ϕ.rvs((n, T), random_state=rng)
495
+
k[:, 0] = ψ_0.rvs(n, random_state=rng) # Draw first column from initial distribution
ax.set_title(f'Density of $k_1$ (lighter) to $k_T$ (darker) for $T={T}$')
504
510
plt.show()
505
511
```
506
512
@@ -531,7 +537,7 @@ We can, however, construct a fairly general theory using distribution functions.
531
537
532
538
### Example and definitions
533
539
534
-
To illustrate the issues, recall that Hopenhayn and Rogerson {cite}`HopenhaynRogerson1993` study a model of firm dynamics where individual firm productivity follows the exogenous process
540
+
To illustrate the issues, recall that {cite:t}`HopenhaynRogerson1993` study a model of firm dynamics where individual firm productivity follows the exogenous process
535
541
536
542
$$
537
543
X_{t+1} = a + \rho X_t + \xi_{t+1},
@@ -557,7 +563,7 @@ puts positive probability mass on 0 and 1.
557
563
558
564
Hence it cannot be represented as a density.
559
565
560
-
What we can do instead is use cumulative distribution functions (cdfs).
566
+
What we can do instead is use cumulative distribution functions (CDFs).
561
567
562
568
To this end, set
563
569
@@ -566,7 +572,7 @@ G(x, y) := \mathbb P \{ h(a + \rho x + \xi_{t+1}) \leq y \}
566
572
\qquad (0 \leq x, y \leq 1)
567
573
$$
568
574
569
-
This family of cdfs $G(x, \cdot)$ plays a role analogous to the stochastic kernel in the density case.
575
+
This family of CDFs $G(x, \cdot)$ plays a role analogous to the stochastic kernel in the density case.
570
576
571
577
The distribution dynamics in {eq}`statd_fdd` are then replaced by
572
578
@@ -576,13 +582,13 @@ The distribution dynamics in {eq}`statd_fdd` are then replaced by
576
582
F_{t+1}(y) = \int G(x,y) F_t(dx)
577
583
```
578
584
579
-
Here $F_t$ and $F_{t+1}$ are cdfs representing the distribution of the current state and next period state.
585
+
Here $F_t$ and $F_{t+1}$ are CDFs representing the distribution of the current state and next period state.
580
586
581
587
The intuition behind {eq}`statd_fddc` is essentially the same as for {eq}`statd_fdd`.
582
588
583
589
### Computation
584
590
585
-
If you wish to compute these cdfs, you cannot use the look-ahead estimator as before.
591
+
If you wish to compute these CDFs, you cannot use the look-ahead estimator as before.
586
592
587
593
Indeed, you should not use any density estimator, since the objects you are
588
594
estimating/computing are not densities.
@@ -591,7 +597,7 @@ One good option is simulation as before, combined with the [empirical distributi
591
597
592
598
## Stability
593
599
594
-
In our [lecture](https://python-intro.quantecon.org/finite_markov.html) on finite Markov chains, we also studied stationarity, stability and ergodicity.
600
+
In our lecture {doc}`intermediate:finite_markov`, we also studied stationarity, stability and ergodicity.
595
601
596
602
Here we will cover the same topics for the continuous case.
597
603
@@ -603,7 +609,7 @@ The general case is relatively similar --- references are given below.
603
609
604
610
Analogous to [the finite case](https://python.quantecon.org/finite_markov.html#stationary-distributions), given a stochastic kernel $p$ and corresponding Markov operator as
605
611
defined in {eq}`def_dmo`, a density $\psi^*$ on $S$ is called
606
-
*stationary* for $P$ if it is a fixed point of the operator $P$.
612
+
**stationary** for $P$ if it is a fixed point of the operator $P$.
607
613
608
614
In other words,
609
615
@@ -640,9 +646,9 @@ With additional conditions, we can also get a unique stationary density ($\psi \
640
646
```
641
647
642
648
This combination of existence, uniqueness and global convergence in the sense
643
-
of {eq}`statd_dca` is often referred to as *global stability*.
649
+
of {eq}`statd_dca` is often referred to as **global stability**.
644
650
645
-
Under very similar conditions, we get *ergodicity*, which means that
651
+
Under very similar conditions, we get **ergodicity**, which means that
0 commit comments