Attachment 'sheet10.m'

Download

   1 function sheet10
   2 
   3 % generate some data
   4 sheet10_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). 
  43 % Input: 
  44 %   K          - kernel matrix (n x n) of training data
  45 %   Y          - labels (1 x n)
  46 %   C          - regularization constant
  47 % Output:
  48 %   svm.alpha  - learned alphas
  49 %   svm.b      - learned b
  50 %   svm.y      - training Ys
  51 function svm = trainSVM(K, Y, C)
  52 % ...
  53 
  54 % 3b. Predict the labels given the kernel matrix built from the
  55 % test/training data points, and the svm structure returned by trainSVM.
  56 % Input:
  57 %   K:         - kernel matrix (m x n) of test/training data
  58 %   svm:       - svm structure 
  59 % Output:
  60 %   Yk         - predicted labels (1 x m)
  61 function Yh = predictSVM(K, svm)
  62 % ...
  63 
  64 % 3c. Compute the rbf kernel. If Y is missing, assume X = Y. Do not use
  65 % for loops to compute the pairwise distances!
  66 % Input: 
  67 %   w:         - kernel width
  68 %   X:         - Input vectors (d x n)
  69 %   Y:         - Input vectors (d x m)
  70 % Output:
  71 %   K:         - Kernel matrix (n x m)
  72 function K = rbfkern(w, X, Y)
  73 % ...

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] (2010-12-03 11:00:13, 73.5 KB) [[attachment:FDA and LSR.pdf]]
  • [get | view] (2010-11-18 14:22:56, 1407.4 KB) [[attachment:clustering_slides.pdf]]
  • [get | view] (2011-01-25 08:30:15, 499.5 KB) [[attachment:efficient_backprop.pdf]]
  • [get | view] (2010-10-28 10:55:22, 123.9 KB) [[attachment:full_sheet01.pdf]]
  • [get | view] (2010-11-04 14:04:25, 118.5 KB) [[attachment:full_sheet02.pdf]]
  • [get | view] (2010-11-11 10:52:24, 60.2 KB) [[attachment:full_sheet03.pdf]]
  • [get | view] (2010-11-18 15:23:26, 97.5 KB) [[attachment:full_sheet04.pdf]]
  • [get | view] (2010-11-25 15:14:31, 92.0 KB) [[attachment:full_sheet05.pdf]]
  • [get | view] (2010-12-02 08:50:14, 108.9 KB) [[attachment:full_sheet06.pdf]]
  • [get | view] (2010-12-09 13:30:45, 161.5 KB) [[attachment:full_sheet07.pdf]]
  • [get | view] (2010-12-16 13:33:01, 84.4 KB) [[attachment:full_sheet08.pdf]]
  • [get | view] (2011-01-05 17:12:33, 127.5 KB) [[attachment:full_sheet09.pdf]]
  • [get | view] (2011-01-12 18:08:23, 136.1 KB) [[attachment:full_sheet10.pdf]]
  • [get | view] (2011-01-19 19:10:49, 143.6 KB) [[attachment:full_sheet11.pdf]]
  • [get | view] (2011-01-26 11:33:22, 136.7 KB) [[attachment:full_sheet12.pdf]]
  • [get | view] (2011-02-02 20:35:04, 134.9 KB) [[attachment:full_sheet13.pdf]]
  • [get | view] (2010-11-25 15:08:04, 1505.5 KB) [[attachment:ica_slides.pdf]]
  • [get | view] (2011-01-08 10:49:41, 504.7 KB) [[attachment:kernel_intro.pdf]]
  • [get | view] (2011-01-25 08:30:11, 1221.6 KB) [[attachment:lect_kernels.pdf]]
  • [get | view] (2011-02-13 09:07:55, 1391.7 KB) [[attachment:rde-tutorial.pdf]]
  • [get | view] (2010-11-18 15:23:34, 1.4 KB) [[attachment:sheet04.m]]
  • [get | view] (2010-11-25 15:14:53, 0.8 KB) [[attachment:sheet05.m]]
  • [get | view] (2010-11-30 21:18:03, 1.1 KB) [[attachment:sheet06.m]]
  • [get | view] (2010-12-09 13:31:05, 1.9 KB) [[attachment:sheet07.m]]
  • [get | view] (2010-12-16 13:33:09, 2.7 KB) [[attachment:sheet08.m]]
  • [get | view] (2011-01-12 17:38:01, 2.0 KB) [[attachment:sheet10.m]]
  • [get | view] (2011-01-12 17:38:14, 4.8 KB) [[attachment:sheet10_data.m]]
  • [get | view] (2011-01-19 19:11:02, 1.5 KB) [[attachment:sheet11.m]]
  • [get | view] (2011-01-26 11:33:28, 1.7 KB) [[attachment:sheet12.m]]
 All files | Selected Files: delete move to page copy to page

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