Custom Weibull distribution

By the way, it looks like you’re using a shifted version of the Weibull. I think the right way of doing thi sis actually to use the Transform API. Shockingly, translation and scaling are not default transforms (?? @junpenglao) but it’s easy to implement:

class Translate(pm.Transform):
  def __init__(self, v):
    self.v_ = v

  def forward(self, x):
    return x + self.v_

  def forward_val(self, x):
    return x + self.v_

  def backward(self, z):
    return x - self.v_

  def jacobian_det(self, x):
    return 0. * x  # log(1) = 0

  def apply(self, dist):
    return TransformedDistribution.dist(dist, self)

with pm.Model() as model:
  l = pm.Gamma('l_pr', 3.)
  a = pm.Gamma('a_pr', 3.)
  b = pm.Gamma('b_pr', 3.)
  shift = Translate(l)
  weib = shift.apply(pm.Weibull('base', a, b))

Now you even have access to the distribution’s logp function and RNG!

1 Like