function bnet = unroll_dbn(bnet, T)
% UNROLL_DBN Make the DBN able to represent a sequence of length T.
% bnet = unroll_dbn(bnet, T)

% We line up the vectors vertically to make T columns. They can still be accessed sequentially.

ss = bnet.slice_size;
bnet.equiv_class = [bnet.equiv_class_slice1(:) bnet.equiv_class_slice2(:) ...
                    repmat(bnet.equiv_class_slice2(:), 1, T-2)];
num_equiv_classes = max(bnet.equiv_class(:));	      
bnet.members_of_equiv_class = inverse_relation(num2cell(bnet.equiv_class(:)), num_equiv_classes);
bnet.discrete_nodes = unroll_set(bnet.discrete_slice(:), ss, T);
bnet.cts_nodes = unroll_set(bnet.cts_slice(:), ss, T);
bnet.node_sizes = repmat(bnet.node_sizes_slice(:), 1, T); 
bnet.blocks = repmat(bnet.blocks_slice(:), 1, T);  
bnet.num_nodes = bnet.slice_size*T;
bnet.adj_mat = unroll_dbn_topology(bnet.intra1, bnet.intra, bnet.inter, T);
bnet.num_slices = T;

% The following will be true if the observation pattern is constant across slices
% but may get changed inside enter_evidence
bnet.observed_nodes = unroll_set(bnet.observed_slice(:), ss, T);
bnet.hidden_nodes = unroll_set(bnet.hidden_slice(:), ss, T);
