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
[calvo_ml] Updates on Visualizations and Regressions (#170)
* Adding a new regression v_t on theta and theta^2
* Tom's Aug 4 edits of Calvo_machine_learning lecture
* update graph for v_t and regression data
* use V^R to distinguish with the criterion V
* Tom's Aug 5 edits of calvo_machine_learning lecture
* update graph with V^CR
* Tom's second Aug 5 edits of calvo_machine_learning lecture
---------
Co-authored-by: Thomas Sargent <thomassargent@pop-os.localdomain>
Copy file name to clipboardExpand all lines: lectures/calvo_machine_learn.md
+222-35
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ kernelspec:
15
15
16
16
## Introduction
17
17
18
-
This lecture studies a problem that we also study in another quantecon lecture
18
+
This lecture studies a problem that we shall study from another angle in another quantecon lecture
19
19
{doc}`calvo`.
20
20
21
21
That lecture used an analytic approach based on ``dynamic programming squared`` to guide computation of a Ramsey plan in a version of a model of Calvo {cite}`Calvo1978`.
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.
710
711
711
-
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$.
712
720
713
721
We'll apply this approach here and compare answers with what we obtained above with the gradient descent approach.
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.
1011
1020
1012
1021
Our hope is that these regressions will reveal structure hidden within the $\vec \mu^R, \vec \theta^R$ sequences associated with a Ramsey plan.
1013
1022
1014
-
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.
1015
1024
1016
-
Artificial intelligence (AI a.k.a. ML) is running the regressions.
1025
+
Artificial intelligence, i.e., some Python code and a computer, is running the regressions for us.
1017
1026
1018
-
But you can regress anything on anything else.
1027
+
But we are free to regress anything on anything else.
1019
1028
1020
-
Human intelligence tell us which regressions to run.
1029
+
Human intelligence tells us what regressions to run.
1021
1030
1022
-
Even more human intelligence is required fully to appreciate what they reveal about the structure of the Ramsey plan.
1031
+
Additional inputs of human intelligence will be required fully to appreciate what those regressions reveal about the structure of a Ramsey plan.
1023
1032
1024
1033
```{note}
1025
-
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
1026
1035
$\theta_t$ as his key state variable.
1027
1036
```
1028
1037
1029
1038
1030
1039
We'll begin by simply plotting the Ramsey plan's $\mu_t$ and $\theta_t$ for $t =0, \ldots, T$ against $t$ in a graph with $t$ on the ordinate axis.
1031
1040
1032
-
These are the data that we'll be running some linear least squares regressions on.
1033
-
1041
+
These are the data that we'll be running some linear least squares regressions on.
1034
1042
1035
1043
```{code-cell} ipython3
1036
1044
# Compute θ using optimized_μ
@@ -1040,23 +1048,23 @@ These are the data that we'll be running some linear least squares regressions o
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$
Figure {numref}`continuation_values` shows several striking patterns:
1237
+
1238
+
* The sequence of continuation values $\{v_t\}_{t=0}^T$ is monotonically decreasing
1239
+
* Evidently, $v_0 > V^{CR} > v_T$ so that
1240
+
* 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$.
1241
+
* 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$
1242
+
1243
+
1244
+
```{note}
1245
+
The continuation value $v_T$ is what some researchers call the "value of a Ramsey plan under a
1246
+
time-less perspective." A more descriptive phrase is "the value of the worst continuation Ramsey plan."
1247
+
```
1248
+
1249
+
1250
+
Next we ask Python to regress $v_t$ against a constant, $\theta_t$, and $\theta_t^2$.
1251
+
1252
+
$$
1253
+
v_t = g_0 + g_1 \theta_t + g_2 \theta_t^2 .
1254
+
$$
1255
+
1256
+
```{code-cell} ipython3
1257
+
# Third regression: v_t on a constant, θ_t and θ^2_t
1258
+
X3_θ = np.column_stack((np.ones(T), θs, θs**2))
1259
+
model3 = sm.OLS(v_t, X3_θ)
1260
+
results3 = model3.fit()
1261
+
1262
+
1263
+
# Print regression summary
1264
+
print("\nRegression of v_t on a constant, θ_t and θ^2_t:")
1265
+
print(results3.summary(slim=True))
1266
+
```
1267
+
1268
+
The regression has an $R^2$ equal to $1$ and so fits perfectly.
1269
+
1270
+
However, notice the warning about the high condition number.
1271
+
1272
+
As indicated in the printout, this is a consequence of
1273
+
$\theta_t$ and $\theta_t^2$ being highly correlated along the Ramsey plan.
1274
+
1275
+
```{code-cell} ipython3
1276
+
np.corrcoef(θs, θs**2)
1277
+
```
1278
+
1279
+
Let's plot $v_t$ against $\theta_t$ along with the nonlinear regression line.
The highest continuation value $v_0$ at $t=0$ appears at the peak of the function quadratic function
1302
+
$g_0 + g_1 \theta_t + g_2 \theta_t^2$.
1303
+
1304
+
1305
+
Subsequent values of $v_t$ for $t \geq 1$ appear to the lower left of the pair $(\theta_0, v_0)$ and converge monotonically from above to $v_T$ at time $T$.
1306
+
1307
+
The value $V^{CR}$ attained by the Ramsey plan that is restricted to be a constant $\mu_t = \mu^{CR}$ sequence appears as a horizontal line.
1308
+
1309
+
Evidently, continuation values $v_t > V^{CR}$ for $t=0, 1, 2$ while $v_t < V^{CR}$ for $t \geq 3$.
1310
+
1311
+
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
## What has Machine Learning Taught Us?
1140
1318
1141
1319
1142
1320
Our regressions tells us that along the Ramsey outcome $\vec \mu^R, \vec \theta^R$, the linear function
@@ -1145,10 +1323,14 @@ $$
1145
1323
\mu_t = .0645 + 1.5995 \theta_t
1146
1324
$$
1147
1325
1148
-
fits perfectly and that so does the regression line
1326
+
fits perfectly and that so do the regression lines
@@ -1170,12 +1352,18 @@ that along a Ramsey plan, the following relationships prevail:
1170
1352
1171
1353
where the initial value $\theta_0^R$ was computed along with other components of $\vec \mu^R, \vec \theta^R$ when we computed the Ramsey plan, and where $b_0, b_1, d_0, d_1$ are parameters whose values we estimated with our regressions.
1172
1354
1355
+
In addition, we learned that continuation values are described by the quadratic function
1356
+
1357
+
$$
1358
+
v_t = g_0 + g_1 \theta_t + g_2 \theta_t^2
1359
+
$$
1360
+
1173
1361
1174
-
We discovered this representation by running some carefully chosen regressions and staring at the results, noticing that the $R^2$ of unity tell us that the fits are perfect.
1362
+
We discovered these relationships by running some carefully chosen regressions and staring at the results, noticing that the $R^2$'s of unity tell us that the fits are perfect.
1175
1363
1176
1364
We have learned something about the structure of the Ramsey problem.
1177
1365
1178
-
But it is challenging to say more just by using the methods and ideas that we have deployed in this lecture.
1366
+
However, it is challenging to say more just by using the methods and ideas that we have deployed in this lecture.
1179
1367
1180
1368
There are many other linear regressions among components of $\vec \mu^R, \theta^R$ that would also have given us perfect fits.
1181
1369
@@ -1187,7 +1375,7 @@ After all, the Ramsey planner chooses $\vec \mu$, while $\vec \theta$ is an o
1187
1375
1188
1376
Isn't it more natural then to expect that we'd learn more about the structure of the Ramsey problem from a regression of components of $\vec \theta$ on components of $\vec \mu$?
1189
1377
1190
-
To answer such questions, we'll have to deploy more economic theory.
1378
+
To answer these questions, we'll have to deploy more economic theory.
1191
1379
1192
1380
We do that in this quantecon lecture {doc}`calvo`.
1193
1381
@@ -1204,7 +1392,6 @@ and the parameters $d_0, d_1$ in the updating rule for $\theta_{t+1}$ in represe
1204
1392
1205
1393
First, we'll again use ``ChangLQ`` to compute these objects (along with a number of others).
0 commit comments