def test_ergo_mc(): from dolo import yaml_import, improved_time_iteration, ergodic_distribution model = yaml_import("examples/models/rbc_mc.yaml") sol = improved_time_iteration(model) Π, μ = ergodic_distribution(model, sol.dr) assert (μ.ndim == 2)
def equilibrium( hmodel, m0: "vector", S0=None, X0: "vector" = None, p=None, dr0=None, grids=None, verbose=False, return_equilibrium=True, ): if p is None: p = hmodel.calibration["parameters"] if S0 is None: q0 = hmodel.projection(m0, X0, p) else: q0 = hmodel.projection(m0, S0, X0, p) dp = inject_process(q0, hmodel.model.exogenous) sol = time_iteration(hmodel.model, dr0=dr0, dprocess=dp, maxit=10, verbose=verbose) sol = improved_time_iteration(hmodel.model, dr0=sol, dprocess=dp, verbose=verbose) dr = sol.dr if grids is None: exg, edg = grids = dr.exo_grid, dr.endo_grid else: exg, edg = grids Π0, μ0 = ergodic_distribution(hmodel.model, dr, exg, edg, dp) s = edg.nodes if exg.n_nodes == 0: nn = 1 μμ0 = μ0.data[None, :] else: nn = exg.n_nodes μμ0 = μ0.data xx0 = np.concatenate( [e[None, :, :] for e in [dr(i, s) for i in range(nn)]], axis=0) res = hmodel.𝒜(grids, m0, μμ0, xx0, X0, m0, X0, p, S0=S0, S1=S0) if return_equilibrium: return (res, sol, μ0, Π0) else: return res
def get_starting_rule(self, method="improved_time_iteration", **kwargs): # provides initial guess for d.r. by solving agent's problem dp = self.model.exogenous.discretize() # dr0 = time_iteration(self.model, dprocess=mc) if method == "improved_time_iteration": sol = improved_time_iteration(self.model, dprocess=dp, **kwargs) elif method == "time_iteration": sol = time_iteration(self.model, dprocess=dp, **kwargs) dr0 = sol.dr return dr0
def get_starting_rule(self, method='improved_time_iteration', **kwargs): # provides initial guess for d.r. by solving agent's problem mc = self.model.exogenous.discretize( to='mc', options=[{}, self.discretization_options]) # dr0 = time_iteration(self.model, dprocess=mc) if method == 'improved_time_iteration': sol = improved_time_iteration(self.model, dprocess=mc, **kwargs) elif method == 'time_iteration': sol = time_iteration(self.model, dprocess=mc, **kwargs) dr0 = sol.dr return dr0