Code Monkey home page Code Monkey logo

Comments (9)

wo80 avatar wo80 commented on August 10, 2024 1

I just looked up the documentation of the Multiply method and I agree it's a bit sparse:

/// <summary>
/// Sparse matrix multiplication, C = A*B
/// </summary>
/// <param name="other">The sparse matrix multiplied to this instance.</param>
/// <returns>C = A*B</returns>
public CompressedColumnStorage<T> Multiply(CompressedColumnStorage<T> other)

Do you think changing the summary would be enough:

/// <summary>
/// Sparse matrix multiplication, C = A*B, where A is current instance.
/// </summary>

from csparse.net.

wo80 avatar wo80 commented on August 10, 2024

I haven't tested any of the code you provided, but the first issue I see is

var aSparse = new CSparseMatrix(a.RowCount, a.ColumnCount)

That would only be ok for a square matrix. If a.RowCount != a.ColumnCount, you should write

var aSparse = new CSparseMatrix(a.ColumnCount, a.RowCount)

Can you please test this and report back. If the problems reside, I'll have a closer look.

from csparse.net.

ChristoWolf avatar ChristoWolf commented on August 10, 2024

Hi @wo80!

Thanks for the quick help, that was it!
But I do not understand at all why this is needed.
Also, it gives the transposed matrix, so I would need to transpose my minimization problem.
No biggy, but still would like to understand the thought process behind this limitation.

from csparse.net.

wo80 avatar wo80 commented on August 10, 2024

You need to understand how the matrix entries are stored (see for example https://www.smcm.iqfr.csic.es/docs/intel/mkl/mkl_manual/appendices/mkl_appA_SMSF.htm).

MathNet uses CSR storage (matrix entries are stored row-wise) while CSparse uses CSC storarge (entries are stored column-wise). So if you take the CSR storage and just interpret it as CSC, it will represent the transposed matrix. This means, if your original matrix stored as CSR is m x n, then it will represent a n x m matrix in CSC.

Also, it gives the transposed matrix, so I would need to transpose my minimization problem. No biggy, but still would like to understand the thought process behind this limitation.

Yes, if you want to solve a least-squares problem, make sure that the CSparse m x n matrix has m >= n, so the MathNet matrix should be built as n x m. You can also feed matrices with m < n to SparseQR, but it will then compute the transposed matrix internally:

else
{
// Ax=b is underdetermined
var AT = A.Transpose();
var p = AMD.Generate(AT, order);
// Ordering and symbolic analysis
C.SymbolicAnalysis(AT, p, order == ColumnOrdering.Natural);
// Numeric QR factorization of A'
C.Factorize(AT, progress);
}

from csparse.net.

ChristoWolf avatar ChristoWolf commented on August 10, 2024

Thanks a ton for clarifying, seems that I really misunderstood a few things.

I am actually thinking about rewriting most of my code to use CSparse directly, the performance is incredible!

Do you think changing the summary would be enough:

Absolutely, that makes it very explicit.
The issue that I have with

The sparse matrix multiplied to this instance.

is that one could interpret it as left multiplication, as right multiplication is quite uncommon.

from csparse.net.

epsi1on avatar epsi1on commented on August 10, 2024

I am actually thinking about rewriting most of my code to use CSparse directly, the performance is incredible!

I think you are right. The CSparse.NET is a port of CSparse by Tim. Davis. If i remember right, CSparse.NET had reasonably good performance compared to original CSparse although the original one is in native C or C++.

from csparse.net.

wo80 avatar wo80 commented on August 10, 2024

@ChristoWolf

I am actually thinking about rewriting most of my code to use CSparse directly, the performance is incredible!

In case you were using the dense QR from MathNet (or even native MKL), the difference will be considerable. You can set up your matrix using the CSparse.NET CoordinateStorage class, so in case you aren't using any other parts from MathNet, switching should be easy.

The issue that I have with [...] is that one could interpret it as left multiplication, as right multiplication is quite uncommon.

Alright, I will make sure to add a note that the matrix A is multiplied by the other matrix from the right.

from csparse.net.

wo80 avatar wo80 commented on August 10, 2024

Please leave this issue open! I will close it with the next pull request.

from csparse.net.

ChristoWolf avatar ChristoWolf commented on August 10, 2024

Thanks a ton, @wo80!

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.