fvar = tf.reshape(Kdiag, (-1,1)) + tf.reduce_sum(tf.reshape(tf.square(tf.transpose(A)), )[:,:,None] * (q_var[None, :,:] - 1),1)
elif q_sqrt.get_shape().ndims ==3:
// we have the cholesky form for q(v)
fvar = Kdiag[:,None] - tf.reduce_sum(np.square(A), 0)[:,None]
def f(w):
R = tf.triu(w)
RA = tf.matmul(R, A)
return tf.square(RA).sum(0)
After Change
//compute kernel stuff
num_data = tf.shape(X)[0]
Kdiag = kern.Kdiag(Xnew)
Kmn = kern.K(X, Xnew)
Kmm = kern.K(X) + eye(num_data)*1e-4
Lm = tf.cholesky(Kmm)
//this is O(N M^2)
A = tf.user_ops.triangular_solve(Lm, Kmn, "lower")
//construct the mean and variance of q(f)
fmean = tf.matmul(tf.transpose(A), q_mu)
if q_sqrt.get_shape().ndims==2:
//we hae a diagonal form for q(v)
q_var = np.square(q_sqrt)
//fvar = Kdiag[:,None] + tf.reduce_sum((tf.square(tf.transpose(A)))[:,:,None] * (q_var[None, :,:] - 1),1)
fvar = tf.reshape(Kdiag, (-1,1)) + tf.reduce_sum(tf.reshape(tf.square(tf.transpose(A)), )[:,:,None] * (q_var[None, :,:] - 1),1)
elif q_sqrt.get_shape().ndims ==3:
// we have the cholesky form for q(v)
fvar = Kdiag - tf.reduce_sum(np.square(A), 0)
fvar = tf.expand_dims(fvar, 1)
def f(w):
R = tf.triu(w)
RA = tf.matmul(R, A)
return tf.square(RA).sum(0)