Attachment 'sheet04.m'

Download

   1 function sheet04
   2 
   3 % get the data
   4 [X, Y] = twomoon(1000);
   5 
   6 % get a subset of the data
   7 figure(1)
   8 NS = 10;
   9 [XS, YS] = subset(NS, X, Y);
  10 plot2ddata(X, Y);
  11 hold on
  12 plot(XS(:, 1), XS(:, 2), 'kx', 'MarkerSize', 10, 'LineWidth', 3);
  13 hold off
  14 title('data and example points')
  15 
  16 % train KRR
  17 figure(2);
  18 K = rbfkern(1, XS, XS);
  19 alpha = inv(K + 1e-6*eye(NS))*YS;
  20 
  21 YH = rbfkern(1, X, XS) * alpha;
  22 
  23 plot2ddata(X, YH);
  24 hold on;
  25 plot(XS(:,1), XS(:, 2), 'kx', 'MarkerSize', 10, 'LineWidth', 3);
  26 hold off
  27 
  28 title('learned only using sample points')
  29 
  30 % train with KRR + Graph Laplacian regularization
  31 figure(3)
  32 alpha = trainGLKRR(1, 0.001, 0.1, 1, XS, YS, X);
  33 YH = rbfkern(1, X, X) * alpha;
  34 plot2ddata(X, YH);
  35 hold on;
  36 plot(XS(:,1), XS(:, 2), 'kx', 'MarkerSize', 10, 'LineWidth', 3);
  37 hold off
  38 
  39 title('learned with graph Laplacian regularizer')
  40 
  41 function K = rbfkern(w, X, Y)
  42 N = size(X, 1);
  43 M = size(Y, 1);
  44 XX = sum(X.*X, 2);
  45 YY = sum(Y.*Y, 2);
  46 D = repmat(XX, 1, M) + repmat(YY', N, 1) - 2 * X * Y';
  47 K = exp(-D/(2*w));
  48 
  49 function plot2ddata(X, Y)
  50 P = (sign(Y) == 1);
  51 N = (sign(Y) == -1);
  52 plot(X(P, 1), X(P, 2), 'r+', X(N, 1), X(N, 2), 'bo');
  53 
  54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  55 %
  56 % your solution below
  57 %
  58 
  59 % 1. Generate a two-moon data set with N points and some noise. Make sure
  60 % that classes are not linearly seprable.
  61 function [X, Y] = twomoon(N)
  62 % ...
  63 
  64 % 2. Choose random subset of size N from a data set X, Y.
  65 function [X, Y] = subset(N, X, Y)
  66 % ...
  67 
  68 % 3. Compute the graph-Laplacian for Gaussian weights with width w
  69 function L = graphLaplacian(w, X)
  70 % ...
  71 
  72 % 4. Train KRR with Graph-Laplacian regularization on the data
  73 %
  74 % Parameters:
  75 %    w - width for the rbf kernel
  76 %    g - width for the graph-Laplacian
  77 %    lambda - regularization constant for general smoothness
  78 %    tau - regularization constant for GL-regularizer
  79 %    XS, YS - data set with labels
  80 %    X - unlabeled data
  81 function alpha = trainGLKRR(w, g, lambda, tau, XS, YS, X)
  82 % ...

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-06-16 13:02:17, 2873.9 KB) [[attachment:bioinf.pdf]]
  • [get | view] (2009-06-09 09:46:52, 209.6 KB) [[attachment:data.tar.gz]]
  • [get | view] (2009-05-26 09:12:28, 3099.4 KB) [[attachment:intrusion.pdf]]
  • [get | view] (2009-06-02 09:30:50, 1391.7 KB) [[attachment:kld-tutorial.pdf]]
  • [get | view] (2009-07-07 09:31:30, 1506.0 KB) [[attachment:largescale.pdf]]
  • [get | view] (2009-07-07 09:34:04, 192.5 KB) [[attachment:optim-intro.pdf]]
  • [get | view] (2009-05-05 08:16:16, 261.1 KB) [[attachment:recap2.pdf]]
  • [get | view] (2009-04-21 08:42:30, 66.5 KB) [[attachment:sheet01.pdf]]
  • [get | view] (2009-04-28 14:08:19, 1.0 KB) [[attachment:sheet02.m]]
  • [get | view] (2009-04-28 14:08:14, 62.8 KB) [[attachment:sheet02.pdf]]
  • [get | view] (2009-05-05 08:17:47, 0.6 KB) [[attachment:sheet03.m]]
  • [get | view] (2009-05-05 08:22:37, 90.9 KB) [[attachment:sheet03.pdf]]
  • [get | view] (2009-05-12 15:17:16, 1.9 KB) [[attachment:sheet04.m]]
  • [get | view] (2009-05-19 09:18:26, 110.6 KB) [[attachment:sheet04.pdf]]
  • [get | view] (2009-05-19 09:05:24, 63.6 KB) [[attachment:sheet05.pdf]]
  • [get | view] (2009-05-26 09:39:01, 4.4 KB) [[attachment:sheet06.m]]
  • [get | view] (2009-05-26 09:38:57, 84.0 KB) [[attachment:sheet06.pdf]]
  • [get | view] (2009-06-02 09:30:26, 0.9 KB) [[attachment:sheet07.m]]
  • [get | view] (2009-06-02 09:30:21, 72.2 KB) [[attachment:sheet07.pdf]]
  • [get | view] (2009-06-09 09:46:48, 2.2 KB) [[attachment:sheet08.m]]
  • [get | view] (2009-06-09 11:10:06, 60.3 KB) [[attachment:sheet08.pdf]]
  • [get | view] (2009-06-09 11:10:02, 2.3 KB) [[attachment:sheet08.py]]
  • [get | view] (2009-06-16 13:02:05, 122.2 KB) [[attachment:sheet09.pdf]]
  • [get | view] (2009-06-23 12:50:29, 1.1 KB) [[attachment:sheet10.m]]
  • [get | view] (2009-06-23 12:48:35, 77.4 KB) [[attachment:sheet10.pdf]]
  • [get | view] (2009-06-23 12:49:27, 5.8 KB) [[attachment:sheet10.tex]]
  • [get | view] (2009-07-07 13:55:57, 1.0 KB) [[attachment:sheet11.m]]
  • [get | view] (2009-07-07 13:58:20, 81.3 KB) [[attachment:sheet11.pdf]]
  • [get | view] (2009-06-23 12:48:40, 58.4 KB) [[attachment:splice.zip]]
  • [get | view] (2009-05-25 08:18:18, 591.1 KB) [[attachment:ssl2.pdf]]
  • [get | view] (2009-05-19 09:05:38, 614.6 KB) [[attachment:structured2.pdf]]
  • [get | view] (2009-05-26 09:39:05, 1217.5 KB) [[attachment:stud-data.mat.gz]]
  • [get | view] (2009-06-08 17:46:34, 1013.6 KB) [[attachment:textmining.pdf]]
 All files | Selected Files: delete move to page copy to page

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