wolffd@0
|
1 function [obs, hidden] = mhmm_sample(T, numex, initial_prob, transmat, mu, Sigma, mixmat)
|
wolffd@0
|
2 % SAMPLE_MHMM Generate random sequences from an HMM with (mixtures of) Gaussian output.
|
wolffd@0
|
3 % [obs, hidden] = sample_mhmm(T, numex, initial_prob, transmat, mu, Sigma, mixmat)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % INPUTS:
|
wolffd@0
|
6 % T - length of each sequence
|
wolffd@0
|
7 % numex - num. sequences
|
wolffd@0
|
8 % init_state_prob(i) = Pr(Q(1) = i)
|
wolffd@0
|
9 % transmat(i,j) = Pr(Q(t+1)=j | Q(t)=i)
|
wolffd@0
|
10 % mu(:,j,k) = mean of Y(t) given Q(t)=j, M(t)=k
|
wolffd@0
|
11 % Sigma(:,:,j,k) = cov. of Y(t) given Q(t)=j, M(t)=k
|
wolffd@0
|
12 % mixmat(j,k) = Pr(M(t)=k | Q(t)=j) : set to ones(Q,1) or omit if single mixture
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % OUTPUT:
|
wolffd@0
|
15 % obs(:,t,l) = observation vector at time t for sequence l
|
wolffd@0
|
16 % hidden(t,l) = the hidden state at time t for sequence l
|
wolffd@0
|
17
|
wolffd@0
|
18 Q = length(initial_prob);
|
wolffd@0
|
19 if nargin < 7, mixmat = ones(Q,1); end
|
wolffd@0
|
20 O = size(mu,1);
|
wolffd@0
|
21 hidden = zeros(T, numex);
|
wolffd@0
|
22 obs = zeros(O, T, numex);
|
wolffd@0
|
23
|
wolffd@0
|
24 hidden = mc_sample(initial_prob, transmat, T, numex)';
|
wolffd@0
|
25 for i=1:numex
|
wolffd@0
|
26 for t=1:T
|
wolffd@0
|
27 q = hidden(t,i);
|
wolffd@0
|
28 m = sample_discrete(mixmat(q,:), 1, 1);
|
wolffd@0
|
29 obs(:,t,i) = gaussian_sample(mu(:,q,m), Sigma(:,:,q,m), 1);
|
wolffd@0
|
30 end
|
wolffd@0
|
31 end
|