Skip to content

Commit 1849a47

Browse files
author
Thomas Sargent
committed
Tom's Aug 5 edits of calvo_machine_learning lecture
1 parent ba4cf4c commit 1849a47

File tree

1 file changed

+58
-27
lines changed

1 file changed

+58
-27
lines changed

lectures/calvo_machine_learn.md

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,14 @@ compute_V(jnp.array([clq.μ_CR]), β=0.85, c=2)
709709
710710
By thinking a little harder about the mathematical structure of the Ramsey problem and using some linear algebra, we can simplify the problem that we hand over to a ``machine learning`` algorithm.
711711
712-
The idea here is that the Ramsey problem that chooses $\vec \mu$ to maximize the government's value function {eq}`eq:Ramseyvalue`subject to equation {eq}`eq:inflation101` is actually a quadratic optimum problem whose solution is characterized by a set of simultaneous linear equations in $\vec \mu$.
712+
We start by recalling that the Ramsey problem that chooses $\vec \mu$ to maximize the government's value function {eq}`eq:Ramseyvalue`subject to equation {eq}`eq:inflation101`.
713+
714+
This is actually an optimization problem with a quadratic objective function and linear constraints.
715+
716+
First-order conditions for this problem are a set of simultaneous linear equations in $\vec \mu$.
717+
718+
If we trust that the second-order conditions for a maximum are also satisfied (they are in our problem),
719+
we can compute the Ramsey plan by solving these equations for $\vec \mu$.
713720
714721
We'll apply this approach here and compare answers with what we obtained above with the gradient descent approach.
715722
@@ -1007,24 +1014,24 @@ closed_grad
10071014
print(f'deviation = {np.linalg.norm(closed_grad - (- grad_J(jnp.ones(T))))}')
10081015
```
10091016
1010-
## Some Regressions
1017+
## Some Exploratory Regressions
10111018
10121019
To help us learn about the structure of the Ramsey plan, we shall compute some least squares linear regressions of particular components of $\vec \theta$ and $\vec \mu$ on others.
10131020
10141021
Our hope is that these regressions will reveal structure hidden within the $\vec \mu^R, \vec \theta^R$ sequences associated with a Ramsey plan.
10151022
1016-
It is worth pausing here to think about roles played by **human** intelligence and **artificial** intelligence here.
1023+
It is worth pausing here to think about roles being played by **human** intelligence and **artificial** intelligence.
10171024
1018-
Artificial intelligence, in this case meaning a computer, is running the regressions for us.
1025+
Artificial intelligence, i.e., some Python code and a computer, is running the regressions for us.
10191026
10201027
But we are free to regress anything on anything else.
10211028
1022-
Human intelligence tells us which regressions to run.
1029+
Human intelligence tells us what regressions to run.
10231030
10241031
Additional inputs of human intelligence will be required fully to appreciate what those regressions reveal about the structure of a Ramsey plan.
10251032
10261033
```{note}
1027-
At this point, it is worthwhile to read how Chang {cite}`chang1998credible` chose
1034+
When we eventually get around to trying to understand the regressions below, it will worthwhile to study the reasoning that let Chang {cite}`chang1998credible` to choose
10281035
$\theta_t$ as his key state variable.
10291036
```
10301037
@@ -1049,15 +1056,15 @@ plt.show()
10491056
```
10501057
10511058
We notice that $\theta_t$ is less than $\mu_t$for low $t$'s but that it eventually converges to
1052-
the same limit that $\mu_t$ does.
1059+
the same limit $\bar \mu$ that $\mu_t$ does.
10531060
1054-
This pattern reflects how formula {eq}`eq_grad_old3` for low $t$'s makes $\theta_t$ makes a weighted average of future $\mu_t$'s.
1061+
This pattern reflects how formula {eq}`eq_grad_old3` makes $\theta_t$ be a weighted average of future $\mu_t$'s.
10551062
10561063
We begin by regressing $\mu_t$ on a constant and $\theta_t$.
10571064
1058-
This might seem strange because, first of all, equation {eq}`eq_grad_old3` asserts that inflation at time $t$ is determined $\{\mu_s\}_{s=t}^\infty$
1065+
This might seem strange because, after all, equation {eq}`eq_grad_old3` asserts that inflation at time $t$ is determined $\{\mu_s\}_{s=t}^\infty$
10591066
1060-
Nevertheless, we'll run this regression anyway and provide a justification later.
1067+
Nevertheless, we'll run this regression anyway.
10611068
10621069
```{code-cell} ipython3
10631070
# First regression: μ_t on a constant and θ_t
@@ -1078,7 +1085,12 @@ $$
10781085
10791086
fits perfectly.
10801087
1081-
Let's plot this function and the points $(\theta_t, \mu_t)$ that lie on it for $t=0, \ldots, T$.
1088+
1089+
```{note}
1090+
Of course, this means that a regression of $\theta_t$ on $\mu_t$ and a constant would also fit perfectly.
1091+
```
1092+
1093+
Let's plot the regression line $\mu_t = .0645 + 1.5995 \theta_t$ and the points $(\theta_t, \mu_t)$ that lie on it for $t=0, \ldots, T$.
10821094
10831095
```{code-cell} ipython3
10841096
plt.scatter(θs, μs, label=r'$\mu_t$')
@@ -1089,10 +1101,9 @@ plt.legend()
10891101
plt.show()
10901102
```
10911103
1092-
The time $0$ pair $\theta_0, \mu_0$ appears as the point on the upper right.
1104+
The time $0$ pair $(\theta_0, \mu_0)$ appears as the point on the upper right.
10931105
1094-
Points for succeeding times appear further and further to the lower left and eventually converge to
1095-
$\bar \mu, \bar \mu$.
1106+
Points $(\theta_t, \mu_t)$ for succeeding times appear further and further to the lower left and eventually converge to $(\bar \mu, \bar \mu)$.
10961107
10971108
10981109
Next, we'll run a linear regression of $\theta_{t+1}$ against $\theta_t$.
@@ -1136,6 +1147,8 @@ plt.show()
11361147
Points for succeeding times appear further and further to the lower left and eventually converge to
11371148
$\bar \mu, \bar \mu$.
11381149
1150+
### Continuation Values
1151+
11391152
Next, we'll compute a sequence $\{v_t\}_{t=0}^T$ of what we'll call "continuation values" along a Ramsey plan.
11401153
11411154
To do so, we'll start at date $T$ and compute
@@ -1185,26 +1198,22 @@ v_t = compute_vt(μs, β=0.85, c=2)
11851198
The initial continuation value $v_0$ should equals the optimized value of the Ramsey planner's criterion $V$ defined
11861199
in equation {eq}`eq:RamseyV`.
11871200
1188-
**Note to Humphrey**
1189-
1190-
Let's add a line of code to check this equality.
1191-
1192-
I printed out the sequence and it looks good. But I suspect you will want to clean up
1193-
that line where I printed out the sequence.
1194-
1195-
Also, please add a graph of $v_t$ against $t$ for $t=0, \ldots, T$.
11961201
1197-
**End of note to Humphrey**
1198-
1199-
Indeed, we find that the deviation is very small
1202+
Indeed, we find that the deviation is very small:
12001203
12011204
```{code-cell} ipython3
12021205
print(f'deviation = {np.linalg.norm(v_t[0] - V_R)}')
12031206
```
12041207
1205-
We can also verify this by inspecting a graph of $v_t$ against $t$ for $t=0, \ldots, T$ along with the value attained by a restricted Ramsey planner $V^{CR}$ and the optimized value of the ordinary Ramsey planner $V^R$
1208+
We can also verify approximate equality by inspecting a graph of $v_t$ against $t$ for $t=0, \ldots, T$ along with the value attained by a restricted Ramsey planner $V^{CR}$ and the optimized value of the ordinary Ramsey planner $V^R$
12061209
12071210
```{code-cell} ipython3
1211+
---
1212+
mystnb:
1213+
figure:
1214+
caption: "Continuation values"
1215+
name: continuation_values
1216+
---
12081217
plt.scatter(Ts, v_t, label='$v_t$')
12091218
plt.axhline(V_R, color='C2', linestyle='--', label='$V^R$')
12101219
plt.axhline(V_CR, color='C1', linestyle='--', label='$V^{CR}$')
@@ -1216,6 +1225,20 @@ plt.tight_layout()
12161225
plt.show()
12171226
```
12181227
1228+
Figure {numref}`continuation_values` shows several striking patterns:
1229+
1230+
* The sequence of continuation values $\{v_t\}_{t=0}^T$ is monotonically decreasing
1231+
* Evidently, $v_0 > V^{CR} > v_T$ so that
1232+
* the value $v_0$ of the ordinary Ramsey plan exceeds the value $V^{CR}$ of the special Ramsey plan in which the planner is constrained to set $\mu_t = \mu^{CR}$ for all $t$.
1233+
* the continuation value $v_T$ of the ordinary Ramsey plan for $t \geq T$ is constant and is less than the value $V^{CR}$ of the special Ramsey plan in which the planner is constrained to set $\mu_t = \mu^{CR}$ for all $t$
1234+
1235+
1236+
```{note}
1237+
The continuation value $v_T$ is what some researchers call the "value of a Ramsey plan under a
1238+
time-less perspective." A more descriptive phrase is "the value of the worst continuation Ramsey plan."
1239+
```
1240+
1241+
12191242
Next we ask Python to regress $v_t$ against a constant, $\theta_t$, and $\theta_t^2$.
12201243
12211244
$$
@@ -1266,10 +1289,18 @@ The highest continuation value $v_0$ at $t=0$ appears at the peak of the graph.
12661289
12671290
Subsequent values of $v_t$ for $t \geq 1$ appear to the left and converge monotonically from above to $v_T$ at time $T$.
12681291
1292+
**Aug 5 Request for Humphrey**
1293+
1294+
Please add a horizontal line labeled $V^{CR}$ to the above graph.
1295+
It will make it even more of a killer graph!
1296+
Thanks.
1297+
1298+
**End of Request for Humphrey**
1299+
12691300
12701301
12711302
1272-
## What has machine learning taught us?
1303+
## What has Machine Learning Taught Us?
12731304
12741305
12751306
Our regressions tells us that along the Ramsey outcome $\vec \mu^R, \vec \theta^R$, the linear function

0 commit comments

Comments
 (0)