about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/graph/mk_rnd_dag_given_edge_prob.m
blob: 205e5b516bd55d2a96cacc4920f49c4ad162d533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function dag = sample_dag(P)
% SAMPLE_DAG Create a random directed acyclic graph with edge probabilities P(i,j)
% dag = sample_dag(P)
%
% This uses rejection sampling to reject graphs with directed cycles.

done = 0;
directed = 1;
iter = 1;
while ~done
  dag = binornd(1, P); % each edge is an indep Bernoulli (0/1) random variable
  dag = setdiag(dag, 0);
  done = acyclic(dag, directed);
  iter = iter + 1
end