Attachment 'sheet14.m'

Download

   1 function sheet14
   2 
   3 % generate some data
   4 sheet14_data     
   5 
   6 % plot data
   7 plot(X(Y == 1, 1), X(Y == 1, 2), 'r+', ...
   8      X(Y == -1, 1), X(Y == -1, 2), 'bo');
   9 
  10 % learn an SVM
  11 width = 0.01;
  12 C = 1e5;
  13 
  14 K = rbfkern(width, X);
  15 svm = trainSVM(K, Y, C);
  16 Yh = predictSVM(K, svm);
  17 
  18 % predict the solution
  19 N = 50;
  20 [MX, MY] = meshgrid(linspace(0, 1, N), linspace(0, 1, N));
  21 XP = [reshape(MX, N*N, 1), reshape(MY, N*N, 1)];
  22 KP = rbfkern(width, XP, X);
  23 YP = predictSVM(KP, svm);
  24 F = reshape(YP, N, N);
  25 hold on
  26 contour(MX, MY, F, [-1, 0, 1]);
  27 % comment out next line for octave
  28 surf(MX, MY, F, 'FaceAlpha', 0.2); shading interp; caxis([-2 2])
  29 hold off
  30 grid
  31 colormap([linspace(1, 0, 100)', linspace(1, 0, 100)', ones(100, 1), ; 
  32           0 0 0; 
  33           ones(100, 1), linspace(0, 1, 100)', linspace(0, 1, 100)'])
  34 
  35 title(sprintf('Error rate: %.2f%%', mean(sign(Yh) ~= Y) * 100));
  36 
  37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38 %
  39 % Your solution below
  40 
  41 % 3a. train a support vector machine using the built-in generic quadratic
  42 % optimizer (quadprog for matlab, qp for octave). Return a structure with
  43 % the following entries:
  44 %
  45 %   svm.alpha - learned alphas
  46 %   svm.b     - learned b
  47 %   svm.y     - training Ys
  48 function svm = trainSVM(K, Y, C)
  49 N = length(Y);
  50 % ...
  51 
  52 % 3b. Predict the labels given the kernel matrix built from the
  53 % test/training data points, and the svm structure returned by trainSVM.
  54 function Yh = predictSVM(K, svm)
  55 % ...
  56 
  57 % 3c. Compute the rbf kernel. If Y is missing, assume X = Y. Do not use
  58 % for loops to compute the pairwise distances!
  59 function K = rbfkern(w, X, Y)
  60 % ...

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.