-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edits to opt savings and opt invest (#154)
* misc * misc * misc * misc
- Loading branch information
Showing
7 changed files
with
313 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
# Implements the OPI-Optimal policy Iteration routine | ||
|
||
def optimistic_policy_iteration(model, tol=1e-5, m=10): | ||
constants, sizes, arrays = model | ||
""" | ||
Implements optimistic policy iteration (see dp.quantecon.org) | ||
""" | ||
params, sizes, arrays = model | ||
v = jnp.zeros(sizes) | ||
error = tol + 1 | ||
while error > tol: | ||
last_v = v | ||
σ = get_greedy(v, constants, sizes, arrays) | ||
σ = get_greedy(v, params, sizes, arrays) | ||
for _ in range(m): | ||
v = T_σ(v, σ, constants, sizes, arrays) | ||
v = T_σ(v, σ, params, sizes, arrays) | ||
error = jnp.max(jnp.abs(v - last_v)) | ||
return get_greedy(v, constants, sizes, arrays) | ||
return get_greedy(v, params, sizes, arrays) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Implements VFI-Value Function iteration | ||
|
||
def value_iteration(model, tol=1e-5): | ||
constants, sizes, arrays = model | ||
def value_function_iteration(model, tol=1e-5): | ||
""" | ||
Implements value function iteration. | ||
""" | ||
params, sizes, arrays = model | ||
vz = jnp.zeros(sizes) | ||
_T = lambda v: T(v, constants, sizes, arrays) | ||
_T = lambda v: T(v, params, sizes, arrays) | ||
v_star = successive_approx_jax(_T, vz, tolerance=tol) | ||
return get_greedy(v_star, constants, sizes, arrays) | ||
return get_greedy(v_star, params, sizes, arrays) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.