1% [alpha, A] = RandomPH(order, mean, zeroEntries, maxTrials, prec)
3% Returns a random phase-type distribution with a given
9% The size of the phase-type distribution
10% mean : double, optional
11% The mean of the 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 PH
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'
38function [alpha, A] = RandomPH(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('RandomPH: 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 PH parameters
107 A = A - diag(sum(A,2)+a);
108 alpha = B(:,order+1)';
109 % check if it
is a proper PH (irreducible phase process & no full zero matrix)
110 if all(all(A==0.0)) || all(alpha==0.0) || all(a==0.0)
113 alpha = alpha / sum(alpha);
115 if rank(D) == order-1
117 if min(abs(pi)) > prec
118 % scale to the mean value
119 m = MomentsFromPH (alpha, A, 1);
127 error ('No feasible random PH found with such many zero entries!');