Initialization for bounded random variable

I’ve created a custom distribution with the DensityDist class; the support of this distribution is 0 < x < 1.

I implemented this within my logpdf function using:

res = whatever
res = at.switch(at.gt(x, 1) | at.lt(x,0), -np.inf, res)
return res

However, when I use this as a prior and generate samples, the initialization fails because the sampler starts with negative values and I get a -infinity in my log-likelihood. Is there some way of getting around this?

You can set theinitval of a distribution so it starts at a valid point. But even better is to pass an interval transform to the distribution so that the sampler never proposes invalid values: pymc.distributions.transforms.Interval — PyMC 4.3.0+0.gea721e4a.dirty documentation