Prev: TAylor Series
Next: Neural Network for ECG signal
From: Nishant on 18 Sep 2005 12:46 Hey Frineds, I have doubt rearding distance Matrix. Can anyone guide me about the technique to use the distance matrix directly for calulating the linkage function directly using the given input distance matrix A? As I think that the pdist function is again converting my input distance matrix A into another distance matrix which is not required. Looking forward to your suggestions for using the distance matrix A directly in my calculations. Thanks Nishant
From: Tom Lane on 19 Sep 2005 08:59 Nishant, I don't know of a commonly accepted way to define a distance matrix that corresponds to a similarity matrix, My previous posting had an off-the-top-of-my-head idea. Here's another based on what the mdscale function does: Divide your matrix A by 6 to get a matrix with 1 on the diagonal Compute D = sqrt(1-A) In another posting you ask a question about using a distance matrix to compute the linkage function. The distance matrix is the input to the linkage function. There's no need to call the pdist function if you already have a distance matrix. You may need to use the squareform function to convert it to the required form. -- Tom "Nishant" <nishantxl(a)rediffmail.com> wrote in message news:1126914141.173379.51930(a)g47g2000cwa.googlegroups.com... > 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 >
From: Nishant on 22 Sep 2005 03:03
Hey Tom, Thanks for your guidance. I think this program works as of now. plz verify my code Thanks and Regards Nishant SAMPLE MATLAB 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');disp(A); % B=squareform(min(100,6./A - 1),'tovector') % D=distmat(A) % Y = pdist(A,'minkowski',4) Ai=abs(A-6); A1=triu(Ai) disp(A1') A2=nonzeros(A1') disp(A2); A3=reshape(A2,1,36); % Y=pdist(A,'cityblock');% pdist function to calculate the distance between every pair of objects in a data set m objects % disp('Y'); disp(A3);% Distance or Dissimiliarity Matrix consisting of m X(m-1) elements YY = squareform(A3)% square form : using the squareform function. %In this matrix, element i,j corresponds to the distance between object i and object j in the original data set. % YY = squareform(Y,'tomatrix') % Y = pdist(X,'minkowski',0) % Z=linkage(Y,minkowski); Z= linkage(A3,'average')%linkage function takes the distance information generated %by pdist and links pairs of objects that are close together into binary clusters %In this output, each row identifies a link between objects or clusters. %The first two columns identify the objects that have been linked, that is, object 1, object 2, and so on. %The third column contains the distance between these objects dendfigno=100+1; % cutoff=10; figure(dendfigno); % H=dendrogram(Z,0); [H,T,perm]=dendrogram(Z,0); [H,T] = dendrogram(Z,'colorthreshold','default'); % [H] = dendrogram(Z,0); % [H,T,perm] = dendrogram(Z) % T = clusterdata(X,'cutoff',10) disp('T') disp(T)% displays information about the number of objects c = cophenet(Z,A3)% the closer c to 1 : for accurate solution I = inconsistent(Z)% to calculate the inconsistency values in by the links created by the linkage function % %the inconsistent function returns data about the links in an (m-1)-by-4 matrix, % whose columns are described in the following table. % % % Column % % Description % % 1Mean of the heights of all the links included in the calculation % 2Standard deviation of all the links included in the calculation % 3Number of links included in the calculation % 4Inconsistency coefficient |