comparison toolboxes/FullBNT-1.0.7/bnt/general/mk_mutilated_samples.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [data, clamped] = mk_mutilated_samples(bnet, ncases, max_clamp, usecell)
2 % GEN_MUTILATED_SAMPLES Do random interventions and then draw random samples
3 % [data, clamped] = gen_mutilated_samples(bnet, ncases, max_clamp, usecell)
4 %
5 % At each step, we pick a random subset of size 0 .. max_clamp, and
6 % clamp these nodes to random values.
7 %
8 % data(i,m) is the value of node i in case m.
9 % clamped(i,m) = 1 if node i in case m was set by intervention.
10
11 if nargin < 4, usecell = 1; end
12
13 ns = bnet.node_sizes;
14 n = length(bnet.dag);
15 if usecell
16 data = cell(n, ncases);
17 else
18 data = zeros(n, ncases);
19 end
20 clamped = zeros(n, ncases);
21
22 csubsets = subsets(1:n, max_clamp, 0); % includes the empty set
23 distrib_cset = normalise(ones(1, length(csubsets)));
24
25 for m=1:ncases
26 cset = csubsets{sample_discrete(distrib_cset)};
27 nvals = prod(ns(cset));
28 distrib_cvals = normalise(ones(1, nvals));
29 cvals = ind2subv(ns(cset), sample_discrete(distrib_cvals));
30 mutilated_bnet = do_intervention(bnet, cset, cvals);
31 ev = sample_bnet(mutilated_bnet);
32 if usecell
33 data(:,m) = ev;
34 else
35 data(:,m) = cell2num(ev);
36 end
37 clamped(cset,m) = 1;
38 end