tensorflow基础tf.cholesky分解_实对称正定矩阵的Cholesky分解(平方根分解、对称三角分解)
#coding:utf8
#Cholesky分解是一种分解矩阵的方法, 在线形代数中有重要的应用。
#Cholesky分解把矩阵分解为一个下三角矩阵以及它的共轭转置矩阵的乘积
#实数界来类比的话,此分解就好像求平方根
#与一般的矩阵分解求解方程的方法比较,Cholesky分解效率很高。
import numpy as np
import tensorflow as tf
sess = tf.InteractiveSession()
identity_matrix = tf.diag([1.0, 1.0, 1.0])
print(sess.run(tf.cholesky(identity_matrix)))
print "矩阵E"
#E = tf.convert_to_tensor(np.array([2.0, -2.0],[-2.0, 5.0]))
E = tf.convert_to_tensor(np.array([1.0, 2.0, 3.0],[2.0, 8.0, 8.0], [3.0, 8.0, 35.0]))
print(sess.run(E))
print "矩阵的cholesky分解下三角 L"
print(sess.run(tf.cholesky(E)))
print "矩阵的转置 U"
#矩阵的转置函数
print sess.run(tf.transpose(tf.cholesky(E)))
print "矩阵E = LU"
print sess.run(tf.matmul(tf.cholesky(E),tf.transpose(tf.cholesky(E))))
sess.close()
#Cholesky分解是一种分解矩阵的方法, 在线形代数中有重要的应用。
#Cholesky分解把矩阵分解为一个下三角矩阵以及它的共轭转置矩阵的乘积
#实数界来类比的话,此分解就好像求平方根
#与一般的矩阵分解求解方程的方法比较,Cholesky分解效率很高。
import numpy as np
import tensorflow as tf
sess = tf.InteractiveSession()
identity_matrix = tf.diag([1.0, 1.0, 1.0])
print(sess.run(tf.cholesky(identity_matrix)))
print "矩阵E"
#E = tf.convert_to_tensor(np.array([2.0, -2.0],[-2.0, 5.0]))
E = tf.convert_to_tensor(np.array([1.0, 2.0, 3.0],[2.0, 8.0, 8.0], [3.0, 8.0, 35.0]))
print(sess.run(E))
print "矩阵的cholesky分解下三角 L"
print(sess.run(tf.cholesky(E)))
print "矩阵的转置 U"
#矩阵的转置函数
print sess.run(tf.transpose(tf.cholesky(E)))
print "矩阵E = LU"
print sess.run(tf.matmul(tf.cholesky(E),tf.transpose(tf.cholesky(E))))
sess.close()
![]() |
还没人转发这篇日记