1% [D0, D1] = MAP2FromMoments(moms, corr1)
3% Returns a MAP(2) which has the same 3 marginal moments
4% and lag-1 autocorrelation as given.
8% moms : vector, length(3)
9% First three marginal moments of the inter-arrival times
11% The lag-1 autocorrelation of the inter-arrival times
15% D0 : matrix, shape (2,2)
16% The D0 matrix of the MAP(2)
17% D1 : matrix, shape (2,2)
18% The D1 matrix of the MAP(2)
20% Raises an exception if the moments are not feasible with
25% The result
is always a valid MAP(2) as
long as the input
26% moments can be realized by a PH(2) (can be checked with
27% :func:`butools.ph.APH2ndMomentLowerBound`,
28% :func:`butools.ph.APH3rdMomentLowerBound`,
29% :func:`butools.ph.APH3rdMomentUpperBound` with n=2) and the
30% correlation falls between the feasible lower and upper
31% bound (check by :func:`MAP2CorrelationBounds`).
35% .. [1] L Bodrog, A Heindl, G Horvath, M Telek, "A Markovian
36% Canonical Form of Second-Order Matrix-Exponential
37% Processes," EUROPEAN JOURNAL OF OPERATIONAL RESEARCH
38% 190:(2) pp. 459-477. (2008)
41function [D0, D1] = MAP2FromMoments (moms, corr1)
47 % If we have an exponential distribution, we do not allow correlation
48 global BuToolsCheckPrecision;
49 if isempty(BuToolsCheckPrecision)
50 BuToolsCheckPrecision = 1e-12;
52 if abs(m2-2.0*m1*m1) < BuToolsCheckPrecision && abs(corr1) > BuToolsCheckPrecision
53 error('We do not allow correlation in case of exponentially distributed marginal');
57 [tau, T] = PH2From3Moments (moms);
63 % Check the feasibility of the correlation parameter
64 [corrl, corru] = MAP2CorrelationBounds (moms);
66 error('The correlation parameter
is too small!');
69 error('The correlation parameter
is too large!');
72 gamma = corr1 * (m2-m1*m1) / (m2/2.0-m1*m1);
76 a = (1.0+alpha*gamma-p*(1.0-gamma)-sqrt((1.0+alpha*gamma-p*(1.0-gamma))^2-4.0*alpha*gamma)) / (2.0*alpha);
77 b = (1.0+alpha*gamma-p*(1.0-gamma)+sqrt((1.0+alpha*gamma-p*(1.0-gamma))^2-4.0*alpha*gamma)) / 2.0;
78 D0 = [-l1, (1.0-a)*l1; 0, -l2];
79 D1 = [a*l1, 0; (1.0-b)*l2, b*l2];
81 a = gamma / (alpha*gamma-p*(1.0-gamma));
82 b = p*(1.0-gamma)-alpha*gamma;
83 D0 = [-l1, (1.0-a)*l1; 0, -l2];
84 D1 = [0, a*l1; b*l2, (1.0-b)*l2];
86 D0 = [-l1, l1; 0, -l2];
87 D1 = [0, 0; p*l2, (1.0-p)*l2];