While trying to build a simpler example to reproduce this error, I also managed to find what’s causing this error. Below code will reproduce the error:
import numpy as np
import pymc3 as pm
import theano.tensor as tt
class Linear(pm.distributions.transforms.ElemwiseTransform):
name = "linear"
def __init__(self, alpha, beta):
self.alpha = tt.as_tensor_variable(alpha)
self.beta = tt.as_tensor_variable(beta)
def forward(self, x):
return self.alpha * x + self.beta
def forward_val(self, x, point=None):
return self.alpha * x + self.beta
def backward(self, x):
return (1 / self.alpha) * (x - self.beta)
def jacobian_det(self, x):
return -tt.log(self.alpha)
obs = dict()
sig = 1.0
obs['x'] = np.random.normal(loc=10.0, scale=sig, size=1000)
alpha = 10
beta = 0
params_init = {'mu':0}
with pm.Model() as mdl:
mu = pm.Normal('mu', mu=0.0, sd=1.0, transform=Linear(alpha, beta))
x = pm.Normal('x', mu=mu, sd=1.0, observed=obs['x'])
trace = pm.sample(start=params_init, chains=1, cores=1)
If the start values are given for variable mu instead of mu_linear__ then this error occurs. Is this the expected behaviour? I understand that sampling is done on transformed variables but it is a bit confusing that initial values are to be defined for variable names which are never explicitly defined in the model.