% % Written by: % -- % John L. Weatherwax 2005-08-14 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; drawnow; clc; clear; addpath( '../../Code/eda_data' ); addpath( '../../Code/eda_toolbox' ); addpath( '../Chapter1' ); % Example 8.4 load L1bpm % Get just those topics on 5 through 11 ind = find(classlab == 5); ind = [ind; find(classlab == 6)]; ind = [ind; find(classlab == 8)]; ind = [ind; find(classlab == 9)]; ind = [ind; find(classlab == 11)]; % Change the class labels for class 11 % for better plotting. clabs = classlab(ind); clabs(find(clabs==11)) = 1; % First do dimensionality reduction - ISOMAP [Y, R, E] = isomap(L1bpm,'k',10); % Choose 3 dimensions, based on residual variance. XX = Y.coords{3}'; % Only need those observations in classes of interest. X = XX(ind,:); % Now do model-based clustering with a maximum of 10 clusters. [bics,bestm,allm,Z,clabsmbc] = mbclust(X,10); % Get the hierarchical clustering. Y = pdist(X); Z = linkage(Y,'complete'); dendrogram(Z); cids = cluster(Z,'maxclust',16); % <- we now ask for 16 groups % An exension of Example 8.7 % Applies Ling's method to interpoint distance matrix. if( 0 ) % Continuing with same data used in Example 8.4. but Use just Topics 6 and 9 ind = find(classlab == 6); ind = [ind; find(classlab == 9)]; clabs = classlab(ind); else ind = 1:size(XX,1); end n = length(ind); data = XX(ind,:); % Randomly reorder the data and view the interpoint distance matrix as an image. data = data(randperm(n),:); Y = pdist(data); Ys = squareform(Y); imagesc(Ys); colormap(gray(256)) title('Interpoint Distance Matrix - Random Order') axis off saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_6_ro', 'epsc' ); % Now apply Ling's method. First need to get a partition or clustering. Z = linkage(Y,'complete'); % Now get the ordering based on the cluster scheme. T = cluster(Z,'maxclust',16); % Sort these, so points in the same cluster are adjacent. [Ts,inds] = sort(T); % Sort the distance matrix using this and replot. figure imagesc(Ys(inds,inds)) title('Interpoint Distance Matrix - Cluster Order') colormap(gray(256)) axis off saveas( gcf, '../../WriteUp/Graphics/Chapter8/prob_8_6_co', 'epsc' );