Large scale Optimization using Sparse?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Gabo
2011 年 6 月 9 日
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
2011 年 6 月 10 日
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 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!