Skip to content

Commit

Permalink
refined doc for ch13 LDS
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Feb 20, 2016
1 parent 206bd62 commit 1fa3bfd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extract demos
modify linPred to use Sigma instead of U and modify related regression functions
chapter10/12: prediction functions for VB
chapter07: rvm seq bug
chapter13/common/other: refine doc
common/other: refine doc
chapter13: refine ldsRnd
chapter05: MLP
chapter08: BP, EP
2 changes: 1 addition & 1 deletion chapter09/mixGaussRnd.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [X, z, model] = mixGaussRnd(d, k, n)
% Sampling form a Gaussian mixture distribution.
% Genarate samples form a Gaussian mixture model.
% Input:
% d: dimension of data
% k: number of components
Expand Down
7 changes: 7 additions & 0 deletions chapter13/LDS/kalmanFilter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function [mu, V, llh] = kalmanFilter(X, model)
% Kalman filter
% Input:
% X: d x n data matrix
% model: model structure
% Output:
% mu: q x n matrix of latent mean mu_t=E[z_t] w.r.t p(z_t|x_{1:t})
% V: q x q x n latent covariance U_t=cov[z_t] w.r.t p(z_t|x_{1:t})
% llh: loglikelihood
% Written by Mo Chen ([email protected]).
A = model.A; % transition matrix
G = model.G; % transition covariance
Expand Down
11 changes: 10 additions & 1 deletion chapter13/LDS/kalmanSmoother.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function [nu, U, Ezz, Ezy, llh] = kalmanSmoother(X, model)
% Kalman smoother
% Kalman smoother (forward-backward algorithm for linear dynamic system)
% Input:
% X: d x n data matrix
% model: model structure
% Output:
% nu: q x n matrix of latent mean mu_t=E[z_t] w.r.t p(z_t|x_{1:T})
% U: q x q x n latent covariance U_t=cov[z_t] w.r.t p(z_t|x_{1:T})
% Ezz: q x q matrix E[z_tz_t^T]
% Ezy: q x q matrix E[z_tz_{t-1}^T]
% llh: loglikelihood
% Written by Mo Chen ([email protected]).
A = model.A; % transition matrix
G = model.G; % transition covariance
Expand Down
12 changes: 9 additions & 3 deletions chapter13/LDS/ldsEm.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function [model, llh] = ldsEm(X, model)
% EM algorithm for parameter estimation of LDS
% EM algorithm for parameter estimation of linear dynamic system.
% Input:
% X: d x n data matrix
% model: prior model structure
% Output:
% model: trained model structure
% llh: loglikelihood
% Written by Mo Chen ([email protected]).
tol = 1e-4;
maxIter = 100;
Expand All @@ -9,11 +15,11 @@
[nu, U, Ezz, Ezy, llh(iter)] = kalmanSmoother(X, model);
if llh(iter)-llh(iter-1) < tol*abs(llh(iter-1)); break; end % check likelihood for convergence
% M-step
model = mStep(X, nu, U, Ezz, Ezy);
model = maximization(X, nu, U, Ezz, Ezy);
end
llh = llh(2:iter);

function model = mStep(X ,nu, U, Ezz, Ezy)
function model = maximization(X ,nu, U, Ezz, Ezy)
n = size(X,2);
mu0 = nu(:,1);
P0 = U(:,:,1);
Expand Down
12 changes: 10 additions & 2 deletions chapter13/LDS/ldsRnd.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function [X, model] = ldsRnd(d, k, n )

function [X, model] = ldsRnd(d, k, n)
% Generate a data sequence from linear dynamic system.
% Input:
% d: dimension of data
% k: dimension of latent variable
% n: number of data
% Output:
% X: d x n data matrix
% model: model structure
% Written by Mo Chen ([email protected]).
A = randn(k,k);
G = iwishrnd(eye(k),k);
C = randn(d,k);
Expand Down

0 comments on commit 1fa3bfd

Please sign in to comment.