Is there any method to reject negative samples from guide. For example, here is a custom guide “normal_guide”. If the pyro.sample produces a negative sample, we should reject this negative sample and generate a new sample.
def normal_guide(data):
# register the two variational parameters with Pyro
mean = pyro.param("mean", torch.ones(1,Num),
constraint=constraints.interval(0, 10))
cov = pyro.param("covariance", torch.rand(Num, Num),
constraint=constraints.positive_definite)
# sample latent_variables from the variational distribution
pyro.sample("latent_variables", dist.MultivariateNormal(mean, cov))
I tried to realize it by the following code, but got wrong with it: RuntimeError: Multiple sample sites named ‘latent_variables’.
def normal_guide(data):
# register the two variational parameters with Pyro
mean = pyro.param("mean", torch.ones(1,Num),
constraint=constraints.interval(0, 10))
cov = pyro.param("covariance", torch.rand(Num, Num),
constraint=constraints.positive_definite)
# sample latent_variables from the variational distribution
sample = pyro.sample('latent_variables', dist.MultivariateNormal(mean, cov))
mask=sample<0
while (True in mask):
sample=pyro.sample("latent_variables", dist.MultivariateNormal(mean, cov))
mask=sample<0
return sample