forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
89 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
binPlot | ||
multiPlot | ||
demo | ||
multiPlot: plot multclass decison boundary | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
|
||
% | ||
clear; close all; | ||
k = 2; | ||
n = 1000; | ||
[X,t] = kmeansRnd(2,k,n); | ||
|
||
[x1,x2] = meshgrid(linspace(min(X(1,:)),max(X(1,:)),n), linspace(min(X(2,:)),max(X(2,:)),n)); | ||
[model, llh] = logitReg(X,t-1,0); | ||
[y,p] = logitPred(model,X); | ||
|
||
w = model.w; | ||
w0 = model.w0; | ||
plot(llh); | ||
figure; | ||
spread(X,t); | ||
|
||
y = w(1)*x1+w(2)*x2+w0; | ||
|
||
hold on; | ||
contour(x1,x2,y,1); | ||
hold off; | ||
binPlot(model,X,t) | ||
pause | ||
%% | ||
% clear; close all; | ||
% k = 3; | ||
% n = 200; | ||
% [X,t] = rndKCluster(2,k,n); | ||
% | ||
% [x1,x2] = meshgrid(linspace(min(X(1,:)),max(X(1,:)),n), linspace(min(X(2,:)),max(X(2,:)),n)); | ||
% [model, llh] = mnReg(X,t, 1e-4,2); | ||
% plot(llh); | ||
% figure; | ||
% spread(X,t); | ||
% | ||
% W = model.W; | ||
% % y = w(1)*x1+w(2)*x2+w(3); | ||
% | ||
% hold on; | ||
% contour(x1,x2,t,1); | ||
% hold off; | ||
clear | ||
k = 3; | ||
n = 1000; | ||
[X,t] = kmeansRnd(2,k,n); | ||
[model, llh] = mnReg(X,t); | ||
y = mnPred(model,X); | ||
spread(X,y) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
% Centerize the data in the kernel space | ||
% kn: kernel function | ||
% X: dxn data matrix of which the center is computed | ||
% Xt(option): dxn test data to be centerized by the center of X | ||
% Xt(optional): dxn test data to be centerized by the center of X | ||
% Written by Mo Chen ([email protected]). | ||
K = kn(X,X); | ||
mK = mean(K); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function [label, energy, model] = knKmeans(X, k, kn) | ||
% Perform kernel k-means clustering. | ||
% K: nxn kernel matrix | ||
% k: number of cluster | ||
% Reference: Kernel Methods for Pattern Analysis | ||
% by John Shawe-Taylor, Nello Cristianini | ||
% Written by Mo Chen ([email protected]). | ||
K = kn(X,X); | ||
n = size(X,2); | ||
label = ceil(k*rand(1,n)); | ||
last = 0; | ||
while any(label ~= last) | ||
E = sparse(label,1:n,1,k,n,n); | ||
E = bsxfun(@times,E,1./sum(E,2)); | ||
T = E*K; | ||
Z = repmat(diag(T*E'),1,n)-2*T; | ||
last = label; | ||
[val, label] = min(Z,[],1); | ||
end | ||
energy = sum(val)+trace(K); | ||
if nargout == 3 | ||
model.X = X; | ||
model.kn = kn; | ||
model.label = label; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function [ output_args ] = knKmeansPred( input_args ) | ||
%KNKMEANSPRED Summary of this function goes here | ||
% Detailed explanation goes here | ||
|
||
|
||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function [y, sigma, p] = knRegPred(model, x, t) | ||
% Prediction for kernel regression model | ||
% Written by Mo Chen ([email protected]). | ||
kn = model.kn; | ||
a = model.a; | ||
X = model.X; | ||
tbar = model.tbar; | ||
y = a'*knCenterize(kn,X,x)+tbar; | ||
if nargin == 3 | ||
sigma = sqrt(1/beta+dot(X,X,1)); % 3.59 | ||
p = exp(((t-y).^2/sigma2+log(2*pi*sigma2))/(-2)); | ||
end | ||
|
||
% if nargout > 1 | ||
% beta = model.beta; | ||
% if isfield(model,'V') % V*V'=inv(S) 3.54 | ||
% U = model.V'*bsxfun(@minus,X,model.xbar); | ||
% sigma = sqrt(1/beta+dot(U,U,1)); % 3.59 | ||
% else | ||
% sigma = sqrt(1/beta); | ||
% end | ||
% if nargin == 3 && nargout == 3 | ||
% p = exp(logGauss(t,y,sigma)); | ||
% % p = exp(-0.5*(((t-y)./sigma).^2+log(2*pi))-log(sigma)); | ||
% end | ||
% end |