"""
cholsky decomp :
A = L * L'
or A = U' * U
' means conjugate transpose
"""
import numpy as np
C = [[4, -2, 4], [-2, 5, 0], [4, 0, 6]]
print('C:\n', C, 'C tranpose:\n', np.array(C).T)
L = np.linalg.cholesky(C) #对额米特正定矩阵的开平方,得到一个三角阵列;
print('Low mat:\n', L, '\nverify\n', L @ L.T)
print('Upper mat:\n', L.T, '\nverify\n', L.T.T @ L.T)
print('自行讲下三角矩阵转置就得到上三角了,同样满足U\' @ U得到原本矩阵')
import scipy.linalg as sla
U = sla.cholesky(C)
print('scipy.linalg.cholsky 同样的:只不过默认上三角输出\n', U)
C:
[[4, -2, 4], [-2, 5, 0], [4, 0, 6]] C tranpose:
[[ 4 -2 4]
[-2 5 0]
[ 4 0 6]]
Low mat:
[[ 2. 0. 0.]
[-1. 2. 0.]
[ 2. 1. 1.]]
verify
[[ 4. -2. 4.]
[-2. 5. 0.]
[ 4. 0. 6.]]
Upper mat:
[[ 2. -1. 2.]
[ 0. 2. 1.]
[ 0. 0. 1.]]
verify
[[ 4. -2. 4.]
[-2. 5. 0.]
[ 4. 0. 6.]]
自行讲下三角矩阵转置就得到上三角了,同样满足U’ @ U得到原本矩阵
scipy.linalg.cholsky 同样的:只不过默认上三角输出
[[ 2. -1. 2.]
[ 0. 2. 1.]
[ 0. 0. 1.]]