Testval for gp.Latent cannot be theano.shared?

Apparently theano.shared does not work with pm.gp.Latent.prior for testval either. I tried to do the “using hold-out testing values” approach as suggested in the FAQ.

I’d like to do something like

J_init = theano.shared(np.zeros(n_coords))
gp = pm.gp.Latent(cov_func=cov)
J = gp.prior('J', X, testval=J_init)

I get the error

pymc3/distributions/distribution.py in default(self)
     60 
     61     def default(self):
---> 62         return np.asarray(self.get_test_val(self.testval, self.defaults), self.dtype)
numpy/core/numeric.py in asarray(a, dtype, order)
--> 531     return array(a, dtype, copy=False, order=order)
    532 
    533 

ValueError: setting an array element with a sequence.

because a = <TensorType(float64, vector)>

You should be able to give a testval that’s a numpy array. Are you trying to do predictions with the GP? If so, you need to use the conditional distribution.

Giving a Numpy array works, but I was trying to use a theano.shared node so that I could reuse the model as much as possible. I’m not trying to make predictions, I wanted to give a previously reconstructed (2D tomography) frame as an initial value to speed up convergence since it is expected that the next frame will be similar, but still different, so conditional is not directly applicable.

Should I perhaps change var.tag.test_value directly?

Right, I see what you mean now. You certainly could if that works for you. I think using a numpy array is the most well worn usage path here though.