Tf.self_adjoint_eig does not work for covariance matrix

If I use tf.self_adjoint_eig to get my own representation of the covariance matrix, I get "Self-adjoint proper division was not successful [sic]. Input may be invalid."

Let's say that I bleach the data (and this is a tensorflow element, so I will not return to numpy svd), then an error occurs when using this code:

def whiten(x):
    x -= tf.reduce_mean(x, reduction_indices=[0])
    decomp = tf.stop_gradient(tf.self_adjoint_eig(tf.matmul(x, x, transpose_a=True)/n))
    evals = decomp[0, :]
    evecs = decomp[1:, :]
    xrot_scaled = tf.matmul(x, evecs)/(tf.sqrt(evals) + 1e-5)
    return tf.matmul(xrot_scaled, evecs, transpose_b=True)

In my opinion, entering tf.self_adjoint_eig is psd, so the solver should not have any problems. Ideas?

+4
source share

Source: https://habr.com/ru/post/1649636/


All Articles