function [intra, inter, obs_nodes] = mk_rnd_can_dbn_topo(N, density, single_obs)
% MK_RND_CAN_DBN Make a random, yet canonical, DBN topology.
% [intra, inter, obs_nodes] = mk_rnd_can_dbn(N, density, single_obs)
%
% 'density' is the probability of an i->j inter-slice connection.
% If single_obs = 1, there is a single observable leaf per slice (as in a FHMM).
% Otherwise, each hidden node gets its own private observable leaf.

M = rand(N,N) < density;
M = setdiag(M, 1);

state_nodes = 1:N;
if single_obs
  obs_nodes = N+1;
else
  obs_nodes = [1:N] + N;
end
ss = length(state_nodes) + length(obs_nodes); % slice size
inter = zeros(ss);
inter(state_nodes, state_nodes) = M;

intra = zeros(ss);
if single_obs
  intra(state_nodes, obs_nodes) = 1;
else
  intra(state_nodes, obs_nodes) = eye(N);
end



