最详细的 tf.cholesky_solve(chol, rhs, name=None)函数和tf.matrix_solve(matrix, rhs, adjoint=None, name=None)

1.tf.cholesky_solve(chol, rhs, name=None)
功能:对方程‘AX=R’进行cholesky求解。

例:

import numpy as np
import tensorflow as tf
sess = tf.Session()

A = tf.constant([2, -2, -2, 5],shape=[2,2],dtype=tf.float64)
chol = tf.cholesky(a)
R=tf.constant([3,10],shape=[2,1],dtype=tf.float64)
x=tf.cholesky_solve(chol,R)
print(sess.run(x))

x==>[[5.83333333]
     [4.33333333]] #A*X=R
  1. tf.matrix_solve(matrix, rhs, adjoint=None, name=None)
    功能:求线性方程组,A*X=R。adjoint:是否对matrix转置。
    例:
import numpy as np
import tensorflow as tf
sess = tf.Session()

A = tf.constant([2, -2, -2, 5],shape=[2,2],dtype=tf.float64)
R=tf.constant([3,10],shape=[2,1],dtype=tf.float64)
x=tf.matrix_solve(A,R)
print(sess.run(x))

x==>[[5.83333333]
     [4.33333333]]
  1. tf.cholesky(input, name=None)
    功能:进行cholesky分解,即把一个对称正定的矩阵表示成一个下三角矩阵L和其转置的乘积的分解。 A = Z × Z T A=Z\times Z^{T}
    输入:注意输入必须是正定矩阵。
    例:
import numpy as np
import tensorflow as tf
sess = tf.Session()

A= tf.constant([2, -2, -2, 5],shape=[2,2],dtype=tf.float64)
Z = tf.cholesky(a)
print(sess.run(Z))

Z==>[[ 1.41421356  0.        ]
     [-1.41421356  1.73205081]]

猜你喜欢

转载自blog.csdn.net/weixin_38632246/article/details/86713494