Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lectures/software_engineering/need_for_speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ f(x) = x > 0.0 ? x : 0.0

Which shows that, when called with an integer, the type could be that integer or the floating point `0.0`.

On the other hand, if we use change the function to return `0` if x <= 0, it is type-unstable with floating point.
On the other hand, if we use change the function to return `0` if `x <= 0`, it is type-unstable with floating point.

```{code-cell} julia
f(x) = x > 0.0 ? x : 0
Expand All @@ -281,8 +281,6 @@ f(x) = x > 0.0 ? x : 0

The solution is to use the `zero(x)` function which returns the additive identity element of type `x`.

On the other hand, if we change the function to return `0` if `x <= 0`, it is type-unstable with floating point.

```{code-cell} julia
@show zero(2.3)
@show zero(4)
Expand Down
2 changes: 1 addition & 1 deletion lectures/tools_and_techniques/geom_series.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ D_i = (1 - r)^i D_0 \ \text{ for } i \geq 0
```

Equation {eq}`geomseries` expresses $D_i$ as the $i$ th term in the
product of $D_0$ and the geometric series
product of $D_0$ and the geometric sequence

$$
1, (1-r), (1-r)^2, \cdots
Expand Down
4 changes: 0 additions & 4 deletions lectures/tools_and_techniques/lln_clt.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ As expected, the distribution smooths out into a bell curve as $n$ increases.

We leave you to investigate its contents if you wish to know more.

If you run the file from the ordinary Julia or IJulia shell, the figure should pop up in a
window that you can rotate with your mouse, giving different views on the
density sequence.

(multivariate_clt)=
### The Multivariate Case

Expand Down
37 changes: 13 additions & 24 deletions lectures/tools_and_techniques/stationary_densities.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ kernelspec:

## Overview

In a {doc}`previous lecture <../introduction_dynamics/finite_markov>` we learned about finite Markov chains, a relatively elementary class of stochastic dynamic models.
In this lecture, we will study the case of continuous (i.e., uncountable) state Markov chains.

The present lecture extends this analysis to continuous (i.e., uncountable) state Markov chains.
A {doc}`previous lecture <../introduction_dynamics/finite_markov>` will cover finite Markov chains, a relatively elementary class of stochastic dynamic models.

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.

Expand All @@ -54,8 +54,7 @@ In particular,
* Is there a notion of "steady state" or "long run equilibrium" that's applicable to the model?
* If so, how can we compute it?

Answering these questions will lead us to revisit many of the topics that occupied us in the finite state case,
such as simulation, distribution dynamics, stability, ergodicity, etc.
Answering these questions will lead us to explore topics such as simulation, distribution dynamics, stability, and ergodicity.

```{note}
For some people, the term "Markov chain" always refers to a process with a
Expand Down Expand Up @@ -89,9 +88,7 @@ Once we've built some intuition we'll cover the general case.

### Definitions and Basic Properties

In our {doc}`lecture on finite Markov chains <../introduction_dynamics/finite_markov>`, we studied discrete time Markov chains that evolve on a finite state space $S$.

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.
We can start by considering a finite state space $S$. 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.

The interpretation of $P$ is that $P[i, j]$ represents the
probability of transitioning from state $i$ to state $j$ in one
Expand Down Expand Up @@ -271,16 +268,15 @@ $\sigma(x) = s f(x)$ is strictly positive for all $s$ as required)

### Distribution Dynamics

In {ref}`this section <mc_md>` of our lecture on **finite** Markov chains, we
asked the following question: If
Later in {ref}`another section <mc_md>` of our lecture on **finite** Markov chains, we
will explore the following question: If

1. $\{X_t\}$ is a Markov chain with stochastic matrix $P$
1. the distribution of $X_t$ is known to be $\psi_t$

then what is the distribution of $X_{t+1}$?

Letting $\psi_{t+1}$ denote the distribution of $X_{t+1}$, the
answer {ref}`we gave <mc_fdd>` was that
Letting $\psi_{t+1}$ denote the distribution of $X_{t+1}$, we will show that

$$
\psi_{t+1}[j] = \sum_{i \in S} P[i,j] \psi_t[i]
Expand Down Expand Up @@ -526,7 +522,7 @@ Notice that the sequence of densities shown in the figure seems to be
converging --- more on this in just a moment.

Another quick comment is that each of these distributions could be interpreted
as a cross sectional distribution (recall {ref}`this discussion <mc_eg1-1>`).
as a cross sectional distribution (see {ref}`this discussion <mc_eg1-1>`).

## Beyond Densities

Expand Down Expand Up @@ -606,17 +602,12 @@ One good option is simulation as before, combined with the [empirical distributi

## Stability

In our {doc}`lecture <../introduction_dynamics/finite_markov>` on finite Markov chains we also studied stationarity, stability and ergodicity.

Here we will cover the same topics for the continuous case.
In this section, we will explore three concepts: stationarity, stability, and ergodicity. Our focus will be specifically on the density case (as in {ref}`this section <statd_density_case>`), where the stochastic kernel is a family of densities. The general case is relatively similar --- references are given below.

We will, however, treat only the density case (as in {ref}`this section <statd_density_case>`), where the stochastic kernel is a family of densities.

The general case is relatively similar --- references are given below.

### Theoretical Results

Analogous to {ref}`the finite case <mc_stat_dd>`, given a stochastic kernel $p$ and corresponding Markov operator as
Given a stochastic kernel $p$ and corresponding Markov operator as
defined in {eq}`def_dmo`, a density $\psi^*$ on $S$ is called
*stationary* for $P$ if it is a fixed point of the operator $P$.

Expand All @@ -635,7 +626,7 @@ the distribution of $X_0$ is $\psi^*$, then, in view of

Hence $\psi^*$ is the stochastic equivalent of a steady state.

In the finite case, we learned that at least one stationary distribution exists, although there may be many.
In the finite case, we will learn that at least one stationary distribution exists, although there may be many.

When the state space is infinite, the situation is more complicated.

Expand Down Expand Up @@ -1000,7 +991,7 @@ T = 40 # Compute density of k_t at 1,...,T+1
xmax = 6.5
ygrid = range(0.01, xmax, length = 150)
laes_plot = zeros(length(ygrid), 4T)
colors = []
colors = zeros(RGBA,1,4*T);
for i in 1:4
k = zeros(n, T)
A = rand!(phi, zeros(n, T))
Expand All @@ -1018,13 +1009,11 @@ for i in 1:4
for j in 1:T
psi = laes[j]
laes_plot[:, ind] = lae_est(psi, ygrid)
colors[ind]=RGBA(0, 0, 0, 1 - (j - 1) / T)
ind = ind + 4
push!(colors, RGBA(0, 0, 0, 1 - (j - 1) / T))
end
end

#colors = reshape(reshape(colors, T, 4)', 4*T, 1)
colors = reshape(colors, 1, length(colors))
plot(ygrid, laes_plot, layout = (2, 2), color = colors,
legend = :none, xlabel = "capital", xlims = (0, xmax))
```
Expand Down