LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
dtmc_stochcomp.m
1%{ @file dtmc_stochcomp.m
2 % @brief Computes the stochastic complement of a DTMC partition
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes the stochastic complement of a DTMC partition
9 %
10 % @details
11 % Performs stochastic complementation on a partitioned DTMC.
12 %
13 % @par Syntax:
14 % @code
15 % S = dtmc_stochcomp(P)
16 % [S, P11, P12, P21, P22] = dtmc_stochcomp(P, I)
17 % @endcode
18 %
19 % @par Parameters:
20 % <table>
21 % <tr><th>Name<th>Description
22 % <tr><td>P<td>Stochastic transition matrix
23 % <tr><td>I<td>(Optional) Vector of indices representing the subset of states to retain
24 % </table>
25 %
26 % @par Returns:
27 % <table>
28 % <tr><th>Name<th>Description
29 % <tr><td>S<td>Stochastic complement matrix for the subset I
30 % <tr><td>P11<td>Submatrix corresponding to transition within I
31 % <tr><td>P12<td>Submatrix corresponding to transitions from I to complement of I
32 % <tr><td>P21<td>Submatrix corresponding to transitions from complement of I to I
33 % <tr><td>P22<td>Submatrix corresponding to transitions within complement of I
34 % </table>
35%}
36function [S,P11,P12,P21,P22]=dtmc_stochcomp(P,I)
37if nargin==1
38 I=1:ceil(length(P)/2);
39end
40Iall = 1:length(P);
41Ic = Iall(~ismember(Iall,I)); % slightly faster than setdiff
42sparsity = nnz(P)/prod(size(P));
43if sparsity <0.05
44 P=sparse(P);
45 P11=P(I,I);
46 P12=P(I,Ic);
47 P21=P(Ic,I);
48 P22=P(Ic,Ic);
49 S2 = sparse(eye(size(P22))-P22);
50 S=P11+P12*(S2 \ P21);
51 S=full(S);
52else
53 P11=P(I,I);
54 P12=P(I,Ic);
55 P21=P(Ic,I);
56 P22=P(Ic,Ic);
57 S2 = eye(size(P22))-P22;
58 S=P11+P12*(S2 \ P21);
59end
60end