1% [alpha, A] = APHFrom3Moments(moms, maxSize)
3% Returns an acyclic PH which has the same 3 moments as
4% given. If detects the order and the structure
5% automatically to match the given moments.
9% moms : vector of doubles, length(3)
11% maxSize : int, optional
12% The maximal size of the resulting APH. The
default value
17% alpha : vector, shape (1,M)
18% The initial probability vector of the APH
19% A : matrix, shape (M,M)
20% Transient generator matrix of the APH
22% Raises an error
if the moments are not feasible with an
23% APH of size
"maxSize".
27% .. [1] A. Bobbio, A. Horvath, M. Telek,
"Matching three
28% moments with minimal acyclic phase type
29% distributions," Stochastic models, pp. 303-326, 2005.
31function [alpha, A] = APHFrom3Moments (moms, maxSize, prec)
33 if ~exist(
'prec',
'var')
36 if ~exist('maxSize','var')
45 % detect number of phases needed
47 while n<maxSize && (APH2ndMomentLowerBound(m1, n) > m2 || APH3rdMomentLowerBound(m1, m2, n) >= m3 || APH3rdMomentUpperBound(m1, m2, n) <= m3)
51 % if PH
is too large, adjust moment to bounds
52 if APH2ndMomentLowerBound(m1, n) > m2
53 m2 = APH2ndMomentLowerBound(m1, n);
56 if APH3rdMomentLowerBound(m1, m2, n) > m3
57 m3 = APH3rdMomentLowerBound(m1, m2, n);
60 if APH3rdMomentUpperBound(m1, m2, n) < m3
61 m3 = APH3rdMomentUpperBound(m1, m2, n);
64 % compute normalized moments
65 nmoms = NormMomsFromMoms ([m1, m2, m3]);
71 if n2>2 || n3 < 2*n2 - 1
72 b = real(2*(4-n*(3*n2-4)) / (n2*(4+n-n*n3) + sqrt(n*n2)*sqrt(12*n2^2*(n+1)+16*n3*(n+1)+n2*(n*(n3-15)*(n3+1)-8*(n3+3)))));
73 a = (b*n2-2)*(n-1)*b / (b-1) / n;
75 lambda = (p*a+1) / n1;
76 mu = (n-1)*lambda / a;
77 % construct representation
89 c4 = n2*(3*n2-2*n3)*(n-1)^2;
90 c3 = 2*n2*(n3-3)*(n-1)^2;
94 fs = roots([c4 c3 c2 c1 c0]);
97 if abs((n-1)*(n2*f^2-2*f+2)-n)<prec
100 a = 2*(f-1)*(n-1) / ((n-1)*(n2*f^2-2*f+2)-n);
103 mu = (n-1) / (n1 - p/lambda);
104 if isreal(p) && isreal(lambda) && isreal(mu)&& p>=0 && p<=1 && lambda>0 && mu>0
121 error('No APH found for the given 3 moments!');