Dense Cholesky update in Python

前端 未结 3 1716
轮回少年
轮回少年 2021-02-09 01:36

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 cal

3条回答
  •  余生分开走
    2021-02-09 02:04

    This should do a rank-1 update or downdate on numpy arrays R and x with sign '+' or '-' corresponding to update or downdate. (Ported from MATLAB cholupdate at the Wikipedia page: http://en.wikipedia.org/wiki/Cholesky_decomposition):

    def cholupdate(R,x,sign):
        import numpy as np
          p = np.size(x)
          x = x.T
          for k in range(p):
            if sign == '+':
              r = np.sqrt(R[k,k]**2 + x[k]**2)
            elif sign == '-':
              r = np.sqrt(R[k,k]**2 - x[k]**2)
            c = r/R[k,k]
            s = x[k]/R[k,k]
            R[k,k] = r
            if sign == '+':
              R[k,k+1:p] = (R[k,k+1:p] + s*x[k+1:p])/c
            elif sign == '-':
              R[k,k+1:p] = (R[k,k+1:p] - s*x[k+1:p])/c
            x[k+1:p]= c*x[k+1:p] - s*R[k, k+1:p]
          return R
    

提交回复
热议问题