LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MG1_NI_LRAi.m
1function G=MG1_NI_LRAi(A0, Ahat, Gamma, varargin)
2% Newton Iteration for M/G/1-Type Markov Chains, exploiting low-rank Ai,
3% for i=1,...,N.
4%
5% G=MG1_NI_LRAi(A0, Ahat, Gamma) solves G = A0 + A1 G + A2 G^2 + A3 G^3 + ... + A_N G^N,
6% where A0, A1,...,AN are mxm nonnegative matrices such that
7% (A0+A1+A2+...+AN) is irreducible and stochastic.
8% Ai can be written as Ai = Gamma*Aihat, for i = 1,...,N, with Aihat rxm
9% matrices and Gamma an mxr matrix.
10% Ahat = [A1hat A2hat A3hat ... ANhat] has r rows and m*N columns.
11%
12% Optional Parameters:
13%
14% Mode: method used to solve the linear system at each iteration
15% 'DirectSum': solves the system directly
16% 'RealSchur': applies a real Schur decomposition (default)
17% 'ComplexSchur': applies a complex Schur decomposition
18% MaxNumIt: Maximum number of iterations (default: 50)
19% EpsilonValue: Required accuracy, used as stop criterium (default:10^(-14))
20% Verbose: The residual error is printed at each step when set to 1,
21% (default:0)
22
23
24OptionNames=['Mode ';
25 'MaxNumIt ';
26 'EpsilonValue';
27 'Verbose '];
28OptionTypes=['char ';
29 'numeric';
30 'numeric';
31 'numeric'];
32OptionValues{1}=['DirectSum ';
33 'RealSchur ';
34 'ComplexSchur '];
35
36
37options=[];
38for i=1:size(OptionNames,1)
39 options.(deblank(OptionNames(i,:)))=[];
40end
41
42% Default settings
43m = size(A0,1);
44options.Mode='RealSchur';
45options.MaxNumIt=50;
46options.Verbose=0;
47options.EpsilonValue=10^(-14);
48
49% Parse Optional Parameters
50options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
51
52
53N = size(Ahat,2)/m;
54r = size(Ahat,1);
55
56check = 1;
57numit = 1;
58
59Uhat = zeros(r,m);
60while(check > options.EpsilonValue && numit < options.MaxNumIt)
61 Uhatold = Uhat;
62
63 %Compute B: matrices premultiplying Y_k, and C: right-hand side
64 Uinv=eye(m)+Gamma*inv(eye(r)-Uhatold*Gamma)*Uhatold;
65 K = Uinv*A0;
66 B = zeros(r, (N-1)*r);
67 temp = Ahat(:,(N-1)*m+1:N*m);
68 UinvG = Uinv*Gamma;
69 for i=N-2:-1:0
70 B(:,i*r+1:(i+1)*r) = temp*UinvG;
71 temp = Ahat(:,i*m+1:(i+1)*m)+temp*K;
72 end
73 C = Uhatold-temp;
74 B = [-eye(r) B];
75
76 checkB = 0;
77 k = N;
78 while k > 1 && checkB < options.EpsilonValue
79 checkB = norm(B(:, (k-1)*r+1:k*r), 'inf');
80 k = k-1;
81 end
82
83 if k < N-1
84 B = B(:,1:(k+1)*r);
85 end
86
87 if strfind(options.Mode,'RealSchur') > 0
88 Y = solveSylvPowersRealSchur_FW(K, B, C);
89 elseif strfind(options.Mode,'ComplexSchur') > 0
90 Y = solveSylvPowersComplexSchur_FW(K, B, C);
91 else
92 Y = solveSylvPowersDirectSum(K, B, C);
93 end
94
95 Uhat = Uhat + Y;
96 check=norm(Uhat-Uhatold,inf);
97 numit = numit + 1;
98 if (~mod(numit,options.Verbose))
99 fprintf('Check after %d iterations: %d\n',numit,check);
100 end
101end
102G = inv(eye(m) - Gamma*Uhat)*A0;
103
104if (numit == options.MaxNumIt)
105 warning('Maximum Number of Iterations %d reached',numit);
106end
107
108if (options.Verbose>0)
109 A = A0;
110 for j = 1:N
111 A = [A Gamma*Ahat(:,(j-1)*m+1:j*m)];
112 end
113 temp=A(:,end-m+1:end);
114 for i=N:-1:1
115 temp=A(:,(i-1)*m+1:i*m)+temp*G;
116 end
117 res_norm=norm(G-temp,inf);
118 fprintf('Final Residual Error for G: %d\n',res_norm);
119end