comparison toolboxes/FullBNT-1.0.7/bnt/general/sample_bnet.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
1 function sample = sample_bnet(bnet, varargin)
2 % SAMPLE_BNET Generate a random sample from a Bayes net.
3 % SAMPLE = SAMPLE_BNET(BNET, ...)
4 %
5 % sample{i} contains the value of the i'th node.
6 % i.e., the result is an Nx1 cell array.
7 % Nodes are sampled in the order given by bnet.order.
8 %
9 % Optional arguments:
10 %
11 % evidence - initial evidence; if evidence{i} is non-empty, node i won't be sampled.
12
13 % set defauly params
14 n = length(bnet.dag);
15 sample = cell(n,1);
16
17 % get optional params
18 args = varargin;
19 nargs = length(args);
20 for i=1:2:nargs
21 switch args{i},
22 case 'evidence', sample = args{i+1}(:);
23 otherwise, error(['unrecognized argument ' args{i}])
24 end
25 end
26
27 for j=bnet.order(:)'
28 if isempty(sample{j})
29 %ps = parents(bnet.dag, j);
30 ps = bnet.parents{j};
31 e = bnet.equiv_class(j);
32 sample{j} = sample_node(bnet.CPD{e}, sample(ps));
33 end
34 end