I have a theano covariance matrix, and i am trying to calculate element wise square of it. I have written following code for same:
import theano
a, b = theano.tensor.matrices('a', 'b')
square = theano.function([a, b], a * b)
sq = square(cov, cov)
where cov is covariance matrix, calculated as:
y1_pre = T.dot(self.x, self.W_left) + self.b_left
y1 = activation(y1_pre, self.hidden_activation)
y2_pre = T.dot(self.x, self.W_right) + self.b_right
y2 = activation(y2_pre, self.hidden_activation)
y1_mean = T.mean(y1, axis=0)
y1_centered = y1 - y1_mean
y2_mean = T.mean(y2, axis=0)
y2_centered = y2 - y2_mean
cov = T.sum(y1_centered[:, :, None] * y2_centered[:, None, :], axis=0)
But it is throwing following error:
TypeError: ('Bad input argument to theano function with name "cov.py:114" at index 0(0-based)', 'Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?')
I know it is trivial to do, but still could not find possible fix. Please help me in this regard.