LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MG1_pi.m
1function pi=MG1_pi(B,A,G,varargin)
2%MG1_pi Stationary vector of a Quasi-Birth-Death Markov Chains [Neuts, Ramaswami]
3%
4% pi=MG1_pi(B,A,G) computes the stationary vector of an M/G/1-type
5% Markov chain with a transition matrix of the form
6%
7% B0 B1 B2 B3 B4 ...
8% A0 A1 A2 A3 A4 ...
9% P = 0 A0 A1 A2 A3 ...
10% 0 0 A0 A1 A2 ...
11% ...
12%
13% the input matrix G is the minimal nonnegative solution to the matrix
14% equation G = A0 + A1 G + A2 G^2 + ... + Aamax G^amax
15% A = [A0 A1 ... Aamax] and B=[B0 B1 B2 ... Bbmax]
16%
17% pi=MG1_pi([],A,G) computes the stationary vector of an M/G/1-type
18% Markov chain with a transition matrix of the form
19%
20% A0 A1 A2 A3 A4 ...
21% A0 A1 A2 A3 A4 ...
22% P = 0 A0 A1 A2 A3 ...
23% 0 0 A0 A1 A2 ...
24% ...
25%
26% Optional Parameters:
27%
28% MaxNumComp: Maximum number of components (default: 500)
29% Verbose: The accumulated probability mass is printed at every
30% n steps when set to n (default:0)
31% Boundary: Allows solving the MG1 type Markov chain with a more
32% general boundary:
33%
34% B0 B1 B2 B3 B4 ...
35% C0 A1 A2 A3 A4 ...
36% P = 0 A0 A1 A2 A3 ...
37% 0 0 A0 A1 A2 ...
38% ...
39%
40% the parameter value contains the matrix C0.
41% The matrices C0 and B1,B2,... need not to be square.
42% (default: C0=A0)
43% InputPiZero: The first component of the steady state vector pi
44% can be given as input by setting this parameter value
45% equal to its first component pi_0 (default: not given)
46
47
48OptionNames=[
49 'MaxNumComp ';
50 'Verbose ';
51 'Boundary ';
52 'InputPiZero'];
53OptionTypes=[
54 'numeric';
55 'numeric';
56 'numeric';
57 'numeric'];
58
59OptionValues=[];
60
61options=[];
62for i=1:size(OptionNames,1)
63 options.(deblank(OptionNames(i,:)))=[];
64end
65
66% Default settings
67options.MaxNumComp=500;
68options.Verbose=0;
69options.Boundary=[];
70options.InputPiZero=[];
71
72% Parse Optional Parameters
73options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
74
75m=size(A,1);
76dega=size(A,2)/m-1;
77
78if (isempty(B))
79 mb=m;
80 degb=dega;
81 if (~isempty(options.Boundary))
82 B=A;
83 end
84else
85 mb=size(B,1);
86 if (mod(size(B,2)-mb,m) ~= 0)
87 error('Matrix B has an incorrect number of columns');
88 end
89 degb=(size(B,2)-mb)/m;
90end
91
92if (isempty(options.Boundary) & mb ~= m)
93 error('The Boundary option must be used as dimension of B0 is not identical to A0');
94end
95
96if (~isempty(options.Boundary))
97 if (size(options.Boundary,1) ~= m || size(options.Boundary,2) ~= mb)
98 error('The Boundary parameter value has an incorrect dimension');
99 end
100end
101% Compute theta and beta, sum_v>=0 Av and sum_v>=k Av G^v-1
102% the last sums (for k=1,...,amax) are stored in A
103sumA=A(:,dega*m+1:end);
104beta=sum(sumA,2);
105% beta = (A_maxd)e + (A_maxd + A_maxd-1)e + ... + (Amaxd+...+A1)e
106for i=dega-1:-1:1
107 sumA=sumA+A(:,i*m+1:(i+1)*m);
108 A(:,i*m+1:(i+1)*m)=A(:,i*m+1:(i+1)*m)+A(:,(i+1)*m+1:(i+2)*m)*G;
109 beta=beta+sum(sumA,2);
110end
111sumA=sumA+A(:,1:m);
112theta=stat(sumA);
113drift=theta*beta;
114
115if (drift >= 1)
116 error('MATLAB:MG1_pi:NotPossitiveRecurrent',...
117 'The Markov chain characterized by A is not positive recurrent');
118end
119
120
121if (isempty(options.InputPiZero))
122 % Compute g
123 g=stat(G);
124
125 if (isempty(B))
126 % Compute pi_0
127 pi0=(1-drift)*g;
128 else
129 % Compute sum_v>=1 Bv, sum_v>=1 (v-1) Bv e, sum_v>=k Bv G^v-1
130 % the last sums (for k=1,...,bmax) are stored in B
131 sumBB0=B(:,mb+(degb-1)*m+1:end);
132 Bbeta=zeros(mb,1);
133 for i=degb-1:-1:1
134 Bbeta=Bbeta+sum(sumBB0,2);
135 sumBB0=sumBB0+B(:,mb+(i-1)*m+1:mb+i*m);
136 B(:,mb+(i-1)*m+1:mb+i*m)=B(:,mb+(i-1)*m+1:mb+i*m)+B(:,mb+i*m+1:mb+(i+1)*m)*G;
137 end
138
139
140 % Compute K, kappa
141 if (isempty(options.Boundary)) %m=mb
142 K=B(:,1:mb)+B(:,mb+1:mb+m)*G;
143 else
144 L=(eye(m)-A(:,m+1:2*m))^(-1)*options.Boundary;
145 K=B(:,1:mb)+B(:,mb+1:mb+m)*L;
146 end
147 kappa=stat(K);
148
149 % Compute psi1, psi2
150 temp=sum((eye(m)-sumA-(ones(m,1)-beta)*g)^(-1),2);
151 psi1=(eye(m)-A(:,1:m)-A(:,m+1:2*m))*temp+...
152 (1-drift)^(-1)*sum(A(:,1:m),2);
153 psi2=ones(mb,1)+(sumBB0-B(:,mb+1:mb+m))*temp+(1-drift)^(-1)*Bbeta;
154
155 % Compute kappa1
156 tildekappa1=psi2+B(:,mb+1:mb+m)*(eye(m)-A(:,m+1:2*m))^(-1)*psi1;
157
158 % Compute pi_0
159 pi0=(kappa*tildekappa1)^(-1)*kappa;
160 end
161else
162 if (~isempty(B))
163 % Compute sum_v>=1 Bv, sum_v>=1 (v-1) Bv e, sum_v>=k Bv G^v-1
164 % the last sums (for k=1,...,bmax) are stored in B
165 sumBB0=B(:,mb+(degb-1)*m+1:end);
166 Bbeta=zeros(mb,1);
167 for i=degb-1:-1:1
168 Bbeta=Bbeta+sum(sumBB0,2);
169 sumBB0=sumBB0+B(:,mb+(i-1)*m+1:mb+i*m);
170 B(:,mb+(i-1)*m+1:mb+i*m)=B(:,mb+(i-1)*m+1:mb+i*m)+B(:,mb+i*m+1:mb+(i+1)*m)*G;
171 end
172 end
173 pi0=options.InputPiZero;
174end
175
176numit=1;
177sumpi=sum(pi0);
178pi = [];
179
180% Start stable RAMASWAMI formula
181invbarA1=(eye(m)-A(:,m+1:2*m))^(-1);
182while (sumpi < 1-10^(-10) && numit < options.MaxNumComp)
183 if (numit <= degb)
184 if (isempty(B))%mb=m
185 pi(numit,1:m)=pi0*A(:,numit*mb+1:(numit+1)*mb);
186 else
187 pi(numit,1:m)=pi0*B(:,mb+(numit-1)*m+1:mb+numit*m);
188 end
189 else
190 pi(numit,1:m)=zeros(1,m);
191 end
192 for j=1:min(numit-1,dega-1)
193 pi(numit,1:m)=pi(numit,1:m)+...
194 pi(numit-j,:)*A(:,(j+1)*m+1:(j+2)*m);
195 end
196 pi(numit,:)=pi(numit,:)*invbarA1;
197 sumpi=sumpi+sum(pi(numit,:));
198 if (~mod(numit,options.Verbose))
199 fprintf('Accumulated mass of the first %d (reblocked) components: %d\n',numit,sumpi);
200 drawnow;
201 end
202 numit=numit+1;
203end
204pi=[pi0 reshape(pi',1,[])];
205if (numit == options.MaxNumComp)
206 warning('Maximum Number of Components %d reached',numit);
207end