function[] = DST_sample_rec(cur) global D; %chain if( D(cur).type==1) for n=1:D(cur).N if(cur==1) D(cur).s{n} = sample_chain(D(cur).phi, D(cur).Phi, D(cur).T(n)); else D(cur).s{n}(1) = sample_multi( D(cur).phi(:, D(D(cur).parent).s{n}(1))); for t=2:D(cur).T(n) D(cur).s{n}(t) = sample_multi( D(cur).Phi(:,D(cur).s{n}(t-1),D(D(cur).parent).s{n}(t))); end end end for i=D(cur).child DST_sample_rec(i); end elseif( D(cur).type==2) %need to write sometime elseif( D(cur).type==3) if(cur==1) %need to write else for n=1:D(cur).N xdim = D(cur).xdim; w = genData(zeros(1,D(cur).ydim),D(cur).R,D(cur).T(n)); for i =1:D(D(cur).parent).S v(:,:,i) = genData(zeros(1,xdim),D(cur).Q(:,:,i),D(cur).T(n))'; end s = D(D(cur).parent).s{n}(1); D(cur).x{n}(:,1) = D(cur).mu(:,s) + genData(zeros(1,xdim),D(cur).Q1(:,:,s),1)'; D(cur).y{n}(1,:) = (D(cur).C * D(cur).x{n}(:,1))' + w(1,:); for t=2:D(cur).T(n) s = D(D(cur).parent).s{n}(t); D(cur).x{n}(:,t) = D(cur).A(:,:,s) * D(cur).x{n}(:,t-1) + v(:,t,s); D(cur).y{n}(t,:) = (D(cur).C * D(cur).x{n}(:,t))' + w(t,:); end end end end