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