LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ctmc_takahashi.m
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)
4% -- Input
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
8% -- Output
9% p : estimated steady-state probability vector
10% p_1 :
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)
15% -- Remarks
16% * The initial approximate solutions is obtained by calling CTMC_COURTOIS(Q,MS)
17% * No convergence stop criterion is currently implented
18
19%% INIT
20nMacroStates = size(MS,1); % Number of macro-states
21nStates=size(Q,1);
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))));
30%% STEP 0
31pn=pcourt;
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
37% sizes.
38%% MAIN LOOP
39for n=1:numSteps
40pn_1=pn;
41p_1=pn_1;
42%% AGGREGATION STEP
43G=zeros(nMacroStates,nMacroStates);
44for I = 1:nMacroStates % for each source macro-state
45 idxI=MS{I}(:)';
46 S=sum(pn_1(idxI));
47 for J = 1:nMacroStates % for dest macro-state
48 if I~=J
49 idxJ=MS{J}(:)';
50 for i=1:length(idxI)
51 for j=1:length(idxJ)
52 if S>1e-14
53 G(I,J)=G(I,J)+P(idxI(i),idxJ(j))*pn_1(idxI(i))/S;
54 end
55 end
56 end
57 end
58 end
59end
60for i = 1:nMacroStates % for each source macro-state
61 G(i,i)=1-sum(G(i,:));
62end
63gamma=dtmc_solve(G); %compute macroprobabilities
64
65%% DISAGGREGATION STEP
66GI=zeros(nMacroStates,nStates);
67for I = 1:nMacroStates % for each source macro-state
68 idxI=MS{I}(:)';
69 S=sum(pn_1(idxI));
70 for j=1:nStates
71 GI(I,j)=GI(I,j)+sum(P(idxI,j).*pn_1(idxI)')/S;
72 end
73end
74for I = 1:nMacroStates % for each source macro-state
75 idxI=MS{I}(:)';
76 A=eye(length(idxI),length(idxI));
77 b=zeros(length(idxI),1);
78 for i=1:length(idxI)
79 for j=1:length(idxI)
80 A(i,j)=A(i,j)-P(idxI(j),idxI(i));
81 end
82 for K=1:nMacroStates
83 if K~=I
84 b(i)=b(i)+gamma(K)*GI(K,idxI(i));
85 end
86 end
87 end
88 xI=[];
89 if size(A,1) > 6000
90 [xg,gflag]=ctmc_gmres(sparse(A),b);
91 if gflag==0
92 xI=xg;
93 end
94 end
95 if isempty(xI)
96 xI=A\b;
97 end
98 pn(idxI)=xI;
99end
100%% END LOOP
101pn=pn/sum(pn);
102end
103%% OUTPUT
104p=pn(:)';
105end