comparison toolboxes/FullBNT-1.0.7/HMM/mhmm_sample.m @ 0:e9a9cd732c1e tip

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