-
Notifications
You must be signed in to change notification settings - Fork 0
/
QBD_NI.m
171 lines (157 loc) · 4.93 KB
/
QBD_NI.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
function [G,R,U]=QBD_NI(A0,A1,A2,varargin)
%QBD_NI Newton Iteration for Quasi-Birth-Death Markov Chains [Ramaswami,
% Latouche,Bini,Meini]
%
% DISCRETE TIME CASE:
%
% G=QBD_NI(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_NI(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation R = A2 + R A1 + R^2 A0
%
% [G,R,U]=QBD_NI(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_NI(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_NI(A0,A1,A2) also provides the minimal nonnegative solution
% to the matrix equation 0 = A2 + R A1 + R^2 A0
%
% [G,R,U]=QBD_NI(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: 'Sylvest' solves a Sylvester matrix equation at each step
% using an Hessenberg algorithm
% 'Estimat' estimates the solution of the Sylvester equation
% 'DirectSum' solves the Sylvester matrix equation at each
% step by rewriting it as a (large) system of linear equations
% (default: 'Sylvest')
% RAPComp: set to 1 if the QBD has RAP components
OptionNames=[
% 'ProgressBar';
'Mode ';
'MaxNumIt ';
'Verbose ';
'RAPComp '];
OptionTypes=[
% 'numeric';
'char ';
'numeric';
'numeric';
'numeric'];
OptionValues{1}=['Sylvest ';
'Estimat ';
'DirectSum'];
options=[];
for i=1:size(OptionNames,1)
options.(deblank(OptionNames(i,:)))=[];
end
% Default settings
%options.ProgressBar=0;
options.Mode='Sylvest';
options.MaxNumIt=50;
options.Verbose=0;
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
% Start NI
m=size(A1,1);
R=zeros(m,m);
check=1;
numit=0;
while (check > 10^(-12) && numit < options.MaxNumIt)
numit=numit+1;
if (numit==1)%R=0;
Yk=A2*(eye(m)-A1)^(-1);
else
if (strcmp(options.Mode,'Estimat'))
FRk=(A2+R*(A1-eye(m)+R*A0)); % FRk = (A2+RA1+R^2A0)-R
Zk=FRk*(eye(m)-A1)^(-1);
Yk=FRk+Zk*A1+(R*Zk+Zk*R)*A0;
else
D=-(A2+R*(A1-eye(m)+R*A0)); % D = R-(A2+RA1+R^2A0)
C=A1+R*A0-eye(m);
% Solve R*Yk*A0+Yk*C=D
if (strcmp(options.Mode,'Sylvest'))
Yk=QBD_NI_Sylvest(A0',R',C',D')';
else
Yk=(kron(A0',R)+kron(C',eye(m)))^(-1)*reshape(D,m^2,1);
Yk=reshape(Yk,m,m);
end
end
end
R=R+Yk;
check=norm(Yk,inf);
if (options.Verbose==1)
fprintf('Check after %d iterations: %d\n',numit,check);
drawnow;
end
end
clear C D Yk;
if (numit == options.MaxNumIt && check > 10^(-12))
warning('Maximum Number of Iterations %d reached',numit);
end
% Compute G
G=(eye(m)-(A1+R*A0))^(-1)*A0;
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
% R
if (nargout > 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