You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Pymc3 Devs,
I've hit a strange error when trying to sample_ppc.
It appears that somewhere in the theano graph a NoneConst is being created, and sample_posterior_predictive throws an error when it tries to sample from it.
In the example below, the simple mean model has set of mean parameters with a dimension for a factor (x), a dimension for another factor (g), and a dimension for a single y output (although this problem also occurs when y has a cardinality of 2 or more). Both g and x are used to pick a specific parameter as a y datapoint's mean.
I think this is something to do with funny broadcasting, because when I don't include they y dimension in my parameters, there is no issue (see note in code).
It could be something i'm doing wrong, but regardless, the error thrown is very hard to debug, and could maybe be improved.
An example:
#create some datan_d=500n_x=2n_g=10g=np.random.randint(0, n_g, (n_d,)) # groupx=np.random.randint(0, n_x, (n_d,)) # x factortrue_x_effect=np.random.normal(0, 10, (n_x,))
true_g_effect=np.random.normal(0, 10, (n_g,))
y=np.random.normal(true_x_effect[x]+true_g_effect[g], 1)
data=pd.DataFrame({'x':x, 'y1':y, 'g':g})
y_vars= ['y1']
n_y=len(y_vars)
withpm.Model() asmodel:
multi_dim_rv=pm.Normal('multi_dim_rv', mu=0, sd=1, shape=(n_x, n_g, n_y))
indexed_rv=multi_dim_rv[data['x'], data['g'], :] #if : is replaced by 0 (effectivly removing y dimention), this works fineerror=pm.HalfCauchy('error', 10)
obs_data=data[y_vars].valuesobs=pm.Normal('obs', mu=indexed_rv, sd=error, observed=obs_data)
print('dist_shape', obs.distribution.logp(data[y_vars].values).tag.test_value.shape) #shapes seem okprint('data_shape', obs_data.shape) #shapes seem oktrace=pm.sample() #samples fine.pm.sample_posterior_predictive(trace) #NoneConst error here.
Thanks for reporting! The problem is that _draw_value does some type checks but we did not consider theano.gof.graph.Constants. It should be easy to fix but in the mean time, your model can work perfectly if you just drop the colon when you create indexed_rv like this:
indexed_rv=multi_dim_rv[data['x'], data['g']] # The colon : is implicit
Hi Pymc3 Devs,
I've hit a strange error when trying to sample_ppc.
It appears that somewhere in the theano graph a NoneConst is being created, and sample_posterior_predictive throws an error when it tries to sample from it.
In the example below, the simple mean model has set of mean parameters with a dimension for a factor (x), a dimension for another factor (g), and a dimension for a single y output (although this problem also occurs when y has a cardinality of 2 or more). Both g and x are used to pick a specific parameter as a y datapoint's mean.
I think this is something to do with funny broadcasting, because when I don't include they y dimension in my parameters, there is no issue (see note in code).
It could be something i'm doing wrong, but regardless, the error thrown is very hard to debug, and could maybe be improved.
An example:
Trace:
Versions and main components
I also asked this question on discourse
The text was updated successfully, but these errors were encountered: