1function [all_jumps, rateBase, eventIdx] = generator_to_jumps(W)
2% [ALL_JUMPS, RATEBASE, EVENTIDX] = GENERATOR_TO_JUMPS(W)
4% Convert infinitesimal generator matrix to jump/rate representation
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
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
16% Copyright (c) 2012-2026, Imperial College London
21% Find all non-zero off-diagonal elements
22[src_states, dst_states, rates] = find(W);
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);
30n_transitions = length(rates);
33all_jumps = zeros(n_states, n_transitions);
37% Construct jump vectors
38for t = 1:n_transitions
42 % Jump: decrease at source, increase at destination
43 all_jumps(src, t) = -1;
44 all_jumps(dst, t) = +1;
47end % generator_to_jumps