我有一个 theano 协方差矩阵,我正在尝试计算它的元素平方。我已经为此编写了以下代码:
import theano
a, b = theano.tensor.matrices('a', 'b')
square = theano.function([a, b], a * b)
sq = square(cov, cov)
其中 cov 是协方差矩阵,计算如下:
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)
但它抛出以下错误:
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?')
我知道这很简单,但仍然找不到可能的解决方法。请在这方面帮助我。