annotate toolboxes/FullBNT-1.0.7/bnt/general/enumerate_scenarios.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 [scenarios, log_probs] = enumerate_scenarios(bnet, evidence)
wolffd@0 2 % ENUMERATE_SCENARIOS Enumerate all assignments, and return the prob. of the non-zeros ones
wolffd@0 3 % function [scenarios, log_probs] = enumerate_scenarios(bnet, evidence)
wolffd@0 4
wolffd@0 5 assert(isempty(bnet.cnodes));
wolffd@0 6 n = length(bnet.dag);
wolffd@0 7 observed = ~isemptycell(evidence);
wolffd@0 8 vals = cat(1,evidence{observed});
wolffd@0 9 vals = vals(:)';
wolffd@0 10 ns = bnet.node_sizes;
wolffd@0 11
wolffd@0 12 log_probs = [];
wolffd@0 13 scenarios = [];
wolffd@0 14 for i=1:prod(ns)
wolffd@0 15 inst = ind2subv(ns, i); % i'th instantiation
wolffd@0 16 if isempty(vals) | inst(observed) == vals % agrees with evidence
wolffd@0 17 ll = log_lik_complete(bnet, num2cell(inst(:)));
wolffd@0 18 log_probs = [log_probs ll];
wolffd@0 19 scenarios = [scenarios(:)' inst];
wolffd@0 20 end
wolffd@0 21 end