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% Randomize the UNPERMUTED Q. The rate is passed explicitly rather than left to
25% the ctmc_randomization default, which is max|Q|+rand and therefore unseeded:
26% the iteration below is invariant to q (the aggregation and disaggregation
27% equations are homogeneous in P-I = Q/q), so the random rate only injected
28% irreproducibility. 1.05*max|Q| is the same rate ctmc_courtois derives.
29P=ctmc_randomization(Q,1.05*max(max(abs(Q))));
32% P and pn are both in the ORIGINAL state ordering, so each macro-state is
33% addressed by the state indices MS{I} carries. The former contiguous offsets
34% (procRows+i) only coincide with MS{I} when every macro-state happens to be a
35% contiguous range of Q in original order: otherwise they read the CONTENTS of
36% MS{I} nowhere and silently solve for a different partition of the same block
43G=zeros(nMacroStates,nMacroStates);
44for I = 1:nMacroStates % for each source macro-state
47 for J = 1:nMacroStates %
for dest macro-state
53 G(I,J)=G(I,J)+P(idxI(i),idxJ(j))*pn_1(idxI(i))/S;
60for i = 1:nMacroStates % for each source macro-state
63gamma=dtmc_solve(G); %compute macroprobabilities
66GI=zeros(nMacroStates,nStates);
67for I = 1:nMacroStates % for each source macro-state
71 GI(I,j)=GI(I,j)+sum(
P(idxI,j).*pn_1(idxI)
')/S;
74for I = 1:nMacroStates % for each source macro-state
76 A=eye(length(idxI),length(idxI));
77 b=zeros(length(idxI),1);
80 A(i,j)=A(i,j)-
P(idxI(j),idxI(i));
84 b(i)=b(i)+gamma(K)*GI(K,idxI(i));
90 [xg,gflag]=ctmc_gmres(sparse(A),b);