Coder Social home page Coder Social logo

[Question❓] about pymatting HOT 1 CLOSED

rafiqulislam21 avatar rafiqulislam21 commented on August 19, 2024
[Question❓]

from pymatting.

Comments (1)

99991 avatar 99991 commented on August 19, 2024 1

Sounds like a bad idea, but if you know what you are doing, you can just use the ichol(A).L.todense(). Note that this is a colossal waste of memory and if all you want is to solve a linear system like $A x = L L^T x = b$, then you probably want to do decomposition = ichol(A); x = decomposition(b) instead, which executes backwards substitution on the sparse $L$ and $L^T$ efficiently:

def __call__(self, b):

Disclaimer: Bad example, don't do this!

import numpy as np
import scipy.sparse
from pymatting import ichol

# Create a symmetric, positive definite matrix
n = 100
np.random.seed(0)
A = np.random.rand(n, n)
# Remove a few values of A to make it more sparse
A[np.random.rand(*A.shape) < 0.98] = 0
A += A.T + n * np.eye(n)

A_sparse = scipy.sparse.csr_matrix(A)

decomposition = ichol(A_sparse, discard_threshold=0.0)

# This constructs a scipy.sparse.csr_matrix
L_sparse = decomposition.L

# The following is not recommended because it constructs
# a dense matrix from a sparse matrix, which is a colossal waste of memory.
# If you just want to solve a linear system like
# A x = L L^T x = b,
# call the decomposition object like `x = decomposition(b)`
L_dense = L_sparse.toarray()

# Compute element-wise mean squared error to dense Cholesky decomposition
mse = np.mean(np.square(L_dense - np.linalg.cholesky(A)))

# Should be very small
print(mse)

from pymatting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.