Prev: TAylor Series
Next: Neural Network for ECG signal
From: Nishant on 15 Sep 2005 22:53 Hi there, I have prepared code for forming dendrogram if a cooccurance matrix is entered already. But I am unable to get the correct heights for all the clusters in the dendrogram please help me in correcting the code plz c the code looking forward to ur guidance Thanks Nishant SAMPLE CODE :- clc close all A= [ 6 2 0 3 1 0 0 0 0; 2 6 4 2 0 1 0 0 0;0 4 6 0 1 1 0 0 0;3 2 0 6 1 0 3 1 0;1 0 1 1 6 3 1 0 3;0 1 1 0 3 6 0 1 5;0 0 0 3 1 0 6 4 0;0 0 0 1 0 1 4 6 2;0 0 0 0 3 5 0 2 6]; disp(A); Y=pdist(A,'cityblock'); Z= linkage(Y,'average'); dendfigno=100+1; figure(dendfigno); [H,T] = dendrogram(Z,'colorthreshold','default'); c = cophenet(Z,Y) I = inconsistent(Z)
From: Tom Lane on 16 Sep 2005 10:21 Nishant, you don't say why the results you get are incorrect, or what results you want. I can guess. It looks like A is a similarity matrix. The pdist function requires a distance or dissimilarity matrix. You pass A through pdist to get something of the proper form. However, pdist is expecting an n-by-p data matrix with n observations for p variables. Your A matrix appears not to be that, though I cannot be sure. If I'm right, you'll need to define a distance matrix that captures, in a way satisfactory to you, the information in the similarity matrix A. I have no idea what you would find satisfactory. Here's something that at least has the proper form: squareform(min(100,6./A - 1),'tovector') However, I do not claim that this is the distance measure that is appropriate for your problem. I just don't know. -- Tom "Nishant" <nishantxl(a)rediffmail.com> wrote in message news:1126839232.941538.252320(a)g49g2000cwa.googlegroups.com... > Hi there, > I have prepared code for forming dendrogram if a > cooccurance matrix is entered already. > > But I am unable to get the correct heights for all the clusters in the > dendrogram > > please help me in correcting the code > > plz c the code > > looking forward to ur guidance > > Thanks > > Nishant > SAMPLE CODE :- > > clc > close all > A= [ 6 2 0 3 1 0 0 0 0; > 2 6 4 2 0 1 0 0 0;0 4 6 0 1 1 0 0 0;3 2 0 6 1 0 3 1 0;1 0 1 1 6 3 1 0 3;0 > 1 1 0 3 6 0 1 5;0 0 0 3 1 0 6 4 0;0 0 0 1 0 1 4 6 2;0 0 0 0 3 5 0 2 6]; > disp(A); > Y=pdist(A,'cityblock'); > Z= linkage(Y,'average'); > dendfigno=100+1; > figure(dendfigno); > [H,T] = dendrogram(Z,'colorthreshold','default'); > c = cophenet(Z,Y) > I = inconsistent(Z) >
From: Nishant on 16 Sep 2005 13:00 hey Tom, Thanks for your suggestions. I can say the error is in the dendrogram heights. If one looks closely it can be said that heights corresponding to cluster formed by objects 2,3 and 7,8 should be of same height. instead this figure wrongly shows height for cluster formed by objects 7,8 and 1,4 as same. secondly ther height corresponding to cluster formed by objects {(6,9)cluster,object 5 } and cluster formed by objects 1,4 should be of same height: instead this figure wrongly shows height for formed by objects {(6,9)cluster,object 5 } higher than cluster formed by objects 1,4 cluster. Please see if you can find a way to correct the code to get the desired results. Looking forward to ur suggestions Thanks Nishant
From: Tom Lane on 16 Sep 2005 15:05 > I can say the error is in the dendrogram heights. If one looks closely > it can be said that heights corresponding to cluster formed by objects > 2,3 and 7,8 should be of same height. instead this figure wrongly > shows height for cluster formed by objects 7,8 and 1,4 as same. Nishant, I'm not sure you understood my comments about similarity matrices and distance matrices. Why do you say that objects (2,3) and (7,8) should cluster at the same height? According to the distance matrix Y that you created and passed into the linkage function, the distances between these pairs are different: >> Y = squareform(Y); >> Y(2,3) ans = 9 >> Y(7,8) ans = 10 These are indeed the heights that you see in the dendrogram. You have again not explained why you think these are wrong. I can only guess that it's because these pairs have the same values in your original matrix A. However, you did not use A as a similarity or dissimilarity matrix. You used it as if it were a data matrix, and computed city block distances between its rows. I recommend that you change your computation of Y. Instead of computing a distance matrix between rows of the co-occurrence matrix, think about how to define a distance matrix that reasonably represents your concept of how the observations differ. -- Tom
From: Nishant on 16 Sep 2005 19:42
Hey Tom, Thanks for your reply. I have used the given matrix A wrongly as it is actually a similiarity matrix. Do you know any technique to use Similiarity matrix for dendrogram generation? Looking forward to your guidance Regards and Thanks Nishant |