Hello all,
I am trying to run a regression model with the following code:
def model(X, obs=None):
# Prior for the bias/intercept
alpha = pyro.sample('alpha', dist.Normal(0., 1.))
# Priors for the regression coeffcients
beta = pyro.sample('beta', dist.Normal(torch.zeros(X.shape[1]),
1.*torch.ones(X.shape[1])))
# Priors for the error term
epsilon = pyro.sample('epsilon', dist.HalfCauchy(5.))
with pyro.plate('data'):
y = pyro.sample('y', dist.Normal(alpha + X.matmul(beta), epsilon), obs=obs)
return y
X_train = torch.tensor(X).float()
y_train = torch.tensor(y).float()
nuts_kernel = NUTS(model)
mcmc = MCMC(nuts_kernel, num_samples=3000, warmup_steps=200, num_chains=2)
mcmc.run(model, X_train, y_train)
Both X_train and y_train are tensors. However, it returns the following error message. And a few month ago, the same code worked.
Does anyone know how to resolve this? All tips are appreciated!
AttributeError Traceback (most recent call last)
Input In [12], in <cell line: 4>()
2 nuts_kernel = NUTS(model)
3 mcmc = MCMC(nuts_kernel, num_samples=3000, warmup_steps=200, num_chains=2)
----> 4 mcmc.run(model, X_train, y_train)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyro/poutine/messenger.py:11, in _context_wrap(context, fn, *args, **kwargs)
10 def _context_wrap(context, fn, *args, **kwargs):
—> 11 with context:
12 return fn(*args, **kwargs)
AttributeError: enter