简体   繁体   中英

Creating and using a sparse matrix in Accord.NET

I would appreciate any hint on how to generate a sparse matrix in Accord.NET or in C#, without creating a library from scratch. The problem is that I want to make a matrix of size 30k by 30k representing the adjacency matrix of a graph, which will be almost always sparse. Past 15000 rows or columns, the following code generates an error:

var A = new double[n, n];

error: Array dimensions exceeded supported range.

ps. I am aware of the Sparse Class but as can be seen from the description, this class can only be used to make sparse vectors, not matrices.

If it is possible to make a sparse matrix, then the next immediate question is can it be treated like a normal matrix in Linear Algebraic operations, eg in subtracting two matrices, or finding a sub-matrix using:

Accord.Math.Matrix.Get(A, IVI, BVI, B);

30kx30k isn't very much.. Try change in your project properties in "Build", "Prefer 32 bit" to unchecked, then you can also try this code: Process.GetCurrentProcess().MaxWorkingSet = new IntPtr(262144000); Process.GetCurrentProcess().MinWorkingSet = new IntPtr(209715200); to your method, it may help if there is problem with memory to make this array.

Anyway you can use for this MathNet downloadavble via Nuget. Exactly sparse matrix from MathNet.Numerics.LinearAlgebra.Double MathNet.Numerics.LinearAlgebra.Double.SparseMatrix M = new MathNet.Numerics.LinearAlgebra.Double.SparseMatrix(30000); This Math.Net look slow to me, Accord is better in some operations and I dont know how to do sparse matrix in Accord which I would rather use than MathNet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM