Skip to content

EnsemblePosterior.sample(x) checks x only in the posteriors it draws #2195

Closed

Description

@janfb

EnsemblePosterior.sample(x=...) checks x only in the component posteriors that the random draw picks. An ensemble of VI posteriors fit to different observations can therefore return samples for an x that some of its posteriors were never fit to, without an error.

The ensemble first draws a component for each sample, then calls sample() of each drawn component. A VI posterior trained with train(x=x_o) raises when it gets another x, but only if it is drawn:

fits = []
for x_o in (2 * ones(1, 2), -2 * ones(1, 2)):
    vi = VIPosterior(potential_fn, prior, q="gaussian")
    vi.train(x=x_o)
    fits.append(vi)
ensemble = EnsemblePosterior(fits, weights=[0.99, 0.01])

ensemble.sample((5,), x=2 * ones(1, 2))  # returns samples in most draws, raises in a few

The ensemble should raise before it draws whenever one of its posteriors cannot take x, so that the result does not depend on the draw. One way: a method that checks x without sampling, which single-x VI overrides and the ensemble calls for every component.

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