1% x = SamplesFromDMMAP(D, K, prec)
3% Generates random samples from a discrete marked
4% Markovian arrival process.
8% D : list of matrices of shape(M,M), length(N)
9% The D0...DN matrices of the DMMAP
11% The number of samples to generate.
12% prec : double, optional
13% Numerical precision to check
if the input DMMAP
is
14% valid. The
default value
is 1e-14.
18% x : matrix, shape(K,2)
19% The random samples. Each row consists of two
20% columns: the (discrete) inter-arrival time and the
23function x = SamplesFromDMMAP(D,k,initial)
25 global BuToolsCheckInput;
26 if isempty(BuToolsCheckInput)
27 BuToolsCheckInput =
true;
30 if BuToolsCheckInput && ~CheckDMMAPRepresentation(D)
31 error(
'SamplesFromDMMAP: input isn''t a valid DMMAP representation!');
36 if ~exist(
'initial',
'var') || isempty(initial)
37 % draw initial state according to the stationary distribution
38 stst = MarginalDistributionFromDMMAP(D);
39 cummInitial = cumsum(stst);
42 while cummInitial(state)<=r
50 sojourn = 1./(1-diag(D{1}));
51 logp = log(diag(D{1}));
52 nextpr = diag(sojourn)*D{1};
53 nextpr = nextpr - diag(diag(nextpr));
55 nextpr=[nextpr,diag(sojourn)*D{i}];
57 nextpr = cumsum(nextpr,2);
67 % play state transitions
69 time = time + 1 + floor(log(rand()) / logp(state));
72 while nextpr(state,nstate)<=r
79 x(n,2) = ceil(state/N)-1;
83 state = rem(state-1,N)+1;