tensorflow pseudo inverse doesn't work for complex matrices!

The Tensorflow documentation here says that:

tf.linalg.pinv is ''analogous to numpy.linalg.pinv. It differs only in default value of rcond''.

However, tf.linalg.pinv requires the matrix to be float type while np.linalg.pinv could be used with complex matrices.

I was wondering why they would only create it for float types and if there is a straightforward way to modify tf.linalg.pinv to be used with complex matrices.

Topic matrix numpy tensorflow python machine-learning

Category Data Science


I just faced the same situation. If you need to explicitly build the inverse, check this paper:

https://pdfs.semanticscholar.org/f278/b548b5121fd0d09c2e589439b97fad16ece3.pdf

In particular, given a Matrix M that you need to invert, you can just do:

    A = tf.math.real(M)
    C = tf.math.imag(M)

    r0  = tf.linalg.pinv(A) @ C
    y11 = tf.linalg.pinv(C @ r0 + A)
    y10 = -r0 @ y11

    M_inverse = tf.cast(tf.complex(y11,y10), dtype = M.dtype)

The complexity is a bit higher than the pure-complex implementation, but so far it has proven to be pretty stable for me.

(just copying my answer from your other post: https://stackoverflow.com/questions/60025950/tensorflow-pseudo-inverse-doesnt-work-for-complex-matrices/60128892#60128892)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.