Beispiel #1
0
    return v, phi_vfi, phi_pfi, new_v


# model parameters
beta = 0.95
c = 0.6
F_a = 1
F_b = 1
G_a = 3
G_b = 1.2
w_max = 2
w_grid_size = 40
pi_grid_size = 40

sp = SearchProblem(beta, c, F_a, F_b, G_a, G_b, w_max, w_grid_size,
                   pi_grid_size)

v, phi_vfi, phi_pfi, new_v = _get_data(sp)


def test_h5_access():
    "odu: test access to data file"
    assert_true(v is not None)
    assert_true(phi_vfi is not None)
    assert_true(phi_pfi is not None)


def test_vfi_v_phi_same_shape():
    "odu: vfi value and policy same shape"
    assert_equal(v.shape, phi_vfi.shape)
Beispiel #2
0
"""
Filename: odu_vfi_plots.py
Authors: John Stachurski and Thomas Sargent
"""

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
from matplotlib import cm
from scipy.interpolate import LinearNDInterpolator
import numpy as np
from quantecon import compute_fixed_point
from quantecon.models import SearchProblem


sp = SearchProblem(w_grid_size=100, pi_grid_size=100)
v_init = np.zeros(len(sp.grid_points)) + sp.c / (1 - sp.beta)
v = compute_fixed_point(sp.bellman_operator, v_init)
policy = sp.get_greedy(v)

# Make functions from these arrays by interpolation
vf = LinearNDInterpolator(sp.grid_points, v)
pf = LinearNDInterpolator(sp.grid_points, policy)

pi_plot_grid_size, w_plot_grid_size = 100, 100
pi_plot_grid = np.linspace(0.001, 0.99, pi_plot_grid_size)
w_plot_grid = np.linspace(0, sp.w_max, w_plot_grid_size)

#plot_choice = 'value_function'
plot_choice = 'policy_function'

if plot_choice == 'value_function':
Beispiel #3
0
"""
Filename: odu_plot_densities.py
Authors: John Stachurski, Thomas J. Sargent

"""
import numpy as np
import matplotlib.pyplot as plt
from quantecon.models import SearchProblem

sp = SearchProblem(F_a=1, F_b=1, G_a=3, G_b=1.2)
grid = np.linspace(0, 2, 150)
fig, ax = plt.subplots()
ax.plot(grid, sp.f(grid), label=r'$f$', lw=2)
ax.plot(grid, sp.g(grid), label=r'$g$', lw=2)
ax.legend(loc=0)
plt.show()