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
6 changed files
with
38 additions
and
8 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
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,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 | ||
|
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,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 | ||
|
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,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; | ||
|
@@ -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); | ||
|
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,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); | ||
|