Daniel@0: function [obs, hidden] = mhmm_sample(T, numex, initial_prob, transmat, mu, Sigma, mixmat) Daniel@0: % SAMPLE_MHMM Generate random sequences from an HMM with (mixtures of) Gaussian output. Daniel@0: % [obs, hidden] = sample_mhmm(T, numex, initial_prob, transmat, mu, Sigma, mixmat) Daniel@0: % Daniel@0: % INPUTS: Daniel@0: % T - length of each sequence Daniel@0: % numex - num. sequences Daniel@0: % init_state_prob(i) = Pr(Q(1) = i) Daniel@0: % transmat(i,j) = Pr(Q(t+1)=j | Q(t)=i) Daniel@0: % mu(:,j,k) = mean of Y(t) given Q(t)=j, M(t)=k Daniel@0: % Sigma(:,:,j,k) = cov. of Y(t) given Q(t)=j, M(t)=k Daniel@0: % mixmat(j,k) = Pr(M(t)=k | Q(t)=j) : set to ones(Q,1) or omit if single mixture Daniel@0: % Daniel@0: % OUTPUT: Daniel@0: % obs(:,t,l) = observation vector at time t for sequence l Daniel@0: % hidden(t,l) = the hidden state at time t for sequence l Daniel@0: Daniel@0: Q = length(initial_prob); Daniel@0: if nargin < 7, mixmat = ones(Q,1); end Daniel@0: O = size(mu,1); Daniel@0: hidden = zeros(T, numex); Daniel@0: obs = zeros(O, T, numex); Daniel@0: Daniel@0: hidden = mc_sample(initial_prob, transmat, T, numex)'; Daniel@0: for i=1:numex Daniel@0: for t=1:T Daniel@0: q = hidden(t,i); Daniel@0: m = sample_discrete(mixmat(q,:), 1, 1); Daniel@0: obs(:,t,i) = gaussian_sample(mu(:,q,m), Sigma(:,:,q,m), 1); Daniel@0: end Daniel@0: end