1% x = SamplesFromMMAP(D, K, prec)
3% Generates random samples from a marked Markovian
8% D : list of matrices of shape(M,M), length(N)
9% The D0...DN matrices of the
MMAP
11% The number of samples to generate.
12% prec : double, optional
13% Numerical precision to check
if the input
MMAP 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 inter-arrival time and the type of the
23function x = SamplesFromMMAP(D,k,initial)
25 global BuToolsCheckInput;
26 if isempty(BuToolsCheckInput)
27 BuToolsCheckInput =
true;
30 if BuToolsCheckInput && ~CheckMMAPRepresentation(D)
31 error(
'SamplesFromMMAP: input isn''t a valid MMAP representation!');
36 if ~exist(
'initial',
'var') || isempty(initial)
37 % draw initial state according to the stationary distribution
38 stst = MarginalDistributionFromMMAP(D);
39 cummInitial = cumsum(stst);
42 while cummInitial(state)<=r
50 sojourn = -1./diag(D{1});
51 nextpr = diag(sojourn)*D{1};
52 nextpr = nextpr - diag(diag(nextpr));
54 nextpr=[nextpr,diag(sojourn)*D{i}];
56 nextpr = cumsum(nextpr,2);
66 % play state transitions
68 time = time - log(rand()) * sojourn(state);
71 while nextpr(state,nstate)<=r
78 x(n,2) = ceil(state/N)-1;
82 state = rem(state-1,N)+1;