Code Monkey home page Code Monkey logo

Comments (4)

wo80 avatar wo80 commented on August 10, 2024

There is no such method. The reason is that setting a single value in a sparse matrix is very inefficient (involves a binary search and possibly memory reallocation).

The SparseMatrix class gives you public access to the ColumnPointers, RowIndices and Values arrays, so feel free to set the values directly, but usually there are better ways than accessing the values of a sparse matrix like that. Could you explain your use case?

from csparse.net.

Thiago-NovaesB avatar Thiago-NovaesB commented on August 10, 2024

My problem is the following:
I have to solve a sequence of sparse square linear systems. In each iteration, some coefficients will change. I have the row, column and new value for each coefficient that needs to change.
I used Mathnet's dense matrices, but with CSparse it greatly reduced the resolution time, but I think I can improve the problem modification time. I tried:

  1. Build the sparse matrix with Mathnet. In each iteration set the news values using Mathnet At operator, convert to CSparse and solve with CSparse.
  2. Construct the dense matrix with double[,]. In each iteration set the news values using Array At operator, convert to CSparse using OfArray and solve with CSparse.

The above approaches are pretty similar with (1) slightly better in my tests.

Is there a better way to do this?

from csparse.net.

wo80 avatar wo80 commented on August 10, 2024

In each iteration, some coefficients will change.

In what way do the values change exactly?

  • If you have a starting matrix A_0, is it an update like A_{i+1} = A_i + C_i? Then just build C_i and compute the sum.
  • If the non-zero pattern of the matrix doesn't change (meaning no new non-zeros are introduced during the iteration process), no memory allocations are needed and modifying the values directly might be efficient.

MathNet does provide the feature you are looking for in SparseCompressedRowMatrixStorage.cs, so you could either do the updates with MathNet and use the wiki example to compute the sparse factorization, or take the code and use it to create a similar method for CSparse.NET. I'll provide help, if necessary.

from csparse.net.

Thiago-NovaesB avatar Thiago-NovaesB commented on August 10, 2024

Thanks for the explanations about sparse structures. Despite having a mask of coefficients, they are not necessarily non-zero. So I can't modify just the values without having to reallocate memory. I think the combination of Array[,]+CSparse will be enough for me. Thank you for your help.

from csparse.net.

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.