LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MG1_IS.m
1function [G,R,U]=MG1_IS(D,varargin)
2%MG1_IS Invariant Subspace for M/G/1-Type Markov Chains [Akar,Sohraby]
3%
4% G=MG1_IS(A) computes the minimal nonnegative solution to the
5% matrix equation G = A0 + A1 G + A2 G^2 + A3 G^3 + ... + A_max G^max,
6% where A = [A0 A1 A2 A3 ... A_max] has m rows and m*max columns and is
7% a nonnegative matrix, with (A0+A1+A2+...+A_max) irreducible and
8% stochastic
9%
10% Optional Parameters:
11%
12% MaxNumIt: Maximum number of iterations (default: 50)
13% Verbose: The residual error is printed at each step when set to 1,
14% (default:0)
15% Mode: 'MSignStandard' uses the matrix sign approach
16% 'MSignBalzer' uses the matrix sign approach with Balzer
17% acceleration
18% 'Schur' relies on a Schur decomposition
19% (default: MSignBalzer)
20
21OptionNames=['Mode ';
22 'Verbose ';
23 'MaxNumIt '];
24OptionTypes=['char ';
25 'numeric';
26 'numeric'];
27
28OptionValues{1}=['MSignStandard';
29 'MSignBalzer ';
30 'Schur '];
31
32options=[];
33for i=1:size(OptionNames,1)
34 options.(deblank(OptionNames(i,:)))=[];
35end
36
37% Default settings
38options.Mode='MSignBalzer';
39options.Verbose=0;
40options.MaxNumIt=50;
41
42% Parse Optional Parameters
43options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
44
45% check whether G is known explicitly
46G=MG1_EG(D,options.Verbose);
47if (~isempty(G))
48 return
49end
50
51epsilon=10^(-14);
52m=size(D,1);
53f=size(D,2)/m-1;
54
55maxd=size(D,2)/m-1;
56sumD=D(:,maxd*m+1:end);
57beta=sum(sumD,2);
58% beta = (D_maxd)e + (D_maxd + D_maxd-1)e + ... + (Dmaxd+...+D1)e
59for i=maxd-1:-1:1
60 sumD=sumD+D(:,i*m+1:(i+1)*m);
61 beta=beta+sum(sumD,2);
62end
63sumD=sumD+D(:,1:m);
64theta=stat(sumD);
65drift=theta*beta-1;
66
67% Step 1, F(z)=z-A(z)
68for i=0:f
69 F{i+1}=-D(:,i*m+1:(i+1)*m);
70end
71F{2}=eye(m)+F{2};
72
73% 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
74for i=0:f
75 H{i+1}=zeros(m,m);
76end
77for i=0:f
78 temp1=[1 -1];
79 temp2=[1 1];
80 con1=1;
81 con2=1;
82 for j=1:f-i
83 con1=conv(con1,temp1);
84 end
85 for j=1:i
86 con2=conv(con2,temp2);
87 end
88 contrib=conv(con1,con2);
89 for j=0:f
90 H{j+1}=H{j+1}+contrib(j+1)*F{i+1};
91 end
92end
93
94clear F;
95
96% Step 3, \hat{H}_i = H_f^-1*H_i
97H{f+1}=inv(H{f+1});
98for i=0:f-1
99 hatH{i+1}=H{f+1}*H{i+1};
100end
101
102% Step 4, y, xT
103y=[ones(m,1); zeros(m*(f-1),1)];
104x0T=[zeros(1,m) 1] / [hatH{1} ones(m,1)];
105for i=1:f-1
106 xT(1,(i-1)*m+1:i*m)=x0T*hatH{i+1};
107end
108xT(1,(f-1)*m+1:f*m)=x0T;
109
110% Step 5, E_m in Zold
111Zold=zeros(m*f,m*f);
112for i=1:f-1
113 Zold((i-1)*m+1:i*m,i*m+1:(i+1)*m)=eye(m);
114end
115for i=0:f-1
116 Zold(m*(f-1)+1:m*f,i*m+1:(i+1)*m)=-hatH{i+1};
117end
118y=y/(xT*y);
119Zold=Zold+sign(drift)*y*xT;
120
121% Step 6, classic matrix sign function algorithm
122if ( exist('ordschur') ~= 5 || ~strcmp(options.Mode,'Schur'))
123 % Step 6, classic matrix sign function algorithm
124 if (strcmp('Schur',options.Mode))
125 fprintf('Ordschur not supported by current MATLAB version\n');
126 fprintf('An automatic switch is performed to the MSignBalzer Mode\n');
127 drawnow;
128 end
129 Znew=(Zold+inv(Zold))/2;
130 numit=0;
131 check=1;
132 while (check > epsilon && numit < options.MaxNumIt)
133 numit=numit+1;
134 Zold=Znew;
135 if (strcmp(options.Mode,'MSignStandard'))
136 determ=1/2;
137 else
138 determ=(1+abs(det(Zold))^(1/(m*f)))^(-1);
139 end
140 Znew=determ*Zold+(1-determ)*inv(Zold);
141 check=norm(Znew-Zold,1)/norm(Zold,1);
142 if (options.Verbose==1)
143 fprintf('Check after %d iterations: %d\n',numit,check);
144 drawnow;
145 end
146 end
147 if (numit == options.MaxNumIt && check > epsilon)
148 warning('Maximum Number of Iterations %d reached: T may not have m columns',numit);
149 end
150 % Step 7,
151 T=orth(Znew-eye(m*f));
152else
153 [T,U]=schur(Zold);
154 [T,U]=ordschur(T,U,'lhp');
155 T=T(:,1:m);
156end
157
158% Step 8,
159G=(T(1:m,:)+T(m+1:2*m,:))*inv(T(1:m,:)-T(m+1:2*m,:));
160if (options.Verbose==1)
161 temp=D(:,end-m+1:end);
162 for i=size(D,2)/m-1:-1:1
163 temp=D(:,(i-1)*m+1:i*m)+temp*G;
164 end
165 res_norm=norm(G-temp,inf);
166 fprintf('Final Residual Error for G: %d\n',res_norm);
167end
168