问题
I would like to create a square matrix with the eigenvalues on the diagonal:
eigen_values, eigen_vectors = theano.tensor.nlinalg.eig(covariance_matrix)
D = T.nlinalg.AllocDiag(eigen_values)
However apparently theano does not treat the D matrix I created as a standard matrix, thus I cannot use it in the succeding computations.
theano.tensor.var.AsTensorError: ('Cannot convert <theano.tensor.nlinalg.AllocDiag object at 0x7face5708450> to TensorType', <class 'theano.tensor.nlinalg.AllocDiag'>)
回答1:
You're using an operation class as if it were an operation function.
Instead of
D = T.nlinalg.AllocDiag(eigen_values)
try
D = T.nlinalg.AllocDiag()(eigen_values)
or
D = T.nlinalg.alloc_diag(eigen_values)
来源:https://stackoverflow.com/questions/30692742/creating-square-matrix-with-eigenvalues-on-the-diagonal-in-theano