LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QBD_pi.m
1function pi=QBD_pi(B0,B1,R,varargin)
2%QBD_pi Stationary vector of a Quasi-Birth-Death Markov Chains [Neuts]
3%
4% DISCRETE TIME CASE:
5%
6% pi=QBD_pi(B0,B1,R) computes the stationary vector of a Quasi-Birth-Death
7% Markov chain with a transition matrix of the form
8%
9% B1 A2 0 0 0 ...
10% B0 A1 A2 0 0 ...
11% P = 0 A0 A1 A2 0 ...
12% 0 0 A0 A1 A2 ...
13% ...
14%
15% the input matrix R is the minimal nonnegative solution to the matrix
16% equation R = A2 + R A1 + R^2 A0
17%
18% CONTINUOUS TIME CASE:
19%
20% pi=QBD_pi(B0,B1,R) computes the stationary vector of a Quasi-Birth-Death
21% Markov chain with a rate matrix of the form
22%
23% B1 A2 0 0 0 ...
24% B0 A1 A2 0 0 ...
25% Q = 0 A0 A1 A2 0 ...
26% 0 0 A0 A1 A2 ...
27% ...
28%
29% the input matrix R is the minimal nonnegative solution to the matrix
30% equation 0 = A2 + R A1 + R^2 A0
31%
32% Optional Parameters:
33%
34% MaxNumComp: Maximum number of components (default: 500)
35% Verbose: The accumulated probability mass is printed at every
36% n steps when set to n (default:0)
37% Boundary: Allows solving the QBD with a more general boundary
38%
39% B1 B2 0 0 0 ...
40% B0 A1 A2 0 0 ...
41% P (or Q) = 0 A0 A1 A2 0 ...
42% 0 0 A0 A1 A2 ...
43% ...
44%
45% the parameter value contains the matrix [B2; A1+R*A0].
46% The matrices B0 and B2 need not to be square.
47% (default: B2=A2)
48
49OptionNames=[
50 'Boundary ';
51 'MaxNumComp ';
52 'Verbose '];
53OptionTypes=[
54 'numeric';
55 'numeric';
56 'numeric'];
57
58OptionValues=[];
59
60options=[];
61for i=1:size(OptionNames,1)
62 options.(deblank(OptionNames(i,:)))=[];
63end
64
65% Default settings
66options.Boundary=[];
67options.MaxNumComp=10000;
68options.Verbose=0;
69
70% Parse Optional Parameters
71options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
72
73m=size(R,1);
74
75% Convert to discrete time problem, if needed
76if (sum(diag(B1)<0)) % continuous time
77 lamb=max(-diag(B1));
78 if (~isempty(options.Boundary))
79 mb=size(B1,1);
80 lamb=max(lamb,max(-diag(options.Boundary(mb+1:end,:))));
81 options.Boundary=options.Boundary/lamb;
82 options.Boundary(mb+1:end,:)=options.Boundary(mb+1:end,:)+eye(m);
83 B1=B1/lamb+eye(mb);
84 else
85 B1=B1/lamb+eye(m);
86 end
87 B0=B0/lamb;
88end
89
90temp=(eye(m)-R)^(-1);
91if( max(temp<-100*eps) )
92 error('MATLAB:QBD_pi:InvalidRInput',...
93 'The spectral radius of R is not below 1: QBD is not pos. recurrent');
94end
95
96if (isempty(options.Boundary))
97 pi=statvec(B1+R*B0); % compute pi_0
98 pi=pi/(pi*temp*ones(m,1)); % normalize pi_0
99 sumpi=sum(pi);
100 numit=1;
101 pi(2:options.MaxNumComp,:)=0;
102 while (sumpi < 1-10^(-10) && numit < 1+options.MaxNumComp)
103 pvec = pi(numit,:)*R;
104 pi(numit+1,1:m)=pvec; % compute pi_(numit+1)
105 numit=numit+1;
106 sumpi=sumpi+sum(pi(numit,:));
107 if (~mod(numit,options.Verbose))
108 fprintf('Accumulated mass after %d iterations: %d\n',numit,sumpi);
109 drawnow;
110 end
111 end
112% pi=reshape(pi',1,[]);
113else
114 mb=size(B1,1);
115 pi0=statvec([[B1; B0] options.Boundary]); % compute pi_0 and pi_1
116 pi0=pi0/(pi0(1:mb)*ones(mb,1)+pi0(mb+1:end)*temp*ones(m,1)); % normalize
117 pi=pi0(mb+1:end);
118 pi0=pi0(1:mb);
119 sumpi=sum(pi0)+sum(pi);
120 numit=1;
121 while (sumpi < 1-10^(-10) && numit < options.MaxNumComp)
122 pi(numit+1,1:m)=pi(numit,:)*R; % compute pi_(numit+1)
123 numit=numit+1;
124 sumpi=sumpi+sum(pi(numit,:));
125 if (~mod(numit,options.Verbose))
126 fprintf('Accumulated mass after %d iterations: %d\n',numit,sumpi);
127 drawnow;
128 end
129 end
130 pi=[pi0 reshape(pi',1,[])];
131 numit=numit+1;
132end
133
134if (numit == 1+options.MaxNumComp)
135% warning('Maximum Number of Components %d reached',numit-1);
136end