1%{ @file dtmc_simulate.m
2 % @brief Simulates a trajectory of a discrete-time Markov chain
4 % @author LINE Development Team
8 % @brief Simulates a trajectory of a discrete-time Markov chain
11 % Generates a sample path of the Markov chain
for n time steps.
15 % sts = dtmc_simulate(
P, pi0, n)
20 % <tr><th>Name<th>Description
21 % <tr><td>
P<td>Stochastic transition matrix
22 % <tr><td>pi0<td>Initial probability distribution vector
23 % <tr><td>n<td>Number of steps to simulate
28 % <tr><th>Name<th>Description
29 % <tr><td>sts<td>Vector of state indices visited in the simulation
32function [sts]=dtmc_simulate(
P, pi0, n)
36if isempty(intersect(find( rnd - cpi0 > 0), find(pi0>0)))
39 st = min(intersect(1 + find( rnd - cpi0 > 0),find(pi0>0)));
44 sts(i) = st; soujt(i)=1;
45 if F(st,end)==0 ||
P(st,st)==1
49 if isempty(intersect(find( rnd - F(st,:) > 0),find(
P(st,:)>0)))
50 st = min(find(
P(st,:)>0));
52 st = min(intersect(1 + find( rnd - F(st,:) > 0),find(
P(st,:)>0)));