Hello,
I have 2 questions and would very grateful for some help.
-
In the below model how do I change the p parameter in the Categorical for out of sample prediction? I have attempted with a shared variable but it doesn’t seem to do anything.
-
Say my out of sample data had 4 data points instead of the 20 in the training. How can I get categorical to swallow the dimension change?
Many thanks!!
from theano import shared
import pymc3 as pm
import numpy as np
x_data = shared( np.random.rand(20,5,3) )
y_data = shared( 2 * np.argmax(x,axis=2) + (np.random.rand(20,5) -0.5) )
with pm.Model() as cmodel:
c = pm.Categorical('cat',p=x_data,shape=(20,5))
beta = pm.Exponential('beta',1)
y = pm.Normal('y',mu=beta*c,sd=1,observed=y_data)
t1 = pm.sample()
#predict
res1 = pm.sample_posterior_predictive(t1,100)
# favour category 0
c0 = np.zeros((20,5,3)) + 0.01
c0[:,:,0] = 1
x_data.set_value(c0)
#predict again
res2 = pm.sample_posterior_predictive(t1,100)
print( res1['y'].mean(0).mean() , res2['y'].mean(0).mean() )