Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentarios
Lorenco Santos Vasconcelos
Lorenco Santos Vasconcelos el 28 de Oct. de 2022
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
Lorenco Santos Vasconcelos el 28 de Oct. de 2022
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?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by