I’m plotting a histogram of the posterior. I’m wondering why plotting “temperature” marginal varies if I comment out the “sales” sampling since temperature doesn’t depend on sales.
I’m also trying to understand why “temperature” gets capped at ~26.5 when “sales” isn’t commented out.
I’ve tried isolating sampling of temperature within a pyro.plate as well as sales but I don’t see any changes while plotting the posterior.
import pyro
import pyro.distributions as dist
from pyro.infer import EmpiricalMarginal
from pyro.infer.mcmc import MCMC
from pyro.infer.mcmc.nuts import HMC
import matplotlib.pyplot as plt
pyro.set_rng_seed(101)
pyro.enable_validation(True)
def model():
cloudy = pyro.sample("cloudy", dist.Bernoulli(0.3), infer={"enumerate": "sequential"})
is_cloudy = cloudy == 1.0
temp_mu = 13.0 if is_cloudy else 24.0
temp_si = 5.0 if is_cloudy else 7.0
temperature = pyro.sample("temperature", dist.Normal(temp_mu, temp_si))
sales_mu = 200.0 if (not is_cloudy and temperature > 26.5) else 50.0
# HELP: commenting the line below seems to affect "temperature" sampling
sales = pyro.sample('sales', dist.Normal(sales_mu, 10.0))
def build_posterior():
hmc_kernel = HMC(model=model, step_size=0.09, num_steps=4)
posterior = MCMC(kernel=hmc_kernel, num_samples=500, warmup_steps=50)
posterior.run()
return posterior
posterior = build_posterior()
marginal = EmpiricalMarginal(posterior, "temperature")
plt.hist([marginal().detach() for x in range(5000)], 50)
plt.title("P(icecream_sales)")
plt.xlabel("$")
plt.ylabel("#")
plt.show()