function [LL,prior,transmat,obsmat,nrIterations] = samplestartEM(Data,N) % Start from a matrix of data Data, and a number of times N you %will run dhmm_em.m starting from N different randomly chosen sets of initial conditions. %Data = m x n matrix of data; in our casino examples, we are usually starting with m=30 and n=300. %N is a positive integer. A=dirichlet_sample([1,1,1,1,1,1],N); B=dirichlet_sample([1,1,1,1,1,1],N); I=[]; for i=1:N v=rand; w=[v,1-v]; I=[I;w]; end M1=[]; for i=1:N a=rand; b=1-a; M1=[M1; a, b]; end M2=[]; for i=1:N c=rand; d=1-c; M2=[M2;c d]; end LogL=[]; transmat1=[]; transmat2=[]; obsmat1=[]; obsmat2=[]; prior=[]; NoIt=[]; for i=1:N [ll,pr,trmat,obmat,nrIt]=dhmm_em(Data,I(i,:),[M1(i,:);M2(i,:)],[A(i,:);B(i,:)]); LogL=[LogL;ll(nrIt)] prior=[prior;pr]; transmat1=[transmat1;trmat(1,:)]; transmat2=[transmat2;trmat(2,:)]; obsmat1=[obsmat1;obmat(1,:)]; obsmat2=[obsmat2;obmat(2,:)]; NoIt=[NoIt;nrIt]; end LogL prior obsmat1 obsmat2 transmat1 transmat2 NoIt end