PerturbationDSGEPosterior#
- class cultivars.multivariate.structural.perturbation.PerturbationDSGEPosterior(*, data, parameter_names, theta_draws, loglik_draws, log_posterior_draws, acceptance_rate, order, n_particles, nobs, n_draws, n_burn, thin, _engine, _unconstrained)[source]#
A particle-chain posterior over a perturbation model.
- Variables:
parameter_names (
tuple[str,...]) – Structural parameter labels.theta_draws (
NDArray[double]) –(S, d)kept draws in the model’s own space.loglik_draws (
NDArray[double]) –(S,)particle likelihood estimates carried with each kept draw.log_posterior_draws (
NDArray[double]) –(S,)log prior plus log-likelihood estimate at each kept draw, in the chain’s unconstrained space.acceptance_rate (
float) – Acceptance rate over the whole run.order (
int) – Perturbation order.n_particles (
int) – Particles per likelihood estimate.nobs (
int) – Observations.n_draws (
int) – Total iterations.n_burn (
int) – Burn-in discarded.thin (
int) – Post-burn thinning.
The draws are stored twice.
theta_drawsholds them in the model’s own, bounded space and is what every summary reads._unconstrainedholds the same draws in the space the chain moved in, which is the spacelog_posterior_drawsis a density on and therefore the space the marginal likelihood is computed in.The record keeps a reference to the engine that produced it, because everything beyond the draws (
solution,state_space,impulse_responses,simulate) solves the model again at a parameter value. None of it is cached.See also
PerturbationDSGEPosterior– the public name of this class.PerturbationDSGE.sample()– returns an instance.PerturbationDSGEPosterior._from_fit()– returns an instance.
Example
A latent AR(1) written as a one-state model, with a chain far too short for inference:
>>> import numpy as np >>> from cultivars.multivariate.structural.perturbation import PerturbationDSGE >>> class Latent: ... parameter_names, bounds = ("rho", "sigma"), ((0.0, 0.99), (0.01, 1.0)) ... n_states, n_controls = 1, 1 ... ... def equations(self, th, y_next, y, x_next, x): ... return np.array([y[0] - x[0], x_next[0] - th[0] * x[0]]) ... ... def steady_state(self, th): ... return np.zeros(1), np.zeros(1) ... ... def shock_loading(self, th): ... return np.array([[th[1]]]) ... ... def observation(self, th): ... return np.array([[0.0, 1.0]]), np.zeros(1), np.array([[1e-4]]) ... ... def log_prior(self, th): ... return 0.0 >>> rng = np.random.default_rng(0) >>> x = np.zeros(80) >>> for t in range(1, 80): ... x[t] = 0.8 * x[t - 1] + 0.5 * rng.standard_normal() >>> model = PerturbationDSGE(Latent(), x, order=2) >>> start = model.fit([0.5, 0.3]).theta >>> post = model.sample(start, n_particles=50, n_draws=30, n_burn=10, seed=0) >>> isinstance(post, _PerturbationDSGEPosterior), post.n_kept, list(post.params) (True, 20, ['rho', 'sigma']) >>> states, controls = post.impulse_responses(horizon=5, n_draws=4, seed=0) >>> states.shape, controls.shape ((4, 1, 5, 1), (4, 1, 5, 1))
Attributes#
The observables, |
|
Structural parameter labels, in the column order of |
|
Kept draws in the model's own, constrained space, |
|
Particle log-likelihood estimate carried with each kept draw, |
|
Log prior plus log-likelihood estimate at each kept draw, |
|
Acceptance rate of the chain over the whole run, burn-in included. |
|
Perturbation order of the solution the likelihood was evaluated on. |
|
Particles per likelihood estimate. |
|
Number of observations \(n\). |
|
Total chain iterations, burn-in included. |
|
Iterations discarded as burn-in. |
|
Thinning interval applied after burn-in. |
|
Posterior draws retained. |
|
The posterior mean by name. |
|
The perturbation solution at the posterior mean. |
|
The solution at the posterior mean on its substrate. |
|
The posterior mean. |
Methods#
|
Assess the sampler's convergence over the retained draws. |
|
Posterior draws of the responses. |
|
Geweke's modified harmonic mean of the log marginal likelihood. |
|
A fresh sample of the observables at the posterior mean or at one kept draw. |
|
The estimation summary, renderable as text, HTML, or a dataframe. |