In [1]:
import numpy as np
import matplotlib.pyplot as plt
import quantecon as qe
In [2]:
%run src/ssy_discretized_test.py
In [4]:
s = SSY()
In [5]:
def discrete_call(D):
return test_val_spec_rad(s, K=D, I=D, J=D)
In [6]:
def continuous_call(D):
f = mc_factory(s, K=D, I=D, J=D)
return f(n=1000, m=1000)
In [7]:
%time discrete_call(10)
Out[7]:
In [8]:
%time continuous_call(10)
Out[8]:
In [9]:
comparisons = []
calls = [discrete_call, continuous_call]
results = np.empty(2)
D1, D2 = 3, 20
for d in range(D1, D2):
for i, call in enumerate(calls):
qe.tic()
call(d)
results[i] = qe.toc(verbose=False)
comparisons.append(results[0] / results[1])
In [10]:
comparisons
Out[10]:
In [14]:
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(range(D1, D2), np.array(comparisons), label="spectral radius runtime / Monte Carlo runtime")
ax.set_xlabel("level of discretization $D$", fontsize=12)
ax.set_ylabel("relative time", fontsize=12)
ax.legend()
plt.savefig("ssy_compare_run_times.pdf")
plt.show()
In [ ]: