forked from Edderic/BRML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLDSsmooth.m
35 lines (35 loc) · 1.25 KB
/
LDSsmooth.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [f,F,g,G,Gp,loglik]=LDSsmooth(v,A,B,CovH,CovV,CovP,meanP,meanH,meanV,varargin)
%LDSSMOOTH Linear Dynamical System : Filtering and Smoothing
%[f,F,g,G,Gp]=LDSsmooth(v,A,B,CovH,CovV,CovP,meanP,meanH,meanV,<cellout>)
%
% Inputs:
% v : V x T matrix of observations
% A : transition matrix
% B : emission matrix
% CovH : transition covariance
% CovV : emission covariance
% CovP : initial (prior) covariance
% meanP : initial (prior) mean
% meanH : mean of the hidden transition
% meanV : mean of the observation
%
% Outputs:
% f,F : filtered mean and covariance
% g,G : smoothed mean and covariance
% Gp : smoothed cross moment <h_t h_{t+1}|v_{1:T}> t=1..T-1
% loglik : log likelihood of the sequence v
% By default the outputs are stored in arrays, eg F(:,:,t). Calling
% with cellout set to 1 returns cells eg F{t}
cellout=0; if nargin==10; cellout=varargin{1}; end
[f2,F2,loglik]=LDSforward(v,A,B,CovH,CovV,meanH,meanV,CovP,meanP);
[g2,G2,Gp2]=LDSbackward(v,A,B,f2,F2,CovH,meanH);
[V T]=size(v); H=size(CovH,1);
if cellout
f=mat2cell(f2,H,ones(1,T));
F=mat2cell(F2,H,H,ones(1,T));
g=mat2cell(g2,H,ones(1,T));
G=mat2cell(G2,H,H,ones(1,T));
Gp=mat2cell(Gp2,H,H,ones(1,T-1));
else
f=f2; F=F2; g=g2; G=G2; Gp=Gp2;
end