Skip to content

ADVI not properly sampling from Bounded distributions #1170

Closed
@aasensio

Description

@aasensio

I'm trying to sample from a complex hierarchical model with lots of variables. I'm thinking of applying ADVI to sample from the posterior because the model has potentially many variables. One of the variables has a bounded prior. In the process of learning how to write user-defined bounded distributions, I did some tests with simple distributions and, unless I'm doing something wrong, it looks that ADVI is not able to properly sample from bounded distributions. Here is the code I'm using:

with pm.Model() as model:
    boundedNormal = pm.Bound(pm.Normal, upper=1.0)
    th = boundedNormal('th', mu=0.0, sd=1.0)
    v_params = pm.variational.advi(n=50000)
    traceADVI = pm.variational.sample_vp(v_params, draws=5000)

with pm.Model() as model:
    boundedNormal = pm.Bound(pm.Normal, upper=1.0)
    th = boundedNormal('th', mu=0.0, sd=1.0)
    traceNUTS = pm.sample(2000, pm.NUTS())

pm.traceplot(traceADVI)
pm.traceplot(traceNUTS)

The samples from the NUTS alg are shown in the following
figure_2

while those of ADVI are shown in the following:
figure_1-3

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