Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Fixes to Calvo Machine Learning Lecture #168

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
26 changes: 13 additions & 13 deletions lectures/calvo_machine_learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ First, because we'll want to compare the results we obtain here with those obtai
We hide the cell that copies the class, but readers can find details of the class in this quantecon lecture {doc}`calvo`.

```{code-cell} ipython3
:tags: [hide-output]
:tags: [hide-input]

class ChangLQ:
"""
Expand Down Expand Up @@ -558,14 +558,20 @@ def compute_θ(μ, α=1):
θ = jnp.append(θ, μbar)

return θ

@jit
def compute_hs(u0, u1, u2, α):
h0 = u0
h1 = -u1 * α
h2 = -0.5 * u2 * α**2

return h0, h1, h2

@jit
def compute_V(μ, β, c, α=1, u0=1, u1=0.5, u2=3):
θ = compute_θ(μ, α)

h0 = u0
h1 = -u1 * α
h2 = -0.5 * u2 * α**2
h0, h1, h2 = compute_hs(u0, u1, u2, α)

T = len(μ) - 1
t = np.arange(T)
Expand Down Expand Up @@ -890,9 +896,7 @@ With the more structured approach, we can update our gradient descent exercise w
def compute_J(μ, β, c, α=1, u0=1, u1=0.5, u2=3):
T = len(μ) - 1

h0 = u0
h1 = -u1 * α
h2 = -0.5 * u2 * α**2
h0, h1, h2 = compute_hs(u0, u1, u2, α)
λ = α / (1 + α)

_, B = construct_B(α, T+1)
Expand Down Expand Up @@ -944,9 +948,7 @@ We can also derive a closed-form solution for $\vec \mu$

```{code-cell} ipython3
def compute_μ(β, c, T, α=1, u0=1, u1=0.5, u2=3):
h0 = u0
h1 = -u1 * α
h2 = -0.5 * u2 * α**2
h0, h1, h2 = compute_hs(u0, u1, u2, α)

_, B = construct_B(α, T+1)

Expand Down Expand Up @@ -981,9 +983,7 @@ We can check the gradient of the analytical solution against the `JAX` computed
def compute_grad(μ, β, c, α=1, u0=1, u1=0.5, u2=3):
T = len(μ) - 1

h0 = u0
h1 = -u1 * α
h2 = -0.5 * u2 * α**2
h0, h1, h2 = compute_hs(u0, u1, u2, α)

_, B = construct_B(α, T+1)

Expand Down
Loading