-
Notifications
You must be signed in to change notification settings - Fork 0
/
causet_select_infsteps.m
37 lines (35 loc) · 1.26 KB
/
causet_select_infsteps.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function infsteps = causet_select_infsteps( L, steps )
%CAUSET_SELECT_INFSTEPS returns a N-vector holding the number of steps of
% the future/past infinity up to STEPS for each element in the causet.
% Unidentified elements are returned as NaN.
% Use Inf and -Inf to address 0 step future/past infinity and values
% STEPS > 0 for future, STEPS < 0 for past.
%
% Copyright 2021, C. Minz. BSD 3-Clause License.
N = size( L, 1 );
infsteps = NaN * zeros( 1, N ); % pre-allocate memory
if steps >= 0 % find future infinity steps:
direction = 1;
infsteps( sum( L, 2 ) == 0 ) = 0;
linkcounts = sum( L, 2 );
else % find past infinity steps:
direction = -1;
steps = -steps;
infsteps( sum( L, 1 ) == 0 ) = 0;
linkcounts = sum( L, 1 );
end
if isinf( steps )
steps = 0; % +/-Inf represents +/-0
end
for s = 1 : steps
select = ~isnan( infsteps );
if direction > 0
isinfstep = transpose( sum( L( :, select ), 2 ) == linkcounts ) ...
& ~select;
else
isinfstep = ( sum( L( select, : ), 1 ) == linkcounts ) ...
& ~select;
end
infsteps( isinfstep ) = s;
end
end