Skip to content

Automatically handle warmup draws and sampling metadata from_pymc3 #1146

Closed
@michaelosthege

Description

@michaelosthege

Tell us about it

The trace.report in PyMC3 now has attributes n_tune, n_draws and t_sampling (see pymc-devs/pymc#3827).

I have this snippet to store those metadata with the trace:

idat = arviz.from_pymc3(trace)
if hasattr(trace.report, 'n_tune'):
        idat.posterior.attrs['n_tune'] = trace.report.n_tune
        idat.posterior.attrs['n_draws'] = trace.report.n_draws
        idat.posterior.attrs['t_sampling'] = trace.report.t_sampling

Using n_draws, one can now slice a trace that contains warmup iterations:

trace_warmup = trace[:-trace.report.n_draws]   # <-- may result in len(trace_warmup) == 0
trace_posterior = trace[-trace.report.n_draws:]

Thoughts on implementation

I suppose both snippets should find their place in the PyMC3Converter, but I'm not sure how saving the warmup should be done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions