annotate 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
rev   line source
wolffd@0 1 function [data, clamped] = mk_mutilated_samples(bnet, ncases, max_clamp, usecell)
wolffd@0 2 % GEN_MUTILATED_SAMPLES Do random interventions and then draw random samples
wolffd@0 3 % [data, clamped] = gen_mutilated_samples(bnet, ncases, max_clamp, usecell)
wolffd@0 4 %
wolffd@0 5 % At each step, we pick a random subset of size 0 .. max_clamp, and
wolffd@0 6 % clamp these nodes to random values.
wolffd@0 7 %
wolffd@0 8 % data(i,m) is the value of node i in case m.
wolffd@0 9 % clamped(i,m) = 1 if node i in case m was set by intervention.
wolffd@0 10
wolffd@0 11 if nargin < 4, usecell = 1; end
wolffd@0 12
wolffd@0 13 ns = bnet.node_sizes;
wolffd@0 14 n = length(bnet.dag);
wolffd@0 15 if usecell
wolffd@0 16 data = cell(n, ncases);
wolffd@0 17 else
wolffd@0 18 data = zeros(n, ncases);
wolffd@0 19 end
wolffd@0 20 clamped = zeros(n, ncases);
wolffd@0 21
wolffd@0 22 csubsets = subsets(1:n, max_clamp, 0); % includes the empty set
wolffd@0 23 distrib_cset = normalise(ones(1, length(csubsets)));
wolffd@0 24
wolffd@0 25 for m=1:ncases
wolffd@0 26 cset = csubsets{sample_discrete(distrib_cset)};
wolffd@0 27 nvals = prod(ns(cset));
wolffd@0 28 distrib_cvals = normalise(ones(1, nvals));
wolffd@0 29 cvals = ind2subv(ns(cset), sample_discrete(distrib_cvals));
wolffd@0 30 mutilated_bnet = do_intervention(bnet, cset, cvals);
wolffd@0 31 ev = sample_bnet(mutilated_bnet);
wolffd@0 32 if usecell
wolffd@0 33 data(:,m) = ev;
wolffd@0 34 else
wolffd@0 35 data(:,m) = cell2num(ev);
wolffd@0 36 end
wolffd@0 37 clamped(cset,m) = 1;
wolffd@0 38 end