1%{ @file ctmc_relsolve.m
2 % @brief Computes the equilibrium distribution relative to a reference state
4 % @author LINE Development Team
8 % @brief Computes the equilibrium distribution relative to a reference state
11 % Solves the global balance equations with the normalization condition p(refstate) = 1.
15 % p = ctmc_relsolve(Q)
16 % [p, Q, nConnComp, connComp] = ctmc_relsolve(Q, refstate)
17 % [p, Q, nConnComp, connComp] = ctmc_relsolve(Q, refstate, options)
22 % <tr><th>Name<th>Description
23 % <tr><td>Q<td>Infinitesimal generator matrix
24 % <tr><td>refstate<td>(Optional) Index of the reference state (
default: 1)
25 % <tr><td>options<td>(Optional) Solver options
30 % <tr><th>Name<th>Description
31 % <tr><td>p<td>Relative equilibrium distribution vector
32 % <tr><td>Q<td>Processed generator matrix
33 % <tr><td>nConnComp<td>Number of connected components
34 % <tr><td>connComp<td>Component assignment vector
37function [p, Q, nConnComp, connComp]=ctmc_relsolve(Q,refstate,options)
43if length(Q) > 6000 && (nargin==1 || ~options.force)
44 fprintf(1,
'ctmc_solve: the order of Q is greater than 6000, i.e., %d elements. Press key to continue.',length(Q));
53Q = ctmc_makeinfgen(Q); % so that spurious diagonal elements are set to 0
57 symvariables = symvar(Q); % find all symbolic variables
58 B = double(subs(Q+Q
',symvariables,ones(size(symvariables)))); % replace all symbolic variables with 1.0
62[nConnComp, connComp] = weaklyconncomp(B);
65 % reducible generator - solve each component recursively
72 Qc = Q(connComp==c,connComp==c);
73 Qc = ctmc_makeinfgen(Qc);
74 p(connComp==c) = ctmc_solve(Qc);
89Qnnz_1 = Qnnz; bnnz_1 = bnnz;
96 % zerorow=find(sum(abs(Qnnz),2)==0);
97 % if length(zerorow)>=1
98 % if nargin==1 || options.verbose
99 % %warning('ctmc_solve: the infinitesimal generator
is reducible (zero row)');
100 % fprintf(1,'ctmc_solve: the infinitesimal generator
is reducible.\n');
101 % isReducible = true;
104 % nnzrow = setdiff(nnzel, zerorow);
106 % zerocol=find(sum(abs(Qnnz),1)==0);
107 % nnzcol = setdiff(nnzel, zerocol);
108 % if length(zerocol)>=1
109 % if ~isReducible && (nargin==1 || options.verbose)
110 % %warning('ctmc_solve: the infinitesimal generator
is reducible (zero column)');
111 % fprintf(1,'ctmc_solve: the infinitesimal generator
is reducible.\n');
114 % nnzel = intersect(nnzrow, nnzcol);
116 nnzel = find(sum(abs(Qnnz),1)~=0 & sum(abs(Qnnz),2)'~=0);
117 if length(nnzel) < n && ~isReducible
119 if (nargin > 1 && options.verbose == 2) % debug
120 fprintf(1,'ctmc_solve: the infinitesimal generator
is reducible.\n');
123 Qnnz = Qnnz(nnzel, nnzel);
125 Qnnz = ctmc_makeinfgen(Qnnz);
126 if all(size(Qnnz_1(:)) == size(Qnnz(:))) && all(size(bnnz_1(:)) == size(bnnz(:)))
129 Qnnz_1 = Qnnz; bnnz_1 = bnnz; nnzel = 1:length(Qnnz);
138Qnnz(refstate,end) = 1;
148 p(nnzel)=Qnnz'\ bnnz;
150 switch options.method
153 gQnnz = gpuArray(Qnnz');
154 gbnnz = gpuArray(bnnz);
155 pGPU = gQnnz \ gbnnz;
156 gathered_pGPU = gather(pGPU);
157 p(nnzel) = gathered_pGPU; % transfer from GPU to local env
159 warning('ctmc_solve: GPU either not available or execution failed. Switching to default method.');
160 p(nnzel) = Qnnz'\ bnnz;
163 p(nnzel)=Qnnz'\ bnnz;