annotate toolboxes/FullBNT-1.0.7/graph/mk_rnd_dag.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [dag, order] = mk_rnd_dag(N, max_fan_in)
wolffd@0 2 % MY_MK_RND_DAG Create a random directed acyclic graph
wolffd@0 3 %
wolffd@0 4 % [dag, order] = my_mk_rnd_dag(N, max_fan_in)
wolffd@0 5 % max_fan_in defaults to N.
wolffd@0 6 % order is the random topological order that was chosen
wolffd@0 7
wolffd@0 8 % Modified by Sonia Leach 2/25/02
wolffd@0 9
wolffd@0 10 if nargin < 2, max_fan_in = N; end
wolffd@0 11
wolffd@0 12 order = randperm(N);
wolffd@0 13 dag = zeros(N,N);
wolffd@0 14 for i=2:N
wolffd@0 15 j = order(i);
wolffd@0 16 %k = sample_discrete(normalise(ones(1, min(i-1, max_fan_in))));
wolffd@0 17 k = sample_discrete(normalise(ones(1, min(i-1, max_fan_in)+1))) - 1; % min = 0 (bug fix due to
wolffd@0 18 % Pedrito, 7/28/04)
wolffd@0 19 SS = order(1:i-1); % get Set of possible parentS
wolffd@0 20 p = randperm(length(SS)); % permute order of set
wolffd@0 21 dag(SS(p(1:k)),j) = 1; % take first k in permuted order
wolffd@0 22
wolffd@0 23 % Kevin had:
wolffd@0 24 %SS = subsets(order(1:i-1), k, k);
wolffd@0 25 %p = sample_discrete(normalise(ones(1, length(SS))));
wolffd@0 26 %dag(SS{p}, j) = 1;
wolffd@0 27 end