Sorry, I still can’t seem to figure this out. Here’s what I have for my model and guide:
def hsma_gp_model(X_obs, y_obs, X_acc, y_hyp):
alpha = pyro.sample('alpha', dist.Gamma(10, 10))
sigma = pyro.sample('sigma', dist.Gamma(8, 16))
rho = pyro.sample('rho', dist.Uniform(torch.Tensor([1e-6]), torch.Tensor([4.0])))
n_acc, _ = X_acc.size()
probs = torch.ones(n_acc) / n_acc
X = X_obs
with pyro.iarange('hyp', len(y_hyp)):
ind = pyro.sample('ind', dist.Categorical(probs=probs))
X = torch.cat([X, X_acc[ind:ind+1]])
y = torch.cat([y_obs, y_hyp])
# Covariance
n = len(X)
cov = Matern52(X, X, alpha, rho) + torch.eye(n) * (sigma + 1e-5)
L = torch.potrf(cov, upper=False)
print(L.size())
# Likelihood
return pyro.sample('f', dist.MultivariateNormal(torch.zeros(n), scale_tril=L), obs=y)
def hsma_gp_guide(X_obs, y_obs, X_acc, y_hyp):
aa = pyro.param('aa', torch.Tensor([10]), constraint=constraints.positive)
ab = pyro.param('ab', torch.Tensor([10]), constraint=constraints.positive)
ba = pyro.param('ba', torch.Tensor([8]), constraint=constraints.positive)
bb = pyro.param('bb', torch.Tensor([16]), constraint=constraints.positive)
ra = pyro.param('ra', torch.Tensor([10]), constraint=constraints.positive)
rb = pyro.param('rb', torch.Tensor([10]), constraint=constraints.positive)
n_acc, _ = X_acc.size()
alpha = pyro.sample('alpha', dist.Gamma(aa, ab))
sigma = pyro.sample('sigma', dist.Beta(ba, bb))
rho = pyro.sample('rho', dist.Gamma(ra, rb))
with pyro.iarange('hyp', len(y_hyp)):
ps = pyro.param('ps', torch.ones(n_acc) / n_acc, constraint=constraints.simplex)
ind = pyro.sample('ind', dist.Categorical(probs=ps), infer={'enumerate': 'parallel'})
return alpha, sigma, rho, inds
It’s supposed to choose rows of X_acc to fill in X during each sample.
How does iarange know how many times it needs to loop?