Skip to content

Commit

Permalink
extracted all demos
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Mar 20, 2016
1 parent 414d87f commit b368326
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 183 deletions.
43 changes: 0 additions & 43 deletions chapter10/demo.m

This file was deleted.

2 changes: 2 additions & 0 deletions chapter13/LDS/TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(1) test against matlab implementation of kalman filter
(2) simplify ldsEm with less parameters (G=diag(g), S=I)
35 changes: 0 additions & 35 deletions chapter14/demo.m

This file was deleted.

43 changes: 0 additions & 43 deletions demo/ch10/demo.m

This file was deleted.

34 changes: 0 additions & 34 deletions demo/ch10/demo_rvm.m

This file was deleted.

22 changes: 22 additions & 0 deletions demo/ch10/mixGaussVb_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

%% Variational Bayesian for Gaussian Mixture Model
close all; clear;
d = 2;
k = 3;
n = 2000;
[X,z] = mixGaussRnd(d,k,n);
plotClass(X,z);
m = floor(n/2);
X1 = X(:,1:m);
X2 = X(:,(m+1):end);
% VB fitting
[y1, model, L] = mixGaussVb(X1,10);
figure;
plotClass(X1,y1);
figure;
plot(L)
% Predict testing data
[y2, R] = mixGaussVbPred(model,X2);
figure;
plotClass(X2,y2);

19 changes: 19 additions & 0 deletions demo/ch10/rvmRegVb_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
clear; close all;

d = 100;
beta = 1e-1;
X = rand(1,d);
w = randn;
b = randn;
t = w'*X+b+beta*randn(1,d);
x = linspace(min(X),max(X),d); % test data

[model,llh] = linRegVb(X,t);
% [model,llh] = rvmRegVb(X,t);
plot(llh);
[y, sigma] = linRegPred(model,x,t);
figure
plotCurveBar(x,y,sigma);
hold on;
plot(X,t,'o');
hold off
File renamed without changes.
13 changes: 0 additions & 13 deletions chapter11/demo.m → demo/ch11/gauss_demo.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@

% demos for ch11
%
%% Collapse Gibbs sampling for Dirichelt process gaussian mixture model
close all; clear;
d = 2;
k = 3;
n = 1000;
[X,label] = mixGaussRnd(d,k,n);
plotClass(X,label);

[y,model] = mixGaussGb(X);
figure
plotClass(X,y);
%% Sequential update for Gaussian
close all; clear;
d = 2;
Expand Down
11 changes: 11 additions & 0 deletions demo/ch11/mixGaussGb_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%% Collapse Gibbs sampling for Dirichelt process gaussian mixture model
close all; clear;
d = 2;
k = 3;
n = 500;
[X,label] = mixGaussRnd(d,k,n);
plotClass(X,label);

[y,model] = mixGaussGb(X);
figure
plotClass(X,y);
13 changes: 13 additions & 0 deletions demo/ch12/fa_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% demos for ch12

clear; close all;
d = 3;
m = 2;
n = 1000;

X = ppcaRnd(m,d,n);
plotClass(X);

%% Factor analysis
[W, mu, psi, llh] = fa(X, m);
plot(llh);
11 changes: 0 additions & 11 deletions chapter12/demo.m → demo/ch12/pca_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,3 @@
figure;
plotClass(Z1);
mse3
%% EM probabilistic PCA
[W,mu,beta,llh] = ppcaEm(X,m);
plot(llh)

%% Variational Bayesian probabilistic PCA
[model, energy] = ppcaVb(X);
plot(energy);
%
%% Factor analysis
[W, mu, psi, llh] = fa(X, m);
plot(llh);
13 changes: 13 additions & 0 deletions demo/ch12/ppcaEm_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% demos for ch12

clear; close all;
d = 3;
m = 2;
n = 1000;

X = ppcaRnd(m,d,n);
plotClass(X);

%% EM probabilistic PCA
[W,mu,beta,llh] = ppcaEm(X,m);
plot(llh)
13 changes: 13 additions & 0 deletions demo/ch12/ppcaVb_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% demos for ch12

clear; close all;
d = 3;
m = 2;
n = 1000;

X = ppcaRnd(m,d,n);
plotClass(X);

%% Variational Bayesian probabilistic PCA
[model, energy] = ppcaVb(X);
plot(energy);
File renamed without changes.
4 changes: 0 additions & 4 deletions chapter13/LDS/demo.m → demo/ch13/lds_demo.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
% TODO:
% 1) test against matlab implementation of kalman filter
% 2) simplify ldsEm with less parameters (G=diag(g), S=I)

% demos for LDS in ch13

clear; close all;
Expand Down
10 changes: 10 additions & 0 deletions demo/ch14/adaboostBin_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

%% adaboost
d = 2;
k = 2;
n = 500;
[X,t] = kmeansRnd(d,k,n);
model = adaboostBin(X,t-1);
y = adaboostBinPred(model,X);
plotClass(X,y+1)

14 changes: 14 additions & 0 deletions demo/ch14/mixLinReg_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%% Mixture of linear regression
close all; clear
d = 1;
k = 2;
n = 500;
[X,y] = mixLinRnd(d,k,n);
plot(X,y,'.');
[label,model,llh] = mixLinReg(X, y, k);
plotClass([X;y],label);
figure
plot(llh);
[y_,z,p] = mixLinPred(model,X,y);
figure;
plotClass([X;y],label);
10 changes: 10 additions & 0 deletions demo/ch14/mixLogitBin_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%% Mixture of logistic regression
d = 2;
c = 4;
k = 4;
n = 500;
[X,t] = kmeansRnd(d,c,n);

model = mixLogitBin(X,t-1,k);
y = mixLogitBinPred(model,X);
plotClass(X,y+1)

0 comments on commit b368326

Please sign in to comment.