user27886
user27886

Reputation: 582

Possible tensorflow cholesky_solve inconsistency?

I am trying to solve a linear system of equations using tensorflow.cholesky_solve and I'm getting some unexpected results.

I wrote a script to compare the output of a very simple linear system with simple matrix inversion a la tensorflow.matrix_inverse, the non-cholesky based matrix equation solver tensorflow.matrix_solve, and tensorflow.cholesky_solve.

According to my understanding of the docs I've linked, these three cases should all yield a solution of the identity matrix divided by 2, but this is not the case for tensorflow.cholesky_solve. Perhaps I'm misunderstanding the docs?

import tensorflow as tf

I = tf.eye(2, dtype=tf.float32)
X = 2 * tf.eye(2, dtype=tf.float32)
X_inv = tf.matrix_inverse(X)
X_solve = tf.matrix_solve(X, I)
X_chol_solve = tf.cholesky_solve(tf.cholesky(X), I)

with tf.Session() as sess:
    for x in [X_inv, X_solve, X_chol_solve]:
        print('{}:\n{}'.format(x.name, sess.run(x)))
        print

yielding output:

MatrixInverse:0:
[[ 0.5  0. ]
 [ 0.   0.5]]

MatrixSolve:0:
[[ 0.5  0. ]
 [ 0.   0.5]]

cholesky_solve/MatrixTriangularSolve_1:0:
[[ 1.  0.]
 [ 0.  1.]]


Process finished with exit code 0

Upvotes: 1

Views: 286

Answers (1)

MWB
MWB

Reputation: 12567

I think it's a bug. Notice how the result doesn't even depend on the RHS, unless RHS = 0, in which case you get nan instead of 0. Please report it on GitHub.

Upvotes: 1

Related Questions