function c2tbn = canonize( dag, ss, gnames ) % ss marks the halfway mark between the two time slices % names supplied in num2name.m keepers = zeros(1,ss); for i=1:ss, % keep all the t-1 nodes that have a link to t slice for j=(ss+1):(2*ss), if dag(i,j) == 1, keepers(i) = 1; break; end; end; end; % checking we didn't keep/avoid more for i=1:ss, if keepers(i) == 1, if nargin < 3, disp(num2name(i)); else disp(gnames(i)); end; end; end; c2tbn = keepers; % start deleting non-keepers sizeofc2tbn = length(find(keepers))+ss; pos_2ndslice = ss+1; c2tbn = dag; while 1, if length(c2tbn) <= sizeofc2tbn, break; else % if node doesn't have temporal link then delete it for i=1:length(c2tbn), node = i; found = 0; for j=pos_2ndslice:length(c2tbn), if c2tbn(i,j) == 1, found = 1; break; end; end; if found == 0, c2tbn = rmnode( c2tbn, node ); pos_2ndslice = pos_2ndslice - 1; break; end; end; end; end;