Large scale Optimization using Sparse?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone: I am working on large scale optimization using LINPROG, it has huge matrices of A,B,Aeq,Beq, it goes out of memory when I run it. The Matrices here have almost all zero elements in each row except for one or two columns in that row. I think using sparse matrix would help me resolve this problem but do I have to initialize the matrix as sparse before I start filling it up or after I have done so. Here matrices are filled as separate blocks so I am generalizing the row and column to be filled can this generalizing be done using sparse.? If anyone has a link or something illustrating an example for sparse matrix for large scale optimization please forward it to me at samirgupta@live.com
0 commentaires
Réponses (2)
Gabo
le 9 Juin 2011
You need to create a sparse matrix directly. If you try to create a full matrix and then convert it to sparse, you'll run out of memory. It has happened to me with large matrices.
See the examples in sparse. You can specify the location of the nonzero entries ( i and j ), the nonzero values ( s ), the size of the matrix ( m and n ) and the maximum number of nonzero elements in it ( nzmax ).
Gabo
le 10 Juin 2011
Without looking into all the details, the Code Analyzer seems to be recommending that you indicate the nonzero patter from the start, instead of declaring aeq as an empty sparse matrix, and then filling in the details.
Quick example. If your matrix looked like this:
aeq= [ 0.1 0 0 0 0;
0 0.1 0 0 0;
0 0 0 0.2 0;
0 0 0 0 0.2]
you can do
i=[1 2 3 4];
j=[1 2 4 5];
s=[0.1 0.1 0.2 0.2];
m=4;
n=5;
aeq = sparse(i,j,s,m,n);
In other words, maybe you can use the for loops to create the vectors i,j,s, and create the sparse matrix after the loops. By the way, note that instead of filling in a square block with a full identity matrix, you can save memory by filling in the diagonal elements only.
0 commentaires
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!