function M = unroll_dbn_topology(intra1, intra, inter, T)
% UNROLL_DBN_TOPOLOGY Make the adjacency matrix for a DBN consisting of T slices
% M = unroll_dbn_topology(intra1, intra, inter, T)
% intra is the connectivity within a slice, inter between two slices.
% M will have intra along the diagonal, and inter one above the diagonal.

ss = length(intra); % slice size
M = sparse(ss*T);
bs = repmat(ss, 1, T);
for t=1:T-1
  b = block(t,bs);
  M(b,b) = intra;
  M(b,block(t+1,bs)) = inter;
end
M(block(1,bs), block(1,bs)) = intra1;
if T>1
  M(block(T,bs), block(T,bs)) = intra;
end
