Skip to content

Instantly share code, notes, and snippets.

@dousuguang
Forked from omitakahiro/SparseCholesky.md
Created April 4, 2022 13:36
Show Gist options
  • Select an option

  • Save dousuguang/61d6aefdd32dbf4742ab83acc382e542 to your computer and use it in GitHub Desktop.

Select an option

Save dousuguang/61d6aefdd32dbf4742ab83acc382e542 to your computer and use it in GitHub Desktop.

Revisions

  1. @omitakahiro omitakahiro revised this gist Feb 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ Scipy does not currently provide a routine for cholesky decomposition of a spars

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that A = LL^T.

    ~~~
    ~~~python
    from scipy.sparse import linalg as splinalg
    import scipy.sparse as sparse
    import sys
  2. @omitakahiro omitakahiro revised this gist Jan 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ import sys
    def sparse_cholesky(A): # The input matrix A must be a sparse symmetric positive-definite.
    n = A.shape[0]
    LU = splinalg.splu(A,diag_pivot_thresh=0)
    LU = splinalg.splu(A,diag_pivot_thresh=0) # sparse LU decomposition
    if ( LU.perm_r == np.arange(n) ).all() and ( LU.U.diagonal() > 0 ).all(): # check the matrix A is positive definite.
    return LU.L.dot( sparse.diags(LU.U.diagonal()**0.5) )
  3. @omitakahiro omitakahiro revised this gist Jan 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to rely on another external package such as scikit.sparse for the purpose. Here I implement cholesky decomposition of a sparse matrix only using scipy functions.
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to rely on another external package such as scikit.sparse for the purpose. Here I implement cholesky decomposition of a sparse matrix only using scipy functions. Our implementation relies on sparse LU deconposition.

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that A = LL^T.

  4. @omitakahiro omitakahiro revised this gist Nov 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to rely on another external package such as scikit.sparse for the purpose. Here I implement cholesky decomposition of a sparse matrix only using scipy functions.

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that $A = LL^T$.
    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that A = LL^T.

    ~~~
    from scipy.sparse import linalg as splinalg
  5. @omitakahiro omitakahiro revised this gist Nov 27, 2019. No changes.
  6. @omitakahiro omitakahiro revised this gist Nov 22, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to use another external package such as scikit.sparse. Here I implement cholesky decomposition of a sparse matrix only using scipy.
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to rely on another external package such as scikit.sparse for the purpose. Here I implement cholesky decomposition of a sparse matrix only using scipy functions.

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that $A = LL^T$.

  7. @omitakahiro omitakahiro revised this gist Nov 22, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,11 @@ import scipy.sparse as sparse
    import sys
    def sparse_cholesky(A): # The input matrix A must be a sparse symmetric positive-definite.
    n = A.shape[0]
    LU = splinalg.splu(A,diag_pivot_thresh=0)
    if ( LU.perm_r == np.arange(n) ).all() and ( LU.U.diagonal() > 0 ).all():
    if ( LU.perm_r == np.arange(n) ).all() and ( LU.U.diagonal() > 0 ).all(): # check the matrix A is positive definite.
    return LU.L.dot( sparse.diags(LU.U.diagonal()**0.5) )
    else:
    sys.exit('The matrix is not positive definite')
  8. @omitakahiro omitakahiro revised this gist Nov 22, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to use another external package such as scikit.sparse. Here I implement cholesky decomposition of a sparse matrix only using scipy.

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that $$A = LL^T$$.
    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that $A = LL^T$.

    ~~~
    from scipy.sparse import linalg as splinalg
  9. @omitakahiro omitakahiro created this gist Nov 22, 2019.
    19 changes: 19 additions & 0 deletions SparseCholesky.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to use another external package such as scikit.sparse. Here I implement cholesky decomposition of a sparse matrix only using scipy.

    The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that $$A = LL^T$$.

    ~~~
    from scipy.sparse import linalg as splinalg
    import scipy.sparse as sparse
    import sys
    def sparse_cholesky(A): # The input matrix A must be a sparse symmetric positive-definite.
    n = A.shape[0]
    LU = splinalg.splu(A,diag_pivot_thresh=0)
    if ( LU.perm_r == np.arange(n) ).all() and ( LU.U.diagonal() > 0 ).all():
    return LU.L.dot( sparse.diags(LU.U.diagonal()**0.5) )
    else:
    sys.exit('The matrix is not positive definite')
    ~~~