在python中使用CVXOPT查看稀疏cholesky分解

2024-05-23 17:28:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图写一些代码,给定一个稀疏的平方矩阵M,使用PYTHON 3.5中的CVXOPT包计算它的稀疏cholesky分解,形式为PMP'=LL'(其中'表示转置,p是置换矩阵,L是下三角)

经过the documentation for ^{}我已设法做到以下几点:

import CVXOPT
from CVXOPT import cholmod

# Set the CVXOPT options so that the factorization computed is LL' not LDL'
cholmod.options['supernodal']=2

# Makes an expression describing the factorization to be computed
F=cholmod.symbolic(M) 

# Numerically compute the factorization and store the result in F
cholmod.numeric(M, F) 

# Solve LX=M to obtain L'
L=cholmod.spsolve(F, M, sys=4)

我想这会输出矩阵L(或者更确切地说是L'),这就是我想要得到的。然而,当我试图检查LL'=M时,我发现我的输出矩阵不是L'

print(L*cvxopt.spmatrix.trans(L)-M) # Should equal a matrix of zeros, but doesn't

我真的很困惑,在任何地方都看不到如何从存储在F中的符号表示中打印/获取矩阵L。任何熟悉CVXOPT/的人都能看出我在这方面做错了什么吗?我想要的是矩阵L(如果有人知道怎么做,排列P也会很有用!)。任何帮助都将不胜感激


Tags: theto代码importdocumentation矩阵形式options