1% [alpha, A] = RandomDPH(order, mean, zeroEntries, maxTrials, prec)
3% Returns a random discrete phase-type distribution with a
9% The size of the discrete phase-type distribution
10% mean : double, optional
11% The mean of the discrete phase-type distribution
12% zeroEntries : int, optional
13% The number of zero entries in the initial vector,
14% generator matrix and closing vector
15% maxTrials : int, optional
16% The maximum number of trials to find a proper DPH
17% (that has an irreducible phase process and none of
18% its parameters
is all-zero). The
default value
is
20% prec : double, optional
21% Numerical precision for checking the irreducibility.
22% The default value
is 1e-14.
26% alpha : vector, shape (1,M)
27% The initial probability vector of the phase-type
29% A : matrix, shape (M,M)
30% The transient generator matrix of the phase-type
35% If the procedure fails, try to increase the
'maxTrials'
36% parameter, or increase the mean value.
38function [alpha, A] = RandomDPH(order, mean, zeroEntries, maxTrials, prec)
40 if ~exist(
'zeroEntries',
'var')
44 if ~exist(
'prec',
'var')
48 if ~exist('mean','var')
52 if ~exist('maxTrials','var')
56 if zeroEntries > (order+1)*(order-1)
57 error('RandomDPH: Too many zero entries requested! Try to decrease the zero entries number!');
60 % distribute the zero entries among the rows
61 function o = allZeroDistr (states, zeros)
67 x = allZeroDistr (states-1, zeros-iz);
69 xt = sort([x(jz,:), iz]);
70 % check if we have it already
73 if sum((o(kz,:)-xt).^2)==0
86 zeroDistr = allZeroDistr(order, zeroEntries);
89 while trials<maxTrials
90 % select a configuration from zeroDistr: it
is a list describing the zero entries in each row
91 zdix = randperm(size(zeroDistr,1));
92 for k=1:size(zeroDistr,1)
93 zDistr = zeroDistr(zdix(k),:);
94 B = zeros(order,order+2);
96 rp = randperm(order+1);
98 for j=1:order+1-zDistr(i)
101 B(i,1:i-1) = a(1:i-1);
102 B(i,i+1:end) = a(i:end);
104 % construct DPH parameters
113 alpha = B(:,order+1)';
114 % check if it
is a proper PH (irreducible phase process & no full zero matrix)
115 if all(all(A==0.0)) || all(alpha==0.0) || all(a==0.0)
118 alpha = alpha / sum(alpha);
119 if rank(eye(order)-A) == order
120 if min(abs(alpha*inv(eye(order)-A))) > prec
121 % diagonals of matrix A:
123 % scale to the mean value
124 m = MomentsFromDPH (alpha, diag(1-d)*A+diag(d), 1);
125 d = 1 - (1-d)*m(1)/mean;
126 A = diag(1-d)*A+diag(d);
127 if CheckDPHRepresentation(alpha,A,prec)
135 error ('No feasible random DPH found with such many zero entries! You can also try to increase the mean value!');