In [26]:
%run src/lg_model.py
In [27]:
lg = LinearGaussian(γ=7.5)
Here's the spectral radius at default values:
In [66]:
lrm_analytic(lg)
Out[66]:
In [67]:
lrm_discretized(lg)
Out[67]:
In [68]:
se_mc = lrm_mc_factory(lg, parallel_flag=False)
In [69]:
%time se_mc(m=1500, n=1000)
Out[69]:
Once more with parallelization:
In [70]:
se_mc = lrm_mc_factory(lg, parallel_flag=True)
In [71]:
%time se_mc(m=1500, n=1000)
Out[71]:
For the stability exponent $\Lambda$, with parameter vals from SSY
In [72]:
lg.β * lrm_analytic(lg)**(1 - 1/lg.ψ)
Out[72]:
Generate the table
In [73]:
n_vals = np.array([250, 500, 750])
m_vals = np.array([1000, 2000, 3000, 4000, 5000])
In [74]:
k = 100
MC_draws = np.empty(k)
Lambda_draws = np.empty(k)
MC_means = np.empty((len(n_vals), len(m_vals)))
MC_stds = np.empty((len(n_vals), len(m_vals)))
Lambda_means = np.empty((len(n_vals), len(m_vals)))
Lambda_stds = np.empty((len(n_vals), len(m_vals)))
for n_i, n in enumerate(n_vals):
for m_i, m in enumerate(m_vals):
print(f'Calculating n={n}, m={m}')
for i in range(k):
MC_draws[i] = se_mc(n=n, m=m)
Lambda_draws = lg.β * MC_draws**(1 - 1/lg.ψ)
MC_means[n_i, m_i] = MC_draws.mean()
MC_stds[n_i, m_i] = MC_draws.std()
Lambda_means[n_i, m_i] = Lambda_draws.mean()
Lambda_stds[n_i, m_i] = Lambda_draws.std()
In [75]:
def make_table(means, stds):
means_strings = means.round(7).astype(str)
n_strings = n_vals.astype(str)
start_table = r"""
\begin{table}
\centering
\begin{tabular}{llll}
"""
m_table = ' & m = '.join(m_vals.astype(str))
m_table = ' & m = ' + m_table + r' \\' + '\n' + r'\hline \hline' '\n'
end_table = r"""
\end{tabular}
\end{table}
"""
row_string = ''
for row in range(len(n_strings)):
temp_means = ' & '.join(means_strings[row, :])
x = ['{:f}'.format(item) for item in stds[row, :]]
temp_stds = '(' + ') & ('.join(x) + ')'
row_string += f'n = {n_strings[row]} & ' + temp_means + r' \\' + '\n'
row_string += ' & ' + temp_stds + r' \\' + '\n'
row_string += r'\hline' '\n'
print(start_table + m_table + row_string + end_table)
In [76]:
make_table(MC_means, MC_stds)
In [77]:
make_table(Lambda_means, Lambda_stds)
In [78]:
lg = LinearGaussian(γ=7.5)
In [ ]:
In [ ]: