I’m trying to do a 'hello world" for the new ADVI interface.
This was my old code, which produced an almost exactly matching variational posterior
data = np.random.randn(100)
with pm.Model() as model:
mu = pm.Normal('mu', mu=0, sd=1, testval=0)
sd = pm.HalfNormal('sd', sd=1)
n = pm.Normal('n', mu=mu, sd=sd, observed=data)
advifit = pm.variational.advi( model=model, n=100000)
means, sds, elbo = advifit
In the new way, i create a ADVI object
advifit = pm.ADVI( model=model)
advifit.fit(n=10000)
advifit.approx.mean.eval(), advifit.approx.std.eval()
this gives me:
(array([-0.06538046, -0.03497334]), array([ 0.11616796, 0.08825936]))
is the first array the means of the variational approximations for mu and sd for my model? Or is there something going on with the parametrization (sd has a negative mean). And in general, given the advifit object, what is the officially sanctioned way of getting samples from it? I looked at the quickstart but landed up getting more confused, and the API docs dont seem to go into the Approximation objects.