PosteriorApproximation#
- class pyfcirt.PosteriorApproximation#
Experimental runtime approximation to selected native PyMC free variables.
From idata#
- classmethod PosteriorApproximation.from_idata(
- idata,
- *,
- model,
- var_names,
- method='mvn',
- components=(2, 3),
- random_seed=None,
- transforms=None,
Parameters#
idata: xarray.DataTreeNatural-scale posterior with labelled
chainanddrawaxes. Each selected RV’s remaining dimensions and labels must match the native model.model: pymc.ModelModel that owns the selected continuous RVs.
var_names: sequence of str or mappingNative free-variable names. A sequence gives one density per RV. To group multiple RVs in a joint density, map a parameter-kind name to those RV names.
method: strDefault:
"mvn". See approximation methods.components: sequence of intCandidate mixture component counts. Default:
(2, 3).random_seed: int or NoneSeed for fitting the density.
transforms: mapping or NonePyMC value-transform overrides keyed by RV name.
Noneuses the native defaults. To override a constrained variable, use a transform whose inverse respects its support. Retain paired posterior draws for any free variable that supplies its bounds.
Returns#
- PosteriorApproximation
Runtime object with the selected
var_names, grouping and fittingdiagnostics. It can supply replacement priors in a compatible graph.
Apply to a native model#
- PosteriorApproximation.apply(model)#
Pass a PyMC model with the same selected RV names, parameter shapes and
coordinate system. The result is a new native pymc.Model with the fitted
priors; the input model retains its original priors. For PyFCIRT scoring, use
Model.posterior_approximation()
to carry design and evidence.
Examples#
Start with the fitted native PyMC graph and posterior from a calibration.
This example uses the MGPPM calibration from the
recursive scoring analysis.
It chooses the native source of the final loading variable and applies
the fitted prior to a new graph.
import pyfcirt as fc
from pytensor.graph.traversal import ancestors
native = calibration.build()
(loading_rv,) = [rv for rv in native.free_RVs if rv in ancestors([native["loading"]])]
prior = fc.PosteriorApproximation.from_idata(
calibration.idata,
model=native,
var_names={"loading": [loading_rv.name]},
)
updated = prior.apply(native)
print(updated is not native, tuple(prior.groups))
True ('loading',)