-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
I have a problem with the shape parameter, that doesn't get updated when I update a shared variable. This is a toy example: it doesn't make so sense by itself but it is to reproduce the error.
from pymc3.distributions import distribution
from theano import shared
class CAR2(distribution.Continuous):
def __init__(self, mu, *args, **kwargs):
super(CAR2, self).__init__(*args, **kwargs)
self.mean = mu
def logp(self, x):
return tt.sum(continuous.Normal.dist(mu=0, tau=0.001).logp(x))
df = pd.read_csv('data_bug.csv')[['land_use_mix3', 'y']]
train_index = list(range(df.values.shape[0]-1))
test_index = [df.values.shape[0]-1]
X_shared = shared(df[['land_use_mix3']].values[train_index, :][:, 0])
y_shared = shared(df['y'].values[train_index])
with pm.Model() as pooled_model:
coeffs = pm.Normal('asd', mu=0, tau=0.001)
mu_phi = CAR2('mu_phi', shape=X_shared.get_value().shape[0], mu=tt.zeros(X_shared.get_value().shape[0]))
mu = tt.exp(X_shared.ravel() * coeffs + mu_phi)
obs = pm.Poisson('obs', mu=mu, observed=y_shared)
pooled_trace = pm.sample(100, njobs=1, tune=100)
X_shared.set_value(df[['land_use_mix3']].values[test_index, :][:, 0])
y_shared.set_value(df['y'].values[test_index])
ppc = pm.sample_ppc(pooled_trace, samples=1000, model=pooled_model)
the problem is with shape parameter of CAR2, which stays = to 76 but it should be shape=1 after the update.
ValueError: Input dimension mis-match. (input[0].shape[0] = 1, input[2].shape[0] = 76)
Apply node that caused the error: Elemwise{Composite{exp(((i0 * i1) + i2))}}(<TensorType(float64, vector)>, InplaceDimShuffle{x}.0, mu_phi)
Toposort index: 1
Inputs types: [TensorType(float64, vector), TensorType(float64, (True,)), TensorType(float64, vector)]
Inputs shapes: [(1,), (1,), (76,)]
Inputs strides: [(8,), (8,), (8,)]
Inputs values: [array([-1.30698299]), array([-1.67981393]), 'not shown']
Outputs clients: [['output']]
file:
Metadata
Metadata
Assignees
Labels
No labels