Reputation: 341
I'm trying to create a beta RV that behaves like the one in scipy. Namely, it takes an alpha
, beta
, loc
, and scale
. I followed the discussion on creating a shifted gamma, and came up with something that looks like this:
import pymc3 as pm
class SSBeta(pm.Beta):
def __init__(self, alpha, beta, loc, scale, *args, **kwargs):
# Not sure what this is doing but it won't work without it.
transform = pm.distributions.transforms.lowerbound(loc)
super().__init__(alpha=alpha, beta=beta, *args, **kwargs, transform=transform)
self.scale = scale
self.loc = loc
self.mean += loc
def random(self):
return super().random()*self.scale + self.loc
def logp(self, x):
return super().logp((x - self.loc)/self.scale)
So I have two questions:
random
, logp
)?Upvotes: 3
Views: 435
Reputation: 3682
An alternative is using pm.Deterministic
. This does not allow you to pass observed data, but might be what you want anyways?
mu, scale = 2, 4
with pm.Model():
b = pm.Beta('b', alpha=3, beta=8)
shifted_b = pm.Deterministic('shifted_b', scale * b + mu)
Upvotes: 1