% This file may be used freely for any non-commercial, educational purpose. % Copyright (c) 2003, Eamonn Keogh, Jessica Lin. All rights reserved. % % This function demonstrates the danger of dimensionality reduction by showing how a cloud of % points appear to have different shapes when projected onto different planes. function demo_shape speed = 0.01; % This varible controls the speed of the animation. WARNING Use low value, less than 0.05 data= rand(3000,3); % Create an initial cloud of points in the unit cube % Prune off any points outside a circle in the X,Y plane for i = 1 : size(data,1) x = data(i,1) - 0.5; y = data(i,2) - 0.5; if (x^2 + y^2) > 0.25 data(i,1) =[nan ]; data(i,2) =[nan ]; data(i,3) =[nan ]; end end % Prune off any points outside a triangle in the X,Z plane for i = 1 : size(data,1) if~isnan(data(i,1)) x = data(i,1) ; z = data(i,3) ; if x < .5 & (x < (0.5*z)) data(i,1) =[nan ]; data(i,2) =[nan ]; data(i,3) =[nan ]; elseif ((1-x) < 0.5*z) data(i,1) =[nan ]; data(i,2) =[nan ]; data(i,3) =[nan ]; end end end hold on; grid on; view(135,35); h = plot3(data(:,1) , data(:,2) , data(:,3), 'r.' ); % Plot 3-D cloud of points set(0,'units','pixels'); screenwidth=get(0,'screensize'); set(gcf,'position',screenwidth*0.9); set(gca,'xlim',[-1 2] ); set(gca,'ylim',[-1 2] ); set(gca,'zlim',[-1 2] ); title('Assume that you have this cloud of points in 3 dimensions... Click anywhere to continue') [X,Y] = ginput(1); title('What will happen if you reduce the dimensionality to just 2 dimensions? Click anywhere to continue') [X,Y] = ginput(1); plot3(data(:,1) , data(:,2) , (data(:,3)*0)-1, 'b.' ) title('If you use the X and Y values you get a circle... Click anywhere to continue'); [X,Y] = ginput(1); plot3(data(:,1) , (data(:,2)*0)-1 , data(:,3), 'g.' ) title('If you use the X and Z values you get a triangle... Click anywhere to continue'); [X,Y] = ginput(1); plot3((data(:,1)*0)-1 , data(:,2) , data(:,3), 'm.' ) title('If you use the Y and Z values you get a rectangle... Click anywhere to continue'); [X,Y] = ginput(1); title(' '); pause(1) % Begin a simple animation that rotates the axis to the XY view, the XZ view and the YZ view, pausing briefly at each. pause(1) for i = 135 : 5 : 180 view(i,35 - (abs(i-135)*35/45) ) pause(speed) end pause(1) for i = 180 :-5: 135 view(i,35 - (abs(i-135)*35/45) ) pause(speed) end for i = 135 :-5: 90 view(i,35 - (abs(i-135)*35/45) ) pause(speed) end pause(1) for i = 90 : 5 : 135 view(i,35 - (abs(i-135)*35/45) ) pause(speed) end for i = 35 : 5 : 90 view(135,i) pause(speed) end pause(1) for i = 90 :-5 : 35 view(135,i) pause(speed) end title('(c) Eamonn Keogh, Jessica Lin, used with permission')