LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QBD_CR.m
1function [G,R,U]=QBD_CR(A0,A1,A2,varargin)
2%QBD_CR Cyclic reduction for Quasi-Birth-Death Markov Chains [Bini,Meini]
3%
4% DISCRETE TIME CASE:
5%
6% G=QBD_CR(A0,A1,A2) computes the minimal nonnegative solution to the
7% matrix equation G = A0 + A1 G + A2 G^2, where A,B and C are square
8% nonnegative matrices, with (A0+A1+A2) irreducible and stochastic
9%
10% [G,R]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
11% to the matrix equation R = A2 + R A1 + R^2 A0
12%
13% [G,R,U]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
14% to the matrix equation U = A1 + A2 (I-U)^(-1) A0
15%
16% CONTINUOUS TIME CASE:
17%
18% G=QBD_CR(A0,A1,A2) computes the minimal nonnegative solution to the
19% matrix equation 0 = A0 + A1 G + A2 G^2, where A,B and C are square
20% nonnegative matrices, with (A0+A1+A2) having row sums equal to zero
21%
22% [G,R]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
23% to the matrix equation 0 = A2 + R A1 + R^2 A0
24%
25% [G,R,U]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
26% to the matrix equation U = A1 + A2 (-U)^(-1) A0
27%
28% Optional Parameters:
29%
30% MaxNumIt: Maximum number of iterations (default: 50)
31% Verbose: The residual error is printed at each step when set to 1,
32% (default:0)
33% Mode: 'Basic' uses the Basic Cyclic Reduction
34% 'Shift' uses the shift technique to accelarate convergence
35% (default: 'Shift')
36
37OptionNames=[
38% 'ProgressBar';
39 'Mode ';
40 'MaxNumIt ';
41 'Verbose '];
42OptionTypes=[
43% 'numeric';
44 'char ';
45 'numeric';
46 'numeric'];
47OptionValues{1}=['Basic';
48 'Shift'];
49
50options=[];
51for i=1:size(OptionNames,1)
52 options.(deblank(OptionNames(i,:)))=[];
53end
54
55% Default settings
56%options.ProgressBar=0;
57options.Mode='Shift';
58options.MaxNumIt=50;
59options.Verbose=0;
60
61% Convert to discrete time problem, if needed
62m=size(A1,1);
63continues=0;
64if (sum(diag(A1)<0)) % continuous time
65 continues=1;
66 lamb=max(-diag(A1));
67 A0=A0/lamb;
68 A1=A1/lamb+eye(m);
69 A2=A2/lamb;
70end
71
72% Parse Parameters
73QBD_ParsePara(A0,A1,A2);
74
75% Parse Optional Parameters
76options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
77
78% check whether G is known explicitly
79[G,R,U]=QBD_EG(A0,A1,A2,options.Verbose,nargout);
80if (~isempty(G))
81 return
82end
83
84% Start CR
85
86% Shift technique
87if (options.Mode=='Shift')
88 theta=statvec(A0+A1+A2);
89 drift=theta*sum(A0,2)-theta*sum(A2,2);
90 if (drift < 0) % MC is transient -> use the dual MC
91 if (nargout > 1 | options.Verbose==1)
92 A2old=A2;
93 end
94 A2=A2-ones(m,1)*(theta*A2);
95 A1=A1+ones(m,1)*(theta*A0);
96 else
97 uT=ones(1,m)/m;
98 if (nargout > 2 | options.Verbose==1) % store A0old to compute U
99 A0old=A0;
100 end
101 A0=A0-sum(A0,2)*uT;
102 A1=A1+sum(A2,2)*uT;
103 end
104end
105
106% Start of Cyclic Reduction (Basic)
107A=A1;
108B=A2;
109C=A0;
110if (nargout <= 1 & options.Verbose ~= 1) % A1 and A2 only needed to compute R
111 clear A1 A2;
112end
113Ahat=A;
114%if (options.ProgressBar==1)
115% progressBar2(0,'Quasi-Birth-Death','Computing R via Cyclic Reduction (CR) ...');
116%end
117check=1;
118numit=0;
119while (check > 10^(-14) & numit < options.MaxNumIt)
120 Atemp=(eye(m)-A)^(-1);
121 BAtemp=B*Atemp;
122 Atemp=C*Atemp;
123 Ahat=Ahat+BAtemp*C;
124 A=A+BAtemp*C+Atemp*B;
125 B=BAtemp*B;
126 C=Atemp*C;
127 numit=numit+1;
128 check=min(norm(B,inf),norm(C,inf));
129 %if (options.ProgressBar==1)
130 % est_numit=ceil(log2(log(10^(-50))/log(check/checkold)));
131 % checkold=check;
132 % progressBar2(min([1 numit/(numit+est_numit)]),'Quasi-Birth-Death');
133 %end
134 if (options.Verbose==1)
135 fprintf('Check after %d iterations: %d\n',numit,check);
136 drawnow;
137 end
138end
139if (numit == options.MaxNumIt && check > 10^(-14))
140 warning('Maximum Number of Iterations %d reached',numit);
141end
142clear Atemp BAtemp A B C;
143G=(eye(m)-Ahat)^(-1)*A0;
144clear Ahat;
145
146% Shift Technique
147if (options.Mode=='Shift')
148 if (drift < 0) % transient
149 if (nargout > 1 | options.Verbose==1)
150 A1=A1-ones(m,1)*theta*A0; % restore original A1
151 A2=A2old; % restore original A2
152 end
153 else % pos recurrent
154 G=G+ones(m,1)*uT;
155 if (nargout > 1 | options.Verbose==1)
156 A1=A1-sum(A2,2)*uT; % restore original A1
157 end
158 if (nargout > 2 | options.Verbose==1)
159 A0=A0old; % restore original A0
160 end
161 end
162end
163
164if (options.Verbose==1)
165 res_norm=norm(G-A0-(A1+A2*G)*G,inf);
166 fprintf('Final Residual Error for G: %d\n',res_norm);
167end
168
169% Compute R
170if (nargout > 1)
171 R=A2*(eye(m)-(A1+A2*G))^(-1);
172 if (options.Verbose==1)
173 res_norm=norm(R-A2-R*(A1+R*A0),inf);
174 fprintf('Final Residual Error for R: %d\n',res_norm);
175 end
176end
177
178% Compute U
179if (nargout > 2)
180 U=A1+R*A0;
181 if (options.Verbose==1)
182 res_norm=norm(U-A1-A2*(eye(m)-U)^(-1)*A0,inf);
183 fprintf('Final Residual Error for U: %d\n',res_norm);
184 end
185 if (continues)
186 U=lamb*(U-eye(m));
187 end
188end
189
190
191%if (options.ProgressBar==1)
192% progressBar2(1,'Quasi-Birth-Death');
193%end