-
Notifications
You must be signed in to change notification settings - Fork 0
/
QBD_IS.m
225 lines (202 loc) · 6.16 KB
/
QBD_IS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
function [G,R,U]=QBD_IS(A0,A1,A2,varargin)
%QBD_IS Invariant Subspace for Quasi-Birth-Death Markov Chains [Akar, Sohraby]
%
% DISCRETE TIME CASE:
%
% G=QBD_IS(A0,A1,A2) computes the minimal nonnegative solution to the
% matrix equation G = A0 + A1 G + A2 G^2, where A,B and C are square
% nonnegative matrices, with (A0+A1+A2) irreducible and stochastic
%
% [G,R]=QBD_IS(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation R = A2 + R A1 + R^2 A0
%
% [G,R,U]=QBD_IS(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation U = A1 + A2 (I-U)^(-1) A0
%
% CONTINUOUS TIME CASE:
%
% G=QBD_IS(A0,A1,A2) computes the minimal nonnegative solution to the
% matrix equation 0 = A0 + A1 G + A2 G^2, where A,B and C are square
% nonnegative matrices, with (A0+A1+A2) having row sums equal to zero
%
% [G,R]=QBD_IS(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation 0 = A2 + R A1 + R^2 A0
%
% [G,R,U]=QBD_IS(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation U = A1 + A2 (-U)^(-1) A0
%
% Optional Parameters:
%
% MaxNumIt: Maximum number of iterations (default: 50)
% Verbose: The residual error is printed at each step when set to 1,
% (default:0)
% Mode: 'MSignStandard' uses the matrix sign approach
% 'MSignBalzer' uses the matrix sign approach with Balzer acceleration
% 'Schur' relies on an ordered Schur decomposition to find the
% invariant subspace (default: Schur)
% RAPComp: set to 1 if the QBD has RAP components
OptionNames=['Mode ';
'Verbose ';
'MaxNumIt ';
'RAPComp '];
OptionTypes=['char ';
'numeric';
'numeric';
'numeric'];
OptionValues{1}=['MSignStandard';
'MSignBalzer ';
'Schur '];
options=[];
for i=1:size(OptionNames,1)
options.(deblank(OptionNames(i,:)))=[];
end
% Default settings
options.Mode='Schur';
options.Verbose=0;
options.MaxNumIt=50;
options.RAPComp=0;
% Parse Optional Parameters
options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
if(~options.RAPComp)
% Convert to discrete time problem, if needed
m=size(A1,1);
continues=0;
if (sum(diag(A1)<0)) % continues time
continues=1;
lamb=max(-diag(A1));
A0=A0/lamb;
A1=A1/lamb+eye(m);
A2=A2/lamb;
end
% Parse Parameters
QBD_ParsePara(A0,A1,A2);
else
% Parse Parameters
QBD_RAP_ParsePara(A0,A1,A2);
% Convert to discrete time problem - uniformization
m=size(A1,1);
continues=1;
lamb=max(-diag(A1));
A0=A0/lamb;
A1=A1/lamb+eye(m);
A2=A2/lamb;
end
% check whether G is known explicitly
[G,R,U]=QBD_EG(A0,A1,A2,options.Verbose,nargout);
if (~isempty(G))
return
end
epsilon=10^(-12);
f=2;
m=size(A1,1);
% Step 1, F(z)=zD(z)-N(z), with A(z) = D^(-1)(z)N(z)
% For QBD: A(z) is a polynomial matrix in z with degree f. Thus, D(z)=I.
theta=stat(A0+A1+A2);
drift=theta*sum(A0,2)-theta*sum(A2,2);
F{1}=-A0;
F{2}=eye(m)-A1;
F{3}=-A2;
% Step 2, H(s)=sum_{i=0}^f F_i (1-s)^(f-i) (1+s)^i = sum_{i=0}^f H_i s^i
for i=0:f
H{i+1}=zeros(m,m);
end
for i=0:f
temp1=[1 -1];
temp2=[1 1];
con1=1;
con2=1;
for j=1:f-i
con1=conv(con1,temp1);
end
for j=1:i
con2=conv(con2,temp2);
end
contrib=conv(con1,con2);
for j=0:f
H{j+1}=H{j+1}+contrib(j+1)*F{i+1};
end
end
clear F;
% Step 3, \hat{H}_i = H_f^-1*H_i
H{f+1}=inv(H{f+1});
for i=0:f-1
hatH{i+1}=H{f+1}*H{i+1};
end
% Step 4, y, xT
y=[ones(m,1); zeros(m*(f-1),1)];
x0T=[zeros(1,m) 1] / [hatH{1} ones(m,1)];
for i=1:f-1
xT(1,(i-1)*m+1:i*m)=x0T*hatH{i+1};
end
xT(1,(f-1)*m+1:f*m)=x0T;
% Step 5, E_m in Zold
Zold=zeros(m*f,m*f);
for i=1:f-1
Zold((i-1)*m+1:i*m,i*m+1:(i+1)*m)=eye(m);
end
for i=0:f-1
Zold(m*(f-1)+1:m*f,i*m+1:(i+1)*m)=-hatH{i+1};
end
y=y/(xT*y);
Zold=Zold-sign(drift)*y*xT;
if ( exist('ordschur') ~= 5 || ~strcmp(options.Mode,'Schur'))
% Step 6, classic matrix sign function algorithm
if (strcmp('Schur',options.Mode))
fprintf('Ordschur not supported by current MATLAB version\n');
fprintf('An automatic switch is performed to the MSignBalzer Mode\n');
drawnow;
end
numit=0;
check=1;
while (check > epsilon && numit < options.MaxNumIt)
numit=numit+1;
if (strcmp(options.Mode,'MSignStandard'))
determ=1/2;
else % options.Mode = 'MSignBalzer' or switched from 'Schur' Mode
determ=(1+abs(det(Zold))^(1/(m*f)))^(-1);
determ=min(determ,1-10^(-3));
end
Znew=determ*Zold+(1-determ)*inv(Zold);
check=norm(Znew-Zold,1)/norm(Zold,1);
if (options.Verbose==1)
fprintf('Check after %d iterations: %d\n',numit,check);
drawnow;
end
Zold=Znew;
end
if (numit == options.MaxNumIt && check > epsilon)
warning('Maximum Number of Iterations %d reached: T may not have m columns',numit);
end
% Step 7,
T=orth(Znew-eye(m*f));
else
% Theorem 7 (Akar, Oguz, Sohraby -- SM 2000)
[T,D]=schur(Zold);
[T,D]=ordschur(T,D,'lhp');
T=T(:,1:m);
end
% Step 8,
G=(T(1:m,:)+T(m+1:2*m,:))*inv(T(1:m,:)-T(m+1:2*m,:));
if (options.Verbose==1)
res_norm=norm(G-A0-(A1+A2*G)*G,inf);
fprintf('Final Residual Error for G: %d\n',res_norm);
end
% Compute R
if (nargout > 1)
R=A2*(eye(m)-(A1+A2*G))^(-1);
if (options.Verbose==1)
res_norm=norm(R-A2-R*(A1+R*A0),inf);
fprintf('Final Residual Error for R: %d\n',res_norm);
end
end
% Compute U
if (nargout > 2)
U=A1+R*A0;
if (options.Verbose==1)
res_norm=norm(U-A1-A2*(eye(m)-U)^(-1)*A0,inf);
fprintf('Final Residual Error for U: %d\n',res_norm);
end
if (continues)
U=lamb*(U-eye(m));
end
end