Is there a way of creating a MLGraph from only linearized upper triangular of a symmetric adjacency matrix to save memory?

2 次查看(过去 30 天)
Hi! I have the elements of an upper triangular part of a symmetric adjacency matrix and like this
a b d g
x c e h
x x f i
and the numbers are linearized like H = [a b c d e f g i]
And I need to create a MLGraph using matlab.internal.graph.MLGraph() function but I do not want to transform de H array into a full square symmetric matrix to save memory.
I could do this with
adjacency_matrix(triu(true(n))) = H;
diag = 1:n+1:n^2;
adjacency_matrix = adjacency_matrix + adjacency_matrix';
adjacency_matrix(diag) = adjacency_matrix(diag)/2;
but I'm working with very large arrays and need to save memory...
How could I pass just the linearized upper triangular elements H to matlab.internal.graph.MLGraph() and get the same result as of using the full matrix?
  14 个评论
Lorenco Santos Vasconcelos
For completeness, I'm sharing the entire function I'm trying to optimize for speed and memory.
It receives a large matrix of zscored data X(n_samples,n_features) of sizes like 50,000 x 15 and also receives the array of labels for each sample in X and an array of the clusters. This big matrix is generated once in each worker with WorkerObjWrapper...
This data in X was clustered by a method like DBSCAN. I make a lot of combinations of clustering varying the features. Like 10.000 different clustering combinations and call this function DBCV2 to evaluate the quality of each one. So this function is heavy processing (like 80-100 seconds per call) and called multiple times (10.000 times), so I'm calling it from a parfor loop. That is the reason I need to save memory, because I was getting things like 40 GB on each worker. Now I reduced to 15-20 GB per worker.
So this is it. The trade off between fast vectorized code and low memory usage code but slow
Lorenco Santos Vasconcelos
One more complement... The big trouble is in the first execution in all workers because they all start runing almost in the same time and all allocate lots of memory. Then, one each call of the function lasts a different time, the next iterations will not be at same time and not all workers will allocate memory togheter.
I think this can be resolved like delaying a little bit only the first execution of each worker? Can this be done? How could I apply different delay on only the first execution of each worker?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by