Closed sammosummo closed 8 years ago
I just noticed that the buggyness seems to change depending on the sampler. With Metropolis:
with pymc3.Model() as model:
x = pymc3.HalfNormal(name='x', sd=1)
y = pymc3.Normal(name='y', sd=1)
z = pymc3.Deterministic('z', abs(y))
step = pymc3.Metropolis()
trace = pymc3.sample(500000, step=step)
pymc3.traceplot(trace)
Anyway, just an observation, hopefully it helps. Perhaps the sampler is having trouble taking steps that take it close to zero, given that it'd be so easy to overshoot and end up overshooting and get rejected (in the half-normal case) or overshoot and end up further from zero (in the abs case)
Looks a bit different when I run it with NUTS:
I think you're not up-to-date. I also ran it without transformation and Metropolis and it looks the same. Probably just very difficult to sample extremely close to 0.
I get essentially the same results with NUTS or metropolis (similar to those of @ririw and @twiecki ). I think part of the problem you are seeing is only due to visualization and not sampling. The Kernel Density Estimation implemented in SciPy does not take into account boundary effects. As a result underestimates values close to the boundaries (like 0). I have made a PR upstream to fix this problem. Once it get merged I will make the necessary changes into PyMC3.
@aloctavodia good catch:
Just updated by cloning the repo and installing from source, and the issue is resolved. Thanks!
Neither the
pm.HalfNormal
distribution nor taking the absolute value of a zero-meanpm.Normal
distribution seem to produce accurate half-normal distributions: