LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
generator_to_jumps.m
1function [all_jumps, rateBase, eventIdx] = generator_to_jumps(W)
2% [ALL_JUMPS, RATEBASE, EVENTIDX] = GENERATOR_TO_JUMPS(W)
3%
4% Convert infinitesimal generator matrix to jump/rate representation
5%
6% Input:
7% W: [n_states x n_states] infinitesimal generator matrix
8% W(i,j) = rate of transition from state i to state j (i~=j)
9% W(i,i) = -sum of outgoing rates from state i
10%
11% Output:
12% all_jumps: [n_states x n_transitions] matrix of state change vectors
13% rateBase: [n_transitions x 1] vector of transition rates
14% eventIdx: [n_transitions x 1] vector of source state indices
15%
16% Copyright (c) 2012-2026, Imperial College London
17% All rights reserved.
18
19n_states = size(W, 1);
20
21% Find all non-zero off-diagonal elements
22[src_states, dst_states, rates] = find(W);
23
24% Filter out diagonal elements and zero/negative rates
25off_diag_mask = (src_states ~= dst_states) & (rates > 0);
26src_states = src_states(off_diag_mask);
27dst_states = dst_states(off_diag_mask);
28rates = rates(off_diag_mask);
29
30n_transitions = length(rates);
31
32% Pre-allocate outputs
33all_jumps = zeros(n_states, n_transitions);
34rateBase = rates;
35eventIdx = src_states;
36
37% Construct jump vectors
38for t = 1:n_transitions
39 src = src_states(t);
40 dst = dst_states(t);
41
42 % Jump: decrease at source, increase at destination
43 all_jumps(src, t) = -1;
44 all_jumps(dst, t) = +1;
45end
46
47end % generator_to_jumps