function [intra, inter, node_sizes, obs_nodes] = mk_cancer_topology(N, single_obs, rnd)
% MK_CANCER_TOPOLOGY Make the topology of a DBN for a toy model of how (indicators of) cancer spread through a genome.
% [intra, inter, node_sizes, obs_nodes] = mk_cancer_topology(N, single_obs, rnd)
%
% If single_obs = true, all the hidden nodes are connected to a single observable leaf, as in an HMM.
% This leaf encodes the state of the hidden nodes, are has the extra value "unknown".
% If single_obs = false, each hidden node gets its own observable node.
%
% See "Learning the structure of Dynamic Probabilistic Networks", Friedman, Murphy and Russell,
% UAI 1998, for results on learning this structure from data.

if nargin < 3, rnd = 0; end

if rnd
  M = reshape(rand(N,N) > 0.6);
  M = set_diag(M, 1);
else
  M = eye(N);
  if N==5
    M(1,2) = 1; M(1,3) = 1;
    M(2,4) = 1;
    M(3,4) = 1;
    M(4,5) = 1;
  elseif N==10
    M(1,2) = 1;
    M(2,4) = 1; M(2,5) = 1;
    M(3,1) = 1;
    M(4,3) = 1; M(4,6) = 1;
    M(5,7) = 1;
    M(6,7) = 1;
    M(7,8) = 1;
    M(8,9) = 1;
    M(9,10) = 1;
    M(10,5) = 1;
  end
end

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;
  node_sizes = [twos(1,N) (2^N)+1];
else
  intra(state_nodes, obs_nodes) = eye(N);
  node_sizes = twos(1,2*N);
end



