LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
NSF_GHT.m
1function G=NSF_GHT(A,N,varargin)
2%NSF_GHT Gail, Hantler, Taylor algorithm for Non-Skip-Free Type Markov Chains
3%
4% G=NSF_GHT(A,N) computes the minimal nonnegative solution to the
5% matrix equation G = C0 + C1 G + C2 G^2 + C3 G^3 + ... + C_max G^max,
6% of the reblocked Non-Skip-Free Markov chain.
7% A = [A0 A1 A2 A3 ... A_max] has m rows and m*(max+1) columns and is
8% a nonnegative matrix, with (A0+A1+A2+...+A_max) irreducible and
9% stochastic. The parameter N identifies the number of non-zero blocks
10% below the main diagonal, the matrices Ci are of dimension mN.
11%
12% Optional Parameters:
13%
14% MaxNumIt: Maximum number of iterations (default: 10000)
15% Verbose: When set to k, the residual error is printed every
16% k steps (default:0)
17% FirstBlockRow: When set to one, only the first block row of G
18% is returned, which fully characterizes G (default:0)
19
20OptionNames=['MaxNumIt ';
21 'Verbose ';
22 'FirstBlockRow'];
23OptionTypes=['numeric';
24 'numeric';
25 'numeric'];
26OptionValues=[];
27
28options=[];
29for i=1:size(OptionNames,1)
30 options.(deblank(OptionNames(i,:)))=[];
31end
32
33% Default settings
34options.MaxNumIt=10000;
35options.Verbose=0;
36options.FirstBlockRow=0;
37
38% Parse Optional Parameters
39options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
40
41m=size(A,1);
42K=size(A,2)/m-1; % degree of A(z)
43numit=0;
44check=1;
45G=A(:,1:m*N);
46
47while(check > 10^(-14) && numit < options.MaxNumIt)
48 numit=numit+1;
49 Gold=G;
50 temp=G;
51 G=A(:,1:m*N)+A(:,m*N+1:m*(N+1))*G;
52 for j=N+1:K
53 temp=[zeros(m) temp(:,1:(N-1)*m)]+temp(:,(N-1)*m+1:end)*Gold;
54 G=G+A(:,j*m+1:(j+1)*m)*temp;
55 end
56 check=norm(G-Gold,inf);
57 if (~mod(numit,options.Verbose))
58 fprintf('Check after %d iterations: %d\n',numit,check);
59 drawnow;
60 end
61end
62
63if (numit == options.MaxNumIt && check > 10^(-14))
64 warning('Maximum Number of Iterations %d reached',numit);
65end
66
67if ( ~options.FirstBlockRow )
68 % compute remaining blockrows of G
69 G(m+1:N*m,1:N*m)=zeros(m*(N-1),m*N);
70 for j=2:N
71 G((j-1)*m+1:j*m,:)=[zeros(m) G((j-2)*m+1:(j-1)*m,1:(N-1)*m)]+...
72 G((j-2)*m+1:(j-1)*m,(N-1)*m+1:end)*G(1:m,:);
73 end
74end
75
76if (options.Verbose>0)
77 % we compute the residual error of first blockrow
78 if (~options.FirstBlockRow)
79 A=[A zeros(m,(N-1-mod(K,N))*m)];
80 Nb=size(A,2)/(m*N)-1;
81 Gcheck=A(:,Nb*N*m+1:end);
82 for j=Nb-1:-1:0
83 Gcheck=A(:,j*N*m+1:(j+1)*N*m)+Gcheck*G;
84 end
85 res_norm=norm(G(1:m,:)-Gcheck,inf);
86 fprintf('Final Residual Error for G: %d\n',res_norm);
87 end
88end