LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
dmap_sample.m
1function X = dmap_sample(DMAP, n)
2% Generate n samples from a discrete MAP
3% Returns inter-arrival times (integer-valued)
4 D0 = DMAP{1};
5 D1 = DMAP{2};
6 N = size(D0, 1);
7 al = dmap_pie(DMAP);
8 phase = randsample(N, 1, true, al);
9 X = zeros(n, 1);
10 for i = 1:n
11 t = 0;
12 while true
13 t = t + 1;
14 probs = [D0(phase, :), D1(phase, :)];
15 next = randsample(2*N, 1, true, probs);
16 if next > N
17 phase = next - N;
18 X(i) = t;
19 break;
20 else
21 phase = next;
22 end
23 end
24 end
25end