Skip to content

Commit

Permalink
removed knRegPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Mar 8, 2016
1 parent 5df5da2 commit b679ffd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 87 deletions.
4 changes: 2 additions & 2 deletions chapter03/demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
plot(llh);
[y,sigma] = linRegPred(model,x,t);
figure
plotCurveBar( x, y, sigma );
plotCurveBar(x,y,sigma);
hold on;
plot(x,t,'o');
hold off;
Expand All @@ -24,7 +24,7 @@
plot(llh);
[y,sigma] = linRegPred(model,x,t);
figure
plotCurveBar( x, y, sigma );
plotCurveBar(x,y,sigma);
hold on;
plot(x,t,'o');
hold off;
Expand Down
137 changes: 70 additions & 67 deletions chapter06/demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,74 @@
x = linspace(0,2*pi,n); % test data
t = sin(x)+rand(1,n)/2;
model = knReg(x,t,1e-4,@knGauss);
knRegPlot(model,x,t);

[y,s] = knRegPred(model,x);
plotCurveBar(x,y,s);
hold on;
plot(x,t,'o');
hold off;
%% Kernel regression with linear kernel is EQUIVALENT to linear regression
lambda = 1e-4;
model_kn = knReg(x,t,lambda,@knLin);
model_lin = linReg(x,t,lambda);

idx = 1:2:n;
xt = x(:,idx);
tt = t(idx);

[y_kn, sigma_kn,p_kn] = knRegPred(model_kn,xt,tt);
[y_lin, sigma_lin,p_lin] = linRegPred(model_lin,xt,tt);

maxdiff(y_kn,y_lin)
maxdiff(sigma_kn,sigma_lin)
maxdiff(p_kn,p_lin)
%% Kernel kmeans with linear kernel is EQUIVALENT to kmeans
clear; close all;
d = 2;
k = 3;
n = 500;
[X,y] = kmeansRnd(d,k,n);
init = ceil(k*rand(1,n));
[y_kn,en_kn,model_kn] = knKmeans(X,init,@knLin);
[y_lin,en_lin,model_lin] = kmeans(X,init);

idx = 1:2:n;
Xt = X(:,idx);

[t_kn,ent_kn] = knKmeansPred(model_kn, Xt);
[t_lin,ent_lin] = kmeansPred(model_lin, Xt);

maxdiff(y_kn,y_lin)
maxdiff(en_kn,en_lin)

maxdiff(t_kn,t_lin)
maxdiff(ent_kn,ent_lin)
%% Kernel PCA with linear kernel is EQUIVALENT TO PCA
clear; close all;
d = 10;
q = 2;
n = 500;
X = randn(d,n);


model_kn = knPca(X,q,@knLin);
idx = 1:2:n;
Xt = X(:,idx);

Y_kn = knPcaPred(model_kn,Xt);

[U,L,mu,mse] = pca(X,q);
Y_lin = U'*bsxfun(@minus,Xt,mu); % projection


R = Y_lin/Y_kn; % the results are equivalent up to a rotation.
maxdiff(R*R', eye(q))

%% demo for knCenter
clear; close all;
kn = @knGauss;
X=rand(2,100);
X1=rand(2,10);
X2=rand(2,5);

maxdiff(knCenter(kn,X,X1),diag(knCenter(kn,X,X1,X1)))
maxdiff(knCenter(kn,X),knCenter(kn,X,X,X))
% lambda = 1e-4;
% model_kn = knReg(x,t,lambda,@knLin);
% model_lin = linReg(x,t,lambda);
%
% idx = 1:2:n;
% xt = x(:,idx);
% tt = t(idx);
%
% [y_kn, sigma_kn,p_kn] = knRegPred(model_kn,xt,tt);
% [y_lin, sigma_lin,p_lin] = linRegPred(model_lin,xt,tt);
%
% maxdiff(y_kn,y_lin)
% maxdiff(sigma_kn,sigma_lin)
% maxdiff(p_kn,p_lin)
% %% Kernel kmeans with linear kernel is EQUIVALENT to kmeans
% clear; close all;
% d = 2;
% k = 3;
% n = 500;
% [X,y] = kmeansRnd(d,k,n);
% init = ceil(k*rand(1,n));
% [y_kn,en_kn,model_kn] = knKmeans(X,init,@knLin);
% [y_lin,en_lin,model_lin] = kmeans(X,init);
%
% idx = 1:2:n;
% Xt = X(:,idx);
%
% [t_kn,ent_kn] = knKmeansPred(model_kn, Xt);
% [t_lin,ent_lin] = kmeansPred(model_lin, Xt);
%
% maxdiff(y_kn,y_lin)
% maxdiff(en_kn,en_lin)
%
% maxdiff(t_kn,t_lin)
% maxdiff(ent_kn,ent_lin)
% %% Kernel PCA with linear kernel is EQUIVALENT TO PCA
% clear; close all;
% d = 10;
% q = 2;
% n = 500;
% X = randn(d,n);
%
%
% model_kn = knPca(X,q,@knLin);
% idx = 1:2:n;
% Xt = X(:,idx);
%
% Y_kn = knPcaPred(model_kn,Xt);
%
% [U,L,mu,mse] = pca(X,q);
% Y_lin = U'*bsxfun(@minus,Xt,mu); % projection
%
%
% R = Y_lin/Y_kn; % the results are equivalent up to a rotation.
% maxdiff(R*R', eye(q))
%
% %% demo for knCenter
% clear; close all;
% kn = @knGauss;
% X=rand(2,100);
% X1=rand(2,10);
% X2=rand(2,5);
%
% maxdiff(knCenter(kn,X,X1),diag(knCenter(kn,X,X1,X1)))
% maxdiff(knCenter(kn,X),knCenter(kn,X,X,X))
18 changes: 0 additions & 18 deletions chapter06/knRegPlot.m

This file was deleted.

1 change: 1 addition & 0 deletions common/plotCurveBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ function plotCurveBar( x, y, sigma )
hold on;
plot(x,y,'r-');
hold off
axis([x(1),x(end),-inf,inf])

0 comments on commit b679ffd

Please sign in to comment.