3
$\begingroup$

I have a new clustering and linkage approach that I am testing. My algorithm detected 13 clusters when in reality there are three. I am using linkage to merge clusters by dissimilarity. That is, I initially compute the pairwise dissimilarity between all 13 clusters and then merge the two that are the most similar. I repeat this step until only one cluster remains and then examine the dissimilarity levels at each stage.

I have the following two lists in Mathematica:

DissData={0.0312488, 0.0524895, 0.064099, 0.0686212, 0.0961492, 0.102107, 0.103257, 0.125655, 0.133191, 0.162344, 0.327446, 0.546044};

WhichOneGotMerged={{5, 6}, {10, 11}, {2, 4}, {6, 9}, {5, 8}, {6, 8}, {2, 3}, {4, 5}, {2, 4}, {2, 4}, {1, 3}, {1, 2}};

The DissData list at each position contains the dissimilarity between the corresponding clusters in that position in WhichOneGotMerged. That is, at step one, clusters 5 and 6 were merged as they were the most similar with a dissimilarity level of only 0.0312. Their new cluster is relabeled cluster 5 then cluster 7 becomes labeled cluster 6 and so on until cluster 13 becomes cluster 12. Then it is repeated and cluster 10 is merged with cluster 11. And so on...

I want to plot a dendrogram, preferably using the existing Dendrogram function which will outline this process and will display the original labels of each cluster. Simply taking Dendrogram[DissData] won't work as it won't keep the labels.

Any ideas as to a direction to take this would be very appreciated. Cheers S.E.!

$\endgroup$

1 Answer 1

4
$\begingroup$

To construct the dendogram with the origial numbering (1,2,3..) we must undo the arithmetic that leads to WhichOneGotMerged. First, we must reverse WhichOneGotMerged (dat1) because the last merge appears at the end. dat2 is the final numbering used in WhichOneGotMerged. Then we must undo the renumbering and insert the deleted element in dat1 and dat2.

dat1 = Reverse[WhichOneGotMerged];
n = 11;
dat2 = Range[n];
Do[
 {t1, t2} = dat1[[i]];
 dat2[[t2 ;;]] = dat2[[t2 ;;]] /. x_ /; x >= t2 :> x + 1;
 dat1[[i + 1 ;;]] = dat1[[i + 1 ;;]] /. x_ /; x >= t2 :> x + 1;
 dat2 = Insert[dat2, t2, t2];
 , {i, Length[dat1]}]

dat1 contains now the merges in the original numbering dat2 (simply 1,2,3,...). With this we can draw the dendrogram:

Dendrogram[dat1]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.