% First, let us generate some data, the noisy sinc data set
figure(1)
[X, Y] = sincdata(100, 0.1);
plot(X, Y, '.')
title('the data')

% Generate kernel matrix
K = rbfkern(1, X); % 1 is a reasonable width for this data set.
[U, D] = sortedeig(K); % my special function which takes
                       % care of proper sorting.

% Plot the eigenvalues. These show the variance in the kernel PCA
% directions. We see that only a few directions have any variance at
% all. 
figure(2)
plot(diag(D))
xlabel('kernel PCA components')
ylabel('variance')
title('variances in kernel feature spaces')

% Plot the contributions of the kernel PCA components to the
% label vector. Apparently, all compoments contribute a little to the
% label vector.
figure(3)
plot(abs(Y*U)) % Plots contributions vs. decreasing variance
               % along kernel PCA direction
xlabel('kernel PCA components')
ylabel('contribution to Y values')
title('Y values vs. kernel PCA components')

% Okay, generate target function and noise separately, and do 
% the analysis again.
[X, F] = sincdata(100, 0); % note that the noise is zero
N = 0.1 * randn(1, 100);   % the noise
Y = F + N;                 % adding noise manually
K = rbfkern(1, X);         % new kernel function
[U, D] = sortedeig(K);     % eigendecomposition
figure(4)
plot(1:100, abs(F*U), 'r', 1:100, abs(N*U), 'b')
legend('sinc(x)', 'noise')
xlabel('kernel PCA components')
xlabel('contribution to Y values')
title('relevant information vs. noise')