美文网首页
Compute square root of a large s

Compute square root of a large s

作者: jjx323 | 来源:发表于2019-05-07 16:32 被阅读0次

In the studies of large scale inverse problems, we often meet a problem that is how to decompose a sparse positive definite matrix into its square root. In mathematical notations, we need to find a matrix A^{1/2} such that
A = A^{1/2}A^{1/2}.
For example A\in\mathbb{R}^{180000\times180000}, taking SVD according to the definition of $A^{1/2} is too time consuming.

We can employ the following iterative method proposed by Rice (1982)
X_{k+1} = X_{k} + \frac{1}{p}\left( A - X_{k}^{p} \right).
Here X_{k} will converge to A^{1/p}.

For implementing this iterative algorithm in Python, we give one in the following.

def sqrtMatrix(A, p, max_iter=10, approTol=1e-5):
    nx, ny = A.shape
    Xk = sps.eye(nx)*0.0
    
    for k in range(max_iter):
        temp = Xk
        for j in range(p-1):
            temp = temp@Xk
        Xk = Xk + (1/p)*(A - temp)                     
        ## set small elements to zeros to save memory
        row, col, vals = sps.find(Xk)
        index = (vals < approTol)
        rr, cc = row[index], col[index]
        Xk[rr, cc] = 0
        ## set small elements to zeros to save memory       
        print("Iterate number is ", k)
    
    return Xk

For large scale matrix, during the iteration, there are many small numbers appeared in X_k, which leads to not enough memory problem. So, we add four line of codes to set small elements to zero to save memory. By numerical experiments, the performance is acceptable.

相关文章

网友评论

      本文标题:Compute square root of a large s

      本文链接:https://www.haomeiwen.com/subject/ymcyoqtx.html