Custom Dendrogram Ordering Implementation
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,I'm trying to implement a custom ordering of a dendrogram (obtained using the linkage function) based on the rule that the "highest" branch has to be always on the right side. As an example:
%generate a tree using linkage
rng('default'); %for reproducibility
X = rand(10,2);
D = pdist(X);
tree = linkage(D,'average');
%my desired order
myOrd = [1,4,5,8,9,2,10,3,6,7];
%plot
figure();
subplot(2,1,1);
dendrogram(tree);
title('Default leaf order');
subplot(2,1,2);
dendrogram(tree,'Reorder',myOrd);
title('Desired leaf order');
Do you have any idea for a more efficient implementation?
Thank you
0 件のコメント
採用された回答
Massimo Zanetti
2016 年 12 月 16 日
Apparently, none of the available functionalities of optimalleaforder does the work. So here it is a function that runs through the rows of the tree matrix generated by linkage and produces your output.
function c = binOrd(tree)
p = size(tree,1);
c = zeros(1,p+1);
k = 0;
recBin(p);
function recBin(r)
x = tree(r,1:2)-p-1;
if x(1)<=0
c(k+1) = tree(r,1);
k = k+1;
else
recBin(x(1));
end
if x(2)<=0
c(k+1) = tree(r,2);
k = k+1;
else
recBin(x(2));
end
end
end
To get your desired rightmost binary ordering, run dendogram with 'Reorder' set as the output of the binOrd function:
tree = linkage(D,'average');
myBinOrder = binOrd(tree);
dendrogram(tree,'Reorder',myBinOrder);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Point Cloud Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!