1% [beta, B] = ExtendToMarkovian(alpha, A, maxSize, precision)
3% Assume we have an existing monocyclic (or acyclic)
4% representation of a matrix-exponential distribution
5% described by matrix A and vector alpha such that A
is
6% Markovian but alpha
is not. This procedure appends an
7% appropriate Erlang tail to the representation that makes
8% the result Markovian (both the generator matrix and the
9% initial vector parameter),
while keeping the distribution
10% the same. In [1]_ it
is proven that
this is always
11% possible
if the initial (alpha,A) defines a distribuion
12% (non-negative density).
16% alpha : vector, shape (1,M)
17% The (non-Markovian) initial vector
18% A : matrix, shape (M,M)
19% The (Markovian) transient generator.
20% maxSize : int, optional
21% The procedure stops if more than maxSize new phases
22% are required. The default value
is 100
23% precision : double, optional
24% The initial vector
is considered to be valid if the
25% smallest entry
is greater than -precision. The
26% default value
is 1e-14
30% beta : vector, shape (1,N)
31% The Markovian initial vector (N>=M)
32% B : matrix, shape (N,N)
33% The Markovian transient generator (N>=M).
37% .. [1] Mocanu, S., Commault, C.:
"Sparse representations
38% of phase-type distributions," Stoch. Models 15,
41function [beta, B] = ExtendToMarkovian (alpha, A, maxSize, precision)
43 if ~exist(
'precision',
'var')
47 if ~exist(
'maxSize',
'var')
51 function E = addErlangTail (D, len, mu)
55 E(DN,DN+1) = -sum(D(DN,:));
59 E(DN+ei,DN+ei+1) = mu;
64 function beta = inivecwithtail (gamma, G, tailLengthx, mux)
65 vlen = size(G,1)+tailLengthx;
66 beta = zeros(1, vlen);
67 WG = eye(size(G))+G/mux;
70 for k=vlen:-1:size(G,1)+1
74 beta(1:size(G,1)) = opv;
77 % initial value of t0upper
80 beta = alpha * expm(A*t0upper);
81 while min(beta)<-precision
82 t0upper = t0upper * 2;
83 beta = alpha * expm(A*t0upper);
86 % interval bisectioning
87 while (t0upper - t0lower)/(t0upper + t0lower) > precision
88 t0 = (t0upper + t0lower) / 2;
89 beta = alpha * expm(A*t0);
90 if min(beta)<-precision
98 % find optimal length and rate parameters of the Erlang tail
100 % points towards t0 sometimes give fewer states
101 % thus we try to increase t0 gradually till the number of states
108 % initial value of Lupper
111 beta = inivecwithtail (alpha, A, Lupper, Lupper/t0);
112 while min(beta)<-precision && Lupper<maxSize
114 beta = inivecwithtail (alpha, A, Lupper, Lupper/t0);
117 success = min(beta)>=-precision;
119 % interval bisectioning
120 while Lupper - Llower > 1
121 L = round((Lupper + Llower) / 2);
122 beta = inivecwithtail (alpha, A, L, L/t0);
123 if min(beta)<-precision
132 if bestLupper>=0 && Lupper>bestLupper % there was a successfull attempt before, and this one
is worse
133 break; % stop and keep what we have
134 else % otherwise go on and increment t0
151 error ('No positive representation found up to the given size!');
155 beta = inivecwithtail (alpha, A, Lupper, Lupper/t0);
156 B = addErlangTail (A, Lupper, Lupper/t0);