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% see _kb/03-api-layer.md (CTMC aggregation-disaggregation) for the randomization rationale
25P=ctmc_randomization(Q,1.05*max(max(abs(Q))));
26%% STEP 0
27pn=pcourt;
28% see _kb/03-api-layer.md (CTMC aggregation-disaggregation) for the MS{I} indexing rationale
29%% MAIN LOOP
30for n=1:numSteps
31pn_1=pn;
32p_1=pn_1;
33%% AGGREGATION STEP
34G=zeros(nMacroStates,nMacroStates);
35for I = 1:nMacroStates % for each source macro-state
36 idxI=MS{I}(:)';
37 S=sum(pn_1(idxI));
38 for J = 1:nMacroStates % for dest macro-state
39 if I~=J
40 idxJ=MS{J}(:)';
41 for i=1:length(idxI)
42 for j=1:length(idxJ)
43 if S>1e-14
44 G(I,J)=G(I,J)+P(idxI(i),idxJ(j))*pn_1(idxI(i))/S;
45 end
46 end
47 end
48 end
49 end
50end
51for i = 1:nMacroStates % for each source macro-state
52 G(i,i)=1-sum(G(i,:));
53end
54gamma=dtmc_solve(G); %compute macroprobabilities
55
56%% DISAGGREGATION STEP
57GI=zeros(nMacroStates,nStates);
58for I = 1:nMacroStates % for each source macro-state
59 idxI=MS{I}(:)';
60 S=sum(pn_1(idxI));
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.
64 if S>1e-14
65 for j=1:nStates
66 GI(I,j)=GI(I,j)+sum(P(idxI,j).*pn_1(idxI)')/S;
67 end
68 end
69end
70for I = 1:nMacroStates % for each source macro-state
71 idxI=MS{I}(:)';
72 A=eye(length(idxI),length(idxI));
73 b=zeros(length(idxI),1);
74 for i=1:length(idxI)
75 for j=1:length(idxI)
76 A(i,j)=A(i,j)-P(idxI(j),idxI(i));
77 end
78 for K=1:nMacroStates
79 if K~=I
80 b(i)=b(i)+gamma(K)*GI(K,idxI(i));
81 end
82 end
83 end
84 xI=[];
85 if size(A,1) > 6000
86 [xg,gflag]=ctmc_gmres(sparse(A),b);
87 if gflag==0
88 xI=xg;
89 end
90 end
91 if isempty(xI)
92 xI=A\b;
93 end
94 pn(idxI)=xI;
95end
96%% END LOOP
97pn=pn/sum(pn);
98end
99%% OUTPUT
100p=pn(:)';
101end