LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ldqbd_R.m
1%{ @file ldqbd_R.m
2 % @brief Computes rate matrices for level-dependent QBD processes
3 %
4 % @author QORE Lab, Imperial College London (Algorithm by Phung-Duc et al.)
5%}
6
7%{
8 % @brief Computes all rate matrices R^(n) for a level-dependent QBD
9 %
10 % @details
11 % This function implements the backward recursion algorithm for computing
12 % rate matrices of level-dependent QBD processes with heterogeneous dimensions.
13 %
14 % For a level-dependent QBD with levels 0, 1, ..., N:
15 % R^(N) = Q0^(N-1) * (-Q1^(N))^{-1}
16 % R^(n) = Q0^(n-1) * (-Q1^(n) - R^(n+1) * Q2^(n+1))^{-1} for n = N-1,...,1
17 %
18 % Dimensions:
19 % R^(n) is (states at level n-1) x (states at level n)
20 % Q0^(n-1) is (states at level n-1) x (states at level n)
21 % Q1^(n) is (states at level n) x (states at level n)
22 % Q2^(n) is (states at level n) x (states at level n-1)
23 %
24 % @par Syntax:
25 % @code
26 % R = ldqbd_R(Q0, Q1, Q2)
27 % R = ldqbd_R(Q0, Q1, Q2, options)
28 % @endcode
29 %
30 % @par Parameters:
31 % <table>
32 % <tr><th>Name<th>Description
33 % <tr><td>Q0<td>Cell array {Q0^(0), Q0^(1), ..., Q0^(N-1)} - upward transitions
34 % <tr><td>Q1<td>Cell array {Q1^(0), Q1^(1), ..., Q1^(N)} - local transitions
35 % <tr><td>Q2<td>Cell array {Q2^(1), Q2^(2), ..., Q2^(N)} - downward transitions
36 % <tr><td>options<td>Optional struct with fields: verbose (default false)
37 % </table>
38 %
39 % @par Returns:
40 % <table>
41 % <tr><th>Name<th>Description
42 % <tr><td>R<td>Cell array {R^(1), R^(2), ..., R^(N)} - rate matrices
43 % </table>
44 %
45 % @par Reference:
46 % T. Phung-Duc, H. Masuyama, S. Kasahara, Y. Takahashi, "A Simple Algorithm
47 % for the Rate Matrices of Level-Dependent QBD Processes", QTNA 2010.
48%}
49function R = ldqbd_R(Q0, Q1, Q2, varargin)
50
51% Parse options
52if nargin >= 4 && ~isempty(varargin{1})
53 options = varargin{1};
54else
55 options = struct();
56end
57
58if ~isfield(options, 'verbose'), options.verbose = false; end
59
60% Determine number of levels
61N = length(Q1) - 1; % Maximum level
62
63if options.verbose
64 fprintf('LD-QBD Rate Matrix Computation: N=%d levels\n', N);
65end
66
67% Initialize R cell array
68R = cell(N, 1);
69
70% Start at level N (boundary): R^(N) = Q0^(N-1) * (-Q1^(N))^{-1}
71Q0_Nminus1 = Q0{N}; % Q0^(N-1)
72Q1_N = Q1{N+1}; % Q1^(N)
73
74U = -Q1_N;
75if numel(U) == 1
76 if abs(U) > 1e-14
77 R{N} = Q0_Nminus1 / U;
78 else
79 R{N} = Q0_Nminus1 * 0;
80 end
81else
82 if abs(det(U)) > 1e-14
83 R{N} = Q0_Nminus1 / U;
84 else
85 R{N} = Q0_Nminus1 * pinv(U);
86 end
87end
88
89% Backward recursion for n = N-1 down to 1
90for n = N-1:-1:1
91 % R^(n) = Q0^(n-1) * (-Q1^(n) - R^(n+1) * Q2^(n+1))^{-1}
92 Q0_nminus1 = Q0{n}; % Q0^(n-1): (states at n-1) x (states at n)
93 Q1_n = Q1{n+1}; % Q1^(n): (states at n) x (states at n)
94 Q2_nplus1 = Q2{n+1}; % Q2^(n+1): (states at n+1) x (states at n)
95 R_nplus1 = R{n+1}; % R^(n+1): (states at n) x (states at n+1)
96
97 % Compute R^(n+1) * Q2^(n+1): (states at n) x (states at n)
98 RQ2 = R_nplus1 * Q2_nplus1;
99
100 % Compute U = -Q1^(n) - R^(n+1) * Q2^(n+1)
101 U = -Q1_n - RQ2;
102
103 % Compute R^(n) = Q0^(n-1) * U^{-1}
104 if numel(U) == 1
105 if abs(U) > 1e-14
106 R{n} = Q0_nminus1 / U;
107 else
108 R{n} = Q0_nminus1 * 0;
109 end
110 else
111 if abs(det(U)) > 1e-14
112 R{n} = Q0_nminus1 / U;
113 else
114 R{n} = Q0_nminus1 * pinv(U);
115 end
116 end
117end
118
119if options.verbose
120 for n = 1:N
121 fprintf(' R^(%d) computed (%dx%d)\n', n, size(R{n}, 1), size(R{n}, 2));
122 end
123end
124
125end