To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / graph / mk_rnd_dag_given_edge_prob.m @ 8:b5b38998ef3b
History | View | Annotate | Download (427 Bytes)
| 1 |
function dag = sample_dag(P) |
|---|---|
| 2 |
% SAMPLE_DAG Create a random directed acyclic graph with edge probabilities P(i,j) |
| 3 |
% dag = sample_dag(P) |
| 4 |
% |
| 5 |
% This uses rejection sampling to reject graphs with directed cycles. |
| 6 |
|
| 7 |
done = 0; |
| 8 |
directed = 1; |
| 9 |
iter = 1; |
| 10 |
while ~done |
| 11 |
dag = binornd(1, P); % each edge is an indep Bernoulli (0/1) random variable |
| 12 |
dag = setdiag(dag, 0); |
| 13 |
done = acyclic(dag, directed); |
| 14 |
iter = iter + 1 |
| 15 |
end |