Python中的Dense Cholesky更新 [英] Dense Cholesky update in Python

查看:336
本文介绍了Python中的Dense Cholesky更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我一个允许我对python(numpy)中的Cholesky分解执行低级更新的库/代码吗? Matlab将此功能作为称为"cholupdate"的功能提供. LINPACK也具有此功能,但是(据我所知)它尚未移植到LAPACK,因此在例如肮脏的.

Could anyone point me to a library/code allowing me to perform low-rank updates on a Cholesky decomposition in python (numpy)? Matlab offers this functionality as a function called 'cholupdate'. LINPACK also has this functionality, but it has (to my knowledge) not yet been ported to LAPACK and hence isn't available in e.g. scipy.

我发现scikits.sparse提供了基于CHOLMOD的类似功能,但是我的矩阵很密集.

I found out that scikits.sparse offers a similar function based on CHOLMOD, but my matrices are dense.

是否有适用于python且具有与numpy兼容的'cholupdate'功能的代码?

Is there any code available for python with 'cholupdate''s functionality that's compatible with numpy?

谢谢!

推荐答案

这里是一个Python程序包,它使用Cython对Cholesky因素进行了第1次更新和降级: https://github.com/jcrudy/choldate

Here is a Python package that does rank 1 updates and downdates on Cholesky factors using Cython: https://github.com/jcrudy/choldate

示例:

from choldate import cholupdate, choldowndate
import numpy

#Create a random positive definite matrix, V
numpy.random.seed(1)
X = numpy.random.normal(size=(100,10))
V = numpy.dot(X.transpose(),X)

#Calculate the upper Cholesky factor, R
R = numpy.linalg.cholesky(V).transpose()

#Create a random update vector, u
u = numpy.random.normal(size=R.shape[0])

#Calculate the updated positive definite matrix, V1, and its Cholesky factor, R1
V1 = V + numpy.outer(u,u)
R1 = numpy.linalg.cholesky(V1).transpose()

#The following is equivalent to the above
R1_ = R.copy()
cholupdate(R1_,u.copy())
assert(numpy.all((R1 - R1_)**2 < 1e-16))

#And downdating is the inverse of updating
R_ = R1.copy()
choldowndate(R_,u.copy())
assert(numpy.all((R - R_)**2 < 1e-16))

这篇关于Python中的Dense Cholesky更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆