LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MAP2FromMoments.m
1% [D0, D1] = MAP2FromMoments(moms, corr1)
2%
3% Returns a MAP(2) which has the same 3 marginal moments
4% and lag-1 autocorrelation as given.
5%
6% Parameters
7% ----------
8% moms : vector, length(3)
9% First three marginal moments of the inter-arrival times
10% corr1 : double
11% The lag-1 autocorrelation of the inter-arrival times
12%
13% Returns
14% -------
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)
19%
20% Raises an exception if the moments are not feasible with
21% a MAP(2).
22%
23% Notes
24% -----
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`).
32%
33% References
34% ----------
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)
39%
40
41function [D0, D1] = MAP2FromMoments (moms, corr1)
42
43 m1 = moms(1);
44 m2 = moms(2);
45 m3 = moms(3);
46
47 % If we have an exponential distribution, we do not allow correlation
48 global BuToolsCheckPrecision;
49 if isempty(BuToolsCheckPrecision)
50 BuToolsCheckPrecision = 1e-12;
51 end
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');
54 end
55
56 % Perform PH fitting
57 [tau, T] = PH2From3Moments (moms);
58 l1 = -T(1,1);
59 l2 = -T(2,2);
60 p = tau(1);
61 alpha = l1/l2;
62
63 % Check the feasibility of the correlation parameter
64 [corrl, corru] = MAP2CorrelationBounds (moms);
65 if corr1 < corrl
66 error('The correlation parameter is too small!');
67 end
68 if corr1 > corru
69 error('The correlation parameter is too large!');
70 end
71
72 gamma = corr1 * (m2-m1*m1) / (m2/2.0-m1*m1);
73
74 % Perform MAP fitting
75 if gamma > 0
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];
80 elseif gamma < 0
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];
85 else
86 D0 = [-l1, l1; 0, -l2];
87 D1 = [0, 0; p*l2, (1.0-p)*l2];
88 end
89end