LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
eliminate_immediate_matrix.m
1function [W_red, state_map] = eliminate_immediate_matrix(W, sn, options)
2% [W_RED, STATE_MAP] = ELIMINATE_IMMEDIATE_MATRIX(W, SN, OPTIONS)
3%
4% Eliminate immediate states from infinitesimal generator matrix W
5%
6% Input:
7% W: [n_states x n_states] infinitesimal generator matrix
8% sn: Model structure
9% options: Solver options
10%
11% Output:
12% W_red: Reduced generator matrix
13% state_map: Mapping from reduced to original state indices
14%
15% Copyright (c) 2012-2026, Imperial College London
16% All rights reserved.
17
18% Get immediate detection threshold
19if isfield(options.config, 'immediate_tol')
20 imm_tol = options.config.immediate_tol;
21else
22 imm_tol = GlobalConstants.Immediate / 10; % Default: 1e7
23end
24
25% Identify immediate states (those with very high outgoing rates)
26max_rate_per_state = max(abs(W), [], 2);
27imm_states = find(max_rate_per_state >= imm_tol);
28
29% If no immediate states, return unchanged
30if isempty(imm_states)
31 W_red = W;
32 state_map = 1:size(W, 1);
33 return;
34end
35
36% Identify timed states
37timed_states = setdiff(1:size(W,1), imm_states);
38
39% Check that we have enough timed states remaining
40if isempty(timed_states) || length(timed_states) <= 1
41 % Too few timed states - elimination would produce a trivial system.
42 % Fall back to the original system without elimination.
43 W_red = W;
44 state_map = 1:size(W, 1);
45 return;
46end
47
48try
49 % Apply stochastic complement
50 [W_red, ~, ~, ~, Q22, ~] = ctmc_stochcomp(W, timed_states);
51
52 % Check conditioning
53 if rcond(full(Q22)) < 1e-12
54 warning('LINE:Fluid:IllConditioned', ...
55 'Immediate transition matrix ill-conditioned (rcond = %g)', rcond(full(Q22)));
56 end
57
58 state_map = timed_states;
59
60 % Report reduction
61 if isfield(options, 'verbose') && options.verbose > 0
62 reduction_pct = 100 * (1 - length(timed_states)/size(W,1));
63 line_printf(sprintf('State space reduced from %d to %d states (%.1f%% reduction)\n', ...
64 size(W,1), length(timed_states), reduction_pct));
65 end
66
67catch ME
68 % Elimination failed - fall back to original
69 warning('LINE:Fluid:EliminationFailed', ...
70 'Immediate transition elimination failed: %s. Using original system.', ME.message);
71 W_red = W;
72 state_map = 1:size(W, 1);
73end
74
75end % eliminate_immediate_matrix