I am defining a custom distribution using the code below:
class Jeffreys(pm.Continuous): def __init__(self, lower, upper, **kwargs): self.lower = lower self.upper = upper self.mean = (upper + lower)/2 self.median = self.mean kwargs["testval"] = kwargs.pop("testval", self.mean) super(Jeffreys, self).__init__(**kwargs) def logp(self, value): lower = self.lower upper = self.upper normalization = 1. / pm.math.log(upper / lower) el = tt.log(normalization) - tt.log(value) return tt.switch(tt.or_(tt.gt(lower, value), tt.gt(value, upper)), -np.inf, el/2)
When using pm.sample with this distribution in the model, the lower and upper bounds are followed at every point. However, pm.find_MAP consistently goes below the lower bound, returning a logp of -inf. I can solve this problem by using arbitrarily large numbers in place of -np.inf, but I’m curious if there is anything I am doing wrong.