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