annotate toolboxes/FullBNT-1.0.7/HMM/mhmm_sample.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [obs, hidden] = mhmm_sample(T, numex, initial_prob, transmat, mu, Sigma, mixmat)
Daniel@0 2 % SAMPLE_MHMM Generate random sequences from an HMM with (mixtures of) Gaussian output.
Daniel@0 3 % [obs, hidden] = sample_mhmm(T, numex, initial_prob, transmat, mu, Sigma, mixmat)
Daniel@0 4 %
Daniel@0 5 % INPUTS:
Daniel@0 6 % T - length of each sequence
Daniel@0 7 % numex - num. sequences
Daniel@0 8 % init_state_prob(i) = Pr(Q(1) = i)
Daniel@0 9 % transmat(i,j) = Pr(Q(t+1)=j | Q(t)=i)
Daniel@0 10 % mu(:,j,k) = mean of Y(t) given Q(t)=j, M(t)=k
Daniel@0 11 % Sigma(:,:,j,k) = cov. of Y(t) given Q(t)=j, M(t)=k
Daniel@0 12 % mixmat(j,k) = Pr(M(t)=k | Q(t)=j) : set to ones(Q,1) or omit if single mixture
Daniel@0 13 %
Daniel@0 14 % OUTPUT:
Daniel@0 15 % obs(:,t,l) = observation vector at time t for sequence l
Daniel@0 16 % hidden(t,l) = the hidden state at time t for sequence l
Daniel@0 17
Daniel@0 18 Q = length(initial_prob);
Daniel@0 19 if nargin < 7, mixmat = ones(Q,1); end
Daniel@0 20 O = size(mu,1);
Daniel@0 21 hidden = zeros(T, numex);
Daniel@0 22 obs = zeros(O, T, numex);
Daniel@0 23
Daniel@0 24 hidden = mc_sample(initial_prob, transmat, T, numex)';
Daniel@0 25 for i=1:numex
Daniel@0 26 for t=1:T
Daniel@0 27 q = hidden(t,i);
Daniel@0 28 m = sample_discrete(mixmat(q,:), 1, 1);
Daniel@0 29 obs(:,t,i) = gaussian_sample(mu(:,q,m), Sigma(:,:,q,m), 1);
Daniel@0 30 end
Daniel@0 31 end