Storage backends#

to_inference_data([trace, prior, ...])

Convert pymc data into an InferenceData object.

predictions_to_inference_data(predictions[, ...])

Translate out-of-sample predictions into InferenceData.

Internal structures#

Storage backends for traces

The NDArray (pymc.backends.NDArray) backend holds the entire trace in memory.

Selecting values from a backend#

After a backend is finished sampling, it returns a MultiTrace object. Values can be accessed in a few ways. The easiest way is to index the backend object with a variable or variable name.

>>> trace['x']  # or trace.x or trace[x]

The call will return the sampling values of x, with the values for all chains concatenated. (For a single call to sample, the number of chains will correspond to the cores argument.)

To discard the first N values of each chain, slicing syntax can be used.

>>> trace['x', 1000:]

The get_values method offers more control over which values are returned. The call below will discard the first 1000 iterations from each chain and keep the values for each chain as separate arrays.

>>> trace.get_values('x', burn=1000, combine=False)

The chains parameter of get_values can be used to limit the chains that are retrieved.

>>> trace.get_values('x', burn=1000, chains=[0, 2])

MultiTrace objects also support slicing. For example, the following call would return a new trace object without the first 1000 sampling iterations for all traces and variables.

>>> sliced_trace = trace[1000:]

The backend for the new trace is always NDArray, regardless of the type of original trace.

Loading a saved backend#

Saved backends can be loaded using arviz.from_netcdf

NDArray([name, model, vars, test_point])

NDArray trace object

base.BaseTrace(name[, model, vars, test_point])

Base trace object


Main interface for accessing values from MCMC results.