Attachment 'sheet05_02.m'

Download

   1 function sheet05_02
   2 % Principal Component Analysis
   3 
   4 % simple data set
   5 X = randn(500, 2) * diag([1, 2]) * rotmat(0.3*pi);
   6 X = X + repmat([3, -4], 500, 1);
   7 
   8 plot(X(:,1), X(:,2), '.');
   9 axis equal
  10 grid
  11 
  12 % first PCA without centering
  13 figure(1)
  14 p = pca(X, 0)
  15 plot_pca(X, p);
  16 title('PCA without centering')
  17 
  18 % now, with proper centering
  19 figure(2)
  20 p = pca(X)
  21 plot_pca(X, p);
  22 title('PCA with centering')
  23 
  24 % and now, we add further, far away point
  25 figure(3)
  26 X = [X; -50, -50];
  27 p = pca(X);
  28 plot_pca(X, p);
  29 title('PCA is not very stable with respect to outliers')
  30 
  31 % how about other data?
  32 figure(4)
  33 phi = rand(500, 1) * 4 * pi;
  34 X = [phi, cos(phi) + (phi.^3)/1e2] + 0.5*randn(500, 2);
  35 
  36 p = pca(X);
  37 plot_pca(X, p);
  38 
  39 function R = rotmat(phi)
  40 R = [cos(phi), sin(phi); -sin(phi), cos(phi)];
  41 
  42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43 % Fill in your solutions below
  44 
  45 % 1. Compute the principal components. If the second argument is given and
  46 % non-zero, properly center the data. Otherwise, don't center.  Return a
  47 % struct with fields "U", "D", and "M" with
  48 %
  49 %    U is the matrix whose columns are the principal components
  50 %    D is a vector with the variances
  51 %    M is the mean vector
  52 function result = pca(X, center)
  53 if nargin == 1
  54   center = 1;
  55 end
  56 % ...
  57 result.U = U;
  58 result.D = D;
  59 result.M = M;
  60 
  61 % 2. Plot the principal components for the PCA. First, plot the data as
  62 % points. Then, draw an ellipsis whose radii are given as 2*sqrt(D) such
  63 % that the ellipsis contains the data more or less. Add a grid and make sure
  64 % axes are sized equally.
  65 function plot_pca(X, p)
  66 % ...

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-03-12 14:03:18, 318.2 KB) [[attachment:BayesianDecisionTheory.pdf]]
  • [get | view] (2009-03-12 14:03:18, 247.3 KB) [[attachment:crossvalidation.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1740.8 KB) [[attachment:mlintro.pdf]]
  • [get | view] (2009-03-12 14:03:18, 665.3 KB) [[attachment:probtheo.pdf]]
  • [get | view] (2009-03-12 14:03:18, 52.7 KB) [[attachment:sheet01.pdf]]
  • [get | view] (2009-03-12 14:03:18, 61.7 KB) [[attachment:sheet02.pdf]]
  • [get | view] (2009-03-12 14:03:18, 65.8 KB) [[attachment:sheet03.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.1 KB) [[attachment:sheet04.m]]
  • [get | view] (2009-03-12 14:03:18, 80.3 KB) [[attachment:sheet04.pdf]]
  • [get | view] (2009-03-12 14:03:18, 106.7 KB) [[attachment:sheet05.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet05_01.m]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet05_02.m]]
  • [get | view] (2009-03-12 14:03:18, 0.8 KB) [[attachment:sheet06.m]]
  • [get | view] (2009-03-12 14:03:18, 93.2 KB) [[attachment:sheet06.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.4 KB) [[attachment:sheet07.m]]
  • [get | view] (2009-03-12 14:03:18, 100.6 KB) [[attachment:sheet07.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.7 KB) [[attachment:sheet08.m]]
  • [get | view] (2009-03-12 14:03:18, 85.4 KB) [[attachment:sheet08.pdf]]
  • [get | view] (2009-03-12 14:03:18, 45.2 KB) [[attachment:sheet09.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.5 KB) [[attachment:sheet10.m]]
  • [get | view] (2009-03-12 14:03:18, 59.4 KB) [[attachment:sheet10.pdf]]
  • [get | view] (2009-03-12 14:03:18, 3.0 KB) [[attachment:sheet11.m]]
  • [get | view] (2009-03-12 14:03:18, 68.6 KB) [[attachment:sheet11.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.7 KB) [[attachment:sheet12.m]]
  • [get | view] (2009-03-12 14:03:18, 62.6 KB) [[attachment:sheet12.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.4 KB) [[attachment:sheet12_data.m]]
  • [get | view] (2009-03-12 14:03:18, 63.1 KB) [[attachment:sheet13.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet14.m]]
  • [get | view] (2009-03-12 14:03:18, 73.7 KB) [[attachment:sheet14.pdf]]
  • [get | view] (2009-03-12 14:03:18, 4.8 KB) [[attachment:sheet14_data.m]]
  • [get | view] (2009-03-12 14:03:18, 120.2 KB) [[attachment:summary.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1505.5 KB) [[attachment:vl_ica_tub-08.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.