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
Browse filesBrowse the repository at this point in the historyBrowse files
authored
[mccall_q] Fix typos, heading case and figure legend (#624)
* update import block
* convert mccall model from numba to jax
* complete jax conversion of q-learning implementation
* fix headings and subheadings to match style guide
* rectify grammatical errors in the lecture
* fix legend and place it below graph
earlier the legend overlapped on the curves, making it difficult to interpret the graph. this version fixes it
* update jupytext version
* use seed equals 0 as default
* use vectorized computation
vectorized computation instead of repeatedly
resetting arrays with for loops
* replace eps (epsilon) with the unicode character
* remove unnecessary comment
* put default values of variables into the class
* shorten code length to have each line under 80 characters
* follow copilot's suggestion to prevent division by 0
* shorten lengthy notes
* replace loop with jax.vmap for vectorized value update
* make PRNG key explicit in plot_epochs calls for consistent results
* prevent division by zero as per copilot
* replace valfunc_VFI with valfunc_vfi throughout the lecture
* fix a typo in the lecture
* add minor comments into the code
* Apply the prose, heading and figure fixes from this branch
Reapplies the non-JAX improvements from the original JAX-conversion work
on top of main's Numba implementation:
- typo and wording fixes: "illegitmate", "previos", "prematurally",
"algorthm", "objection to reject" -> "option to reject", "take
existing wage if and update" -> "take the existing wage and update",
"$Q$ map" -> "$Q$ maps", "vis a vis" -> "versus"
- section headings to sentence case, per the style guide (the lecture
title keeps title case)
- move the crowded legend in plot_epochs below the axes in two columns,
where it no longer covers the curves, and format the mean error to two
decimals so the labels fit
- drop a duplicated VFI computation that ran at the end of the wage
distribution plotting cell and again in the cell immediately after
- guard the progress-report modulus against small epoch counts
Co-Authored-By: bishmaybarik <177107536+bishmaybarik@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: John Stachurski <john.stachurski@gmail.com>
Co-authored-by: bishmaybarik <177107536+bishmaybarik@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Note that the first equation of system {eq}`eq:impliedq` presumes that after the agent has accepted an offer, he will not have the objection to reject that same offer in the future.
278
+
Note that the first equation of system {eq}`eq:impliedq` presumes that after the agent has accepted an offer, he will not have the option to reject that same offer in the future.
279
279
280
280
These equations are aligned with the Bellman equation for the worker's optimal value function that we studied in {doc}`this quantecon lecture <mccall_model>`.
281
281
@@ -313,7 +313,7 @@ $$
313
313
314
314
+++
315
315
316
-
## From Probabilities to Samples
316
+
## From probabilities to samples
317
317
318
318
We noted above that the optimal Q function for our McCall worker satisfies the Bellman equations
319
319
@@ -326,7 +326,7 @@ $$ (eq:probtosample1)
326
326
327
327
Notice the integral over $F(w')$ on the second line.
328
328
329
-
Erasing the integral sign sets the stage for an illegitmate argument that can get us started thinking about Q-learning.
329
+
Erasing the integral sign sets the stage for an illegitimate argument that can get us started thinking about Q-learning.
330
330
331
331
Thus, construct a difference equation system that keeps the first equation of {eq}`eq:probtosample1`
332
332
but replaces the second by removing integration over $F (w')$:
@@ -370,7 +370,7 @@ to objects in equation system {eq}`eq:old105`.
370
370
371
371
This informal argument takes us to the threshold of Q-learning.
372
372
373
-
## Q-Learning
373
+
## Q-learning
374
374
375
375
Let's first describe a $Q$-learning algorithm precisely.
376
376
@@ -456,7 +456,7 @@ pseudo-code for our McCall worker to do Q-learning:
456
456
457
457
4. Update the state associated with the chosen action and compute $\widetilde{TD}$ according to {eq}`eq:old4` and update $\widetilde{Q}$ according to {eq}`eq:old3`.
458
458
459
-
5. Either draw a new state $w'$ if required or else take existing wage if and update the Q-table again according to {eq}`eq:old3`.
459
+
5. Either draw a new state $w'$ if required or else take the existing wage and update the Q-table again according to {eq}`eq:old3`.
460
460
461
461
6. Stop when the old and new Q-tables are close enough, i.e., $\lVert\tilde{Q}^{new}-\tilde{Q}^{old}\rVert_{\infty}\leq\delta$ for given $\delta$ or if the worker keeps accepting for $T$ periods for a prescribed $T$.
462
462
@@ -474,7 +474,7 @@ The Q-table is updated via temporal difference learning.
474
474
475
475
We iterate this until convergence of the Q-table or the maximum length of an episode is reached.
476
476
477
-
Multiple episodes allow the agent to start afresh and visit states that she was less likely to visit from the terminal state of a previos episode.
477
+
Multiple episodes allow the agent to start afresh and visit states that she was less likely to visit from the terminal state of a previous episode.
478
478
479
479
For example, an agent who has accepted a wage offer based on her Q-table will be less likely to draw a new offer from other parts of the wage distribution.
@@ -704,7 +702,7 @@ The above graphs indicates that
704
702
705
703
* the quality of approximation to the "true" value function computed by value function iteration improves for longer epochs
706
704
707
-
## Employed Worker Can't Quit
705
+
## Employed worker can't quit
708
706
709
707
710
708
The preceding version of temporal difference Q-learning described in equation system {eq}`eq:old4` lets an employed worker quit, i.e., reject her wage as an incumbent and instead receive unemployment compensation this period
@@ -715,7 +713,7 @@ This is an option that the McCall worker described in {doc}`this quantecon lectu
715
713
See {cite}`Ljungqvist2012`, chapter 6 on search, for a proof.
716
714
717
715
But in the context of Q-learning, giving the worker the option to quit and get unemployment compensation while
718
-
unemployed turns out to accelerate the learning process by promoting experimentation vis a vis premature
716
+
unemployed turns out to accelerate the learning process by promoting experimentation versus premature
719
717
exploitation only.
720
718
721
719
To illustrate this, we'll amend our formulas for temporal differences to forbid an employed worker from quitting a job she had accepted earlier.
@@ -731,7 +729,7 @@ $$ (eq:temp-diff)
731
729
732
730
It turns out that formulas {eq}`eq:temp-diff` combined with our Q-learning recursion {eq}`eq:old3` can lead our agent to eventually learn the optimal value function as well as in the case where an option to redraw can be exercised.
733
731
734
-
But learning is slower because an agent who ends up accepting a wage offer prematurally loses the option to explore new states in the same episode and to adjust the value associated with that state.
732
+
But learning is slower because an agent who ends up accepting a wage offer prematurely loses the option to explore new states in the same episode and to adjust the value associated with that state.
735
733
736
734
This can lead to inferior outcomes when the number of epochs/episodes is low.
737
735
@@ -744,9 +742,9 @@ We illustrate these possibilities with the following code and graph.
0 commit comments