convert edge list to adjacency matrix
1 回表示 (過去 30 日間)
古いコメントを表示
How to convert an edge list with 5000000 nodes to adjacency matrix in Matlab. I tried the following code:
fid = fopen('C:\myfile.txt', 'r');
E = fscanf(fid, '%g %g', [2 inf]);
E=E';
adj=sparse(E(:,1),E(:,2),1);
adj=full(adj);
fclose(fid);
I am getting memory error. Is there any way out?
回答 (1 件)
Walter Roberson
2017 年 3 月 27 日
A non-sparse adjacency matrix with 5 x 10^6 members in it would require a minimum of (5 * 10^6)^2 = 25 * 10^12 bytes, which would be about 22 3/4 petabytes. If you have that much memory available, then you should change your code from
adj=sparse(E(:,1),E(:,2),1);
to
adj = sparse(E(:,1), E(:,2), true);
to create a sparse logical array; then when you do the full() it will be a logical array that is created instead of a double array.
Note: many of the common algorithms you would want to apply to such as matrix will likely require that the data be converted to floating point, and will probably need temporary storage as large as that floating point array, so if you run out of memory using sparse() the way you are calling it now, chances are good that using a logical array instead of a double array will not reduce your memory problems enough to be able to do useful work.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!