-
Notifications
You must be signed in to change notification settings - Fork 0
/
causet_get_chains.m
33 lines (31 loc) · 1.01 KB
/
causet_get_chains.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
function chains = causet_get_chains( C, degree )
%CAUSET_GET_CHAINS the numbers of total ordered k-chains in the
% (sub)-causet with causal matrix C up to k = DEGREE.
%
% Arguments:
% C upper triangular (logical) causals matrix.
%
% Optional arguments:
% DEGREE maximal chain to be returned (length of return
% vector). (Default: 2)
%
% Returns:
% CHAINS row vector of length DEGREE with counts of total
% ordered k tuples (k-chains).
%
% Copyright 2021, C. Minz. BSD 3-Clause License.
%% set default values:
if nargin < 2 || degree < 1
degree = 2;
end
%% compute link matrix powers and chain counts:
chains = zeros( 1, degree );
chains( 1 ) = length( C );
C = double( C );
Cpower = C;
for i = 2 : ( degree - 1 )
chains( i ) = sum( sum( Cpower > 0, 1 ), 2 );
Cpower = Cpower * C;
end
chains( degree ) = sum( sum( Cpower > 0, 1 ), 2 );
end