Module Documentation¶
emcwrap.sampler¶
- emcwrap.sampler.get_prior_sample(frozen_prior, nsamples, check_func=False, seed=None, mapper=<class 'map'>, filterwarnings='error', max_attempts=10, debug=False, verbose=True)¶
Get a sample of size nsamples from the prior distribution.
- emcwrap.sampler.mcmc_summary(chain, lprobs, priors, acceptance_fraction=None, out=<built-in function print>, **args)¶
- emcwrap.sampler.run_mcmc(lprob, nsteps, p0=None, moves=None, priors=None, prior_transform=None, backend=None, update_freq=False, resume=False, pool=None, report=None, description=None, temp=1, maintenance_interval=False, verbose=True, **kwargs)¶
Run the emcee sampler.
emcwrap.moves¶
- class emcwrap.moves.DIMEMove(*args: Any, **kwargs: Any)¶
Bases:
RedBlueMoveA proposal using adaptive differential-independence mixture ensemble MCMC.
This is the Differential-Independence Mixture Ensemble proposal as developed in Ensemble MCMC Sampling for DSGE Models (previousy ADEMC).
- Parameters
sigma (float, optional) – standard deviation of the Gaussian used to stretch the proposal vector.
gamma (float, optional) – mean stretch factor for the proposal vector. By default, it is \(2.38 / \sqrt{2\,\mathrm{ndim}}\) as recommended by ter Braak (2006).
aimh_prob (float, optional) – probability to draw an adaptive independence Metropolis Hastings (AIMH) proposal. By default this is set to \(0.1\).
df_proposal_dist (float) – degrees of freedom of the multivariate t distribution used for AIMH proposals. Defaults to \(10\).
- get_proposal(x, dummy, random)¶
- propose(model, state)¶
- setup(coords)¶
- emcwrap.moves.mvt_sample(df, mean, cov, size, random)¶
Sample from multivariate t distribution
For reasons beyond my understanding, the results from random.multivariate_normal with non-identity covariance matrix are not reproducibel across architecture. Since scipy.stats.multivariate_t is based on numpy’s multivariate_normal, the workaround is to crochet this manually. Advantage is that the scipy dependency drops out.
emcwrap.tools¶
- emcwrap.tools.find_mode_simple(lprob, init, frozen_prior, sd=True, verbose=False, **kwargs)¶
- emcwrap.tools.get_bijective_prior_transformation(funcs_con, funcs_re)¶
Get the bijective prior transformation function.
- emcwrap.tools.get_log_prior(frozen_prior)¶
Get the log-prior function.
- emcwrap.tools.get_prior(prior, verbose=False)¶
Compile prior-related computational objects from a list of priors.
- emcwrap.tools.load_backend(backend)¶
just a shortcut
- emcwrap.tools.remove_backend(backend)¶
just a shortcut
- emcwrap.tools.rm_backend(backend)¶
just a shortcut
- emcwrap.tools.save_to_backend(backend, content)¶
emcwrap.plots¶
- emcwrap.plots.fast_kde(x, bw=4.5)¶
A fft-based Gaussian kernel density estimate (KDE) The code was adapted from https://github.com/mfouesneau/faststats
- Parameters
x (Numpy array or list) –
bw (float) – Bandwidth scaling factor for the KDE. Should be larger than 0. The higher this number the smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott’s rule of thumb (the default rule used by SciPy).
- Returns
density (A gridded 1D KDE of the input points (x))
xmin (minimum value of x)
xmax (maximum value of x)
- emcwrap.plots.get_axis(ax, default_rows, default_columns, **default_kwargs)¶
Verifies the provided axis is of the correct shape, and creates one if needed.
- Parameters
ax – matplotlib axis or None
default_rows – int, expected rows in axis
default_columns – int, expected columns in axis
**default_kwargs – keyword arguments to pass to plt.subplot
- Returns
axis, or raises an error
- emcwrap.plots.kdeplot_op(ax, data, bw, prior=None, prior_alpha=1, prior_style='--')¶
Get a list of density and likelihood plots, if a prior is provided.
- emcwrap.plots.plot_posterior_op(trace_values, ax, bw, prior, kde_plot=False, point_estimate='mean', round_to=3, alpha_level=0.05, ref_val=None, rope=None, text_size=16, display_additinal_info=False, **kwargs)¶
Artist to draw posterior.
- emcwrap.plots.posteriorplot(trace, varnames=None, tune=0, figsize=None, plots_per_fig=4, text_size=None, ropep=None, ref_val=None, round_to=3, alpha_level=0.05, bw=4.5, ax=None, **kwargs)¶
- emcwrap.plots.scale_text(figsize, text_size)¶
Scale text to figsize.
- emcwrap.plots.traceplot(trace, varnames, tune, figsize=None, plots_per_fig=3, frozen_prior=None, draw_each_trace=True, bw=4.5, text_size=None, **kwargs)¶
emcwrap.stats¶
- emcwrap.stats.calc_min_interval(x, alpha)¶
Internal method to determine the minimum interval of a given width
Assumes that x is sorted numpy array.
- emcwrap.stats.gelman_rubin(sample)¶
The Gelman-Rubin (1992) statistics.
- emcwrap.stats.integrated_time(x)¶
- emcwrap.stats.mc_error(x)¶
- emcwrap.stats.mdd_harmonic_mean(chain, lprobs, pool=None, alpha=0.05, verbose=False, debug=False)¶
Approximate the marginal data density useing modified harmonic mean.
- emcwrap.stats.mdd_laplace(chain, lprobs, calc_hess=False)¶
Approximate the marginal data density useing the LaPlace method.
- emcwrap.stats.summary(priors, store, pmode=None, bounds=None, alpha=0.1, top=None, show_prior=True)¶
emcwrap.dists¶
- class emcwrap.dists.InvGammaDynare(*args: Any, **kwargs: Any)¶
Bases:
rv_continuous- name = 'inv_gamma_dynare'¶
- emcwrap.dists.inv_gamma_spec(mu, sigma)¶