LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
APHFrom2Moments.m
1% [alpha, A] = APHFrom2Moments(moms, maxSize)
2%
3% Returns an acyclic PH which has the same 2 moments as
4% given. If detects the order and the structure
5% automatically to match the given moments.
6%
7% Parameters
8% ----------
9% moms : vector of doubles, length(2)
10% The moments to match
11% maxSize : int, optional
12% The maximal size of the resulting APH. The default value
13% is 100.
14%
15% Returns
16% -------
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
21%
22% Raises an error if the moments are not feasible with an
23% APH of size "maxSize".
24
25function [alpha, A] = APHFrom2Moments (moms)
26 cv2 = moms(2)/moms(1)^2 - 1.0;
27 lambda = 1.0 / moms(1);
28 N = max(ceil(1.0/cv2), 2);
29 p = 1.0 / (cv2 + 1.0 + (cv2-1.0)/(N-1));
30 A = -lambda*p*N * eye(N);
31 for i=1:N-1
32 A(i,i+1) = -A(i,i);
33 end
34 A(N,N) = -lambda*N;
35 alpha = zeros(1,N);
36 alpha(1) = p;
37 alpha(N) = 1.0 - p;
38end
39