Ich habe eine Theano-Kovarianz-Matrix, und ich versuche, Element weise Quadrat davon zu berechnen. Ich habe folgenden Code für gleiche geschrieben:Elementweise Quadrat der Theano-Matrix
import theano
a, b = theano.tensor.matrices('a', 'b')
square = theano.function([a, b], a * b)
sq = square(cov, cov)
wo cov Kovarianzmatrix berechnet:
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)
Aber es wirft folgende Fehlermeldung:
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?')
Ich weiß, es ist trivial zu tun, konnte aber immer noch keine mögliche Lösung finden. Bitte helfen Sie mir in dieser Hinsicht.
Was ist 'cov'? – JeD
theano Kovarianz Matrix – Shweta
Haben Sie versucht mit 'sq = Quadrat (cov [:], cov [:])'? Ich assme theano Matrizen verhalten sich wie numpy Arrays? – JeD