1% x = SamplesFromDPH(alpha, A, K, prec)
3% Generates random samples from a discrete phase-type
8% alpha : matrix, shape (1,M)
9% The initial probability vector of the discrete phase-
11% A : matrix, shape (M,M)
12% The transition probability matrix of the discrete phase-
15% The number of samples to generate.
16% prec : double, optional
17% Numerical precision to check
if the input phase-type
18% distribution
is valid. The
default value
is 1e-14.
22% x : vector, length(K)
23% The vector of random samples
25function x = SamplesFromDPH(a,A,k)
27 global BuToolsCheckInput;
28 if isempty(BuToolsCheckInput)
29 BuToolsCheckInput =
true;
32 if BuToolsCheckInput && ~CheckDPHRepresentation(a,A)
33 error(
'SamplesFromDPH: input isn''t a valid DPH representation!');
38 cummInitial = cumsum(a);
40 sojourn = 1./(1-diag(A));
41 nextpr = diag(sojourn)*A;
42 nextpr = nextpr - diag(diag(nextpr));
43 nextpr = [nextpr, 1-sum(nextpr,2)];
44 nextpr = cumsum(nextpr,2);
50 % draw initial distribution
53 while cummInitial(state)<=r
57 % play state transitions
59 time = time + 1 + floor(log(rand()) / logp(state));
62 while nextpr(state,nstate)<=r