Daniel@0: function [obs, hidden] = dhmm_sample_endstate(startprob, transmat, obsmat, endprob, numex) Daniel@0: % SAMPLE_DHMM Generate random sequences from an HMM with discrete outputs. Daniel@0: % function [obs, hidden] = sample_dhmm_endstate(startprob, transmat, obsmat, endprob, numex) Daniel@0: % Daniel@0: % We sample until we have have entered the end state Daniel@0: % obs{m} and hidden{m} are the m'th sequence Daniel@0: Daniel@0: hidden = cell(1,numex); Daniel@0: obs = cell(1,numex); Daniel@0: Daniel@0: for m=1:numex Daniel@0: hidden{m} = mc_sample_endstate(startprob, transmat, endprob); Daniel@0: T = length(hidden{m}); Daniel@0: obs{m} = zeros(1,T); Daniel@0: for t=1:T Daniel@0: h = hidden{m}(t); Daniel@0: obs{m}(t) = sample_discrete(obsmat(h,:)); Daniel@0: end Daniel@0: end