I couldn’t make the suggested shiftedExp code work, pymc has changed, but I found a CustomDist example which did work.
Just for the record:
– Malcolm
# Defined: https://www.pymc.io/projects/docs/en/v5.10.4/api/distributions/generated/pymc.CustomDist.html
from pytensor.tensor import TensorVariable
def shiftedExp(
lam: TensorVariable,
shift: TensorVariable,
size: TensorVariable,
) -> TensorVariable:
return pm.Exponential.dist(lam, size=size) + shift
with pm.Model() as linreg:
lam = pm.HalfCauchy('sigma', beta=10, initval=1.)
intercept = pm.Normal('Intercept', 0, sigma=20)
x_coeff = pm.Normal('Slope', 0, sigma=20)
likelihood = pm.CustomDist('y', lam, intercept + x_coeff * x, observed=y, dist=shiftedExp)
trace2 = pm.sample()