How to pass deterministic variables and observtions to pymc.Metropolis()

20 views Asked by At

I am trying to recreate this tutorial by Austin Rochford about Non-parametric bayesian models from 2016 which can be found here.

The tutorial uses pymc3 and theano which are no longer supported and there is no environment with package versions specified. When I try and run the model:

with pm.Model() as model:
    alpha = pm.Gamma('alpha', 1., 1.)
    beta = pm.Beta('beta', 1., alpha, shape=K)
    w = pm.Deterministic('w', beta * T.concatenate([[1], T.extra_ops.cumprod(1 - beta)[:-1]]))
    component = pm.Categorical('component', w, shape=N)

    tau = pm.Gamma('tau', 1., 1., shape=K)
    lambda_ = pm.Uniform('lambda', 0, 5, shape=K)
    mu = pm.Normal('mu', 0, lambda_ * tau, shape=K)
    obs = pm.Normal('obs', mu[component], lambda_[component] * tau[component],
                    observed=old_faithful_df.std_waiting.values)
with model:
    step1 = pm.Metropolis(vars=[alpha, beta, w, lambda_, tau, mu, obs])
    step2 = pm.ElemwiseCategoricalStep([component], np.arange(K))
    
    trace_ = pm.sample(20000, [step1, step2])


trace = trace_[10000::10]

I get the following errors:

The following variables are not random variables in the model: ['w','obs]

They obviously aren't random variables, implying the call signature for pm.Metropolis has changes from pymc3 to pymc5.

I removed these from the vars list and then had the error:

AttributeError: module 'pymc' has no attribute 'ElemwiseCategoricalStep'

I do not really know anything about either pymc3 or pymc5. I have tried rummaging in their documentation to no avail. Does anyone know how I can rewrite this model and inference so that I can run it with pymc5?

thank you!

0

There are 0 answers