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 some timed states remaining
40if isempty(timed_states)
41 error('LINE:Fluid:AllImmediate', ...
42 'All states have immediate transitions - cannot eliminate');
43end
44
45try
46 % Apply stochastic complement
47 [W_red, ~, ~, ~, Q22, ~] = ctmc_stochcomp(W, timed_states);
48
49 % Check conditioning
50 if rcond(full(Q22)) < 1e-12
51 warning('LINE:Fluid:IllConditioned', ...
52 'Immediate transition matrix ill-conditioned (rcond = %g)', rcond(full(Q22)));
53 end
54
55 state_map = timed_states;
56
57 % Report reduction
58 if isfield(options, 'verbose') && options.verbose > 0
59 reduction_pct = 100 * (1 - length(timed_states)/size(W,1));
60 line_printf(sprintf('State space reduced from %d to %d states (%.1f%% reduction)\n', ...
61 size(W,1), length(timed_states), reduction_pct));
62 end
63
64catch ME
65 % Elimination failed - fall back to original
66 warning('LINE:Fluid:EliminationFailed', ...
67 'Immediate transition elimination failed: %s. Using original system.', ME.message);
68 W_red = W;
69 state_map = 1:size(W, 1);
70end
71
72end % eliminate_immediate_matrix