1function [p,p_1,pcourt,Qperm,eps,epsMAX]=ctmc_takahashi(Q,MS,numSteps)
2% CTMC_TAKAHASHI - Takahashi
's aggregation-disaggregation method
3% [p,p_1,pcourt,Qperm,eps,epsMAX] = CTMC_TAKAHASHI(Q,MS,numSteps)
5% Q : infinitesimal generator matrix
6% MS : cell array where MS{i} is the set of rows of Q in macrostate i
7% numSteps: number of iterative steps
9% p : estimated steady-state probability vector
11% pcourt : steady-state probability vector estimated by ctmc_courtois
12% Qperm : permuted Q matrix w.r.t MS as returned by ctmc_courtois
13% eps : NCD index as returned by ctmc_courtois
14% epsMAX : max acceptable value for eps (otherwise Q is not NCD)
16% * The initial approximate solutions is obtained by calling CTMC_COURTOIS(Q,MS)
17% * No convergence stop criterion is currently implented
20nMacroStates = size(MS,1); % Number of macro-states
22%% START FROM COURTOIS DECOMPOSITION SOLUTION
23[pcourt,Qperm,Qdec,eps,epsMAX,P,B,C,q]=ctmc_courtois(Q,MS);
24% see _kb/03-api-layer.md (CTMC aggregation-disaggregation) for the randomization rationale
25P=ctmc_randomization(Q,1.05*max(max(abs(Q))));
28% see _kb/03-api-layer.md (CTMC aggregation-disaggregation) for the MS{I} indexing rationale
34G=zeros(nMacroStates,nMacroStates);
35for I = 1:nMacroStates % for each source macro-state
38 for J = 1:nMacroStates %
for dest macro-state
44 G(I,J)=G(I,J)+P(idxI(i),idxJ(j))*pn_1(idxI(i))/S;
51for i = 1:nMacroStates % for each source macro-state
54gamma=dtmc_solve(G); %compute macroprobabilities
57GI=zeros(nMacroStates,nStates);
58for I = 1:nMacroStates % for each source macro-state
61 % The aggregation step above already guards on S>1e-14; dividing here by
62 % the same S unguarded put NaN into the iterate whenever a macro-state
63 % carried no probability. Zero
is the S->0 limit of the contribution.
66 GI(I,j)=GI(I,j)+sum(
P(idxI,j).*pn_1(idxI)
')/S;
70for I = 1:nMacroStates % for each source macro-state
72 A=eye(length(idxI),length(idxI));
73 b=zeros(length(idxI),1);
76 A(i,j)=A(i,j)-
P(idxI(j),idxI(i));
80 b(i)=b(i)+gamma(K)*GI(K,idxI(i));
86 [xg,gflag]=ctmc_gmres(sparse(A),b);