Daniel@0: function state = sample_mdp(prior, trans, act) Daniel@0: % SAMPLE_MDP Sample a sequence of states from a Markov Decision Process. Daniel@0: % state = sample_mdp(prior, trans, act) Daniel@0: % Daniel@0: % Inputs: Daniel@0: % prior(i) = Pr(Q(1)=i) Daniel@0: % trans{a}(i,j) = Pr(Q(t)=j | Q(t-1)=i, A(t)=a) Daniel@0: % act(a) = A(t), so act(1) is ignored Daniel@0: % Daniel@0: % Output: Daniel@0: % state is a vector of length T=length(act) Daniel@0: Daniel@0: len = length(act); Daniel@0: state = zeros(1,len); Daniel@0: state(1) = sample_discrete(prior); Daniel@0: for t=2:len Daniel@0: state(t) = sample_discrete(trans{act(t)}(state(t-1),:)); Daniel@0: end