using a dendrogramm to cluster columns of a matrix with complex entries

5 visualizaciones (últimos 30 días)
Gabriel Seidl
Gabriel Seidl el 26 de En. de 2021
Respondida: arushi el 5 de Sept. de 2024
Hello!
For my research, I am trying to find a suitable method for finding collinear columns in a noisy matrix C. I want to try out different algorithms for this task, and one I would like to test is the dendrogramm function. The dendrogramm function is clustering the rows, therefore I am taking the transpose of the matrix C.' to group the columns, and using the following code:
tree = linkage(C.', 'average', 'correlation')
dendrogramm(tree)
My problem is now, that my matrix is containing complex numbers, and I want to cluster the columns by their inner product. However, MATLAB returns the following error:
Error using internal.stats.linkagemex
Function linkagemex only supports real input.
Error in linkage (line 259)
Z = internal.stats.linkagemex(Y,method,pdistArg, memEff);
Error in dendro(line 14)
tree = linkage(C.', 'average', 'correlation');
Apparently, the linkage function that generates the tree for the dendrogramm is only accepting real data. Do I need to rewrite the linkage function for my purposes, or is there a smoother way to work this out?
Thanks in advance for your help.
EDIT: Typo

Respuestas (1)

arushi
arushi el 5 de Sept. de 2024
Hi Gabriel,
Since the linkage function in MATLAB doesn't support complex numbers directly, you'll need to find a workaround. One approach is to create a custom distance matrix that computes the distances between columns based on the inner product for complex numbers, and then use this distance matrix with the linkage function.
Here's a step-by-step approach to achieve this:
  1. Compute the distance matrix manually using the inner product for complex numbers. The distance between two columns can be defined as 1 - abs(inner_product(col_i, col_j)), where inner_product(col_i, col_j) is the normalized inner product between column i and column j. The normalization ensures that the result lies between 0 and 1, which is suitable for clustering.
  2. Once you have the distance matrix, you can use it with the linkage function by passing the matrix as an argument.
  3. Use the resulting linkage matrix to create a dendrogram.
Here's how you might implement this in MATLAB:
% Assuming C is your complex matrix
% Step 1: Compute the distance matrix based on the inner product
n = size(C, 2); % Number of columns
distanceMatrix = zeros(n, n);
for i = 1:n
for j = i+1:n
% Compute the normalized inner product
innerProd = (C(:, i)' * C(:, j)) / (norm(C(:, i)) * norm(C(:, j)));
% Compute the distance
distanceMatrix(i, j) = 1 - abs(innerProd);
distanceMatrix(j, i) = distanceMatrix(i, j); % The matrix is symmetric
end
end
% Step 2: Use the distance matrix with the linkage function
% Convert the distance matrix into a format suitable for linkage
squareformDistance = squareform(distanceMatrix);
tree = linkage(squareformDistance, 'average');
% Step 3: Create a dendrogram
dendrogram(tree);
This code snippet computes a custom distance matrix for the complex matrix C, where the distance between the columns is based on their inner product. This distance matrix is then converted to a vector form suitable for the linkage function using squareform. The resulting linkage matrix is used to create a dendrogram.
Take a look at the following documentations which might be helpful:

Community Treasure Hunt

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

Start Hunting!

Translated by