Daniel@0: function [scenarios, log_probs] = enumerate_scenarios(bnet, evidence) Daniel@0: % ENUMERATE_SCENARIOS Enumerate all assignments, and return the prob. of the non-zeros ones Daniel@0: % function [scenarios, log_probs] = enumerate_scenarios(bnet, evidence) Daniel@0: Daniel@0: assert(isempty(bnet.cnodes)); Daniel@0: n = length(bnet.dag); Daniel@0: observed = ~isemptycell(evidence); Daniel@0: vals = cat(1,evidence{observed}); Daniel@0: vals = vals(:)'; Daniel@0: ns = bnet.node_sizes; Daniel@0: Daniel@0: log_probs = []; Daniel@0: scenarios = []; Daniel@0: for i=1:prod(ns) Daniel@0: inst = ind2subv(ns, i); % i'th instantiation Daniel@0: if isempty(vals) | inst(observed) == vals % agrees with evidence Daniel@0: ll = log_lik_complete(bnet, num2cell(inst(:))); Daniel@0: log_probs = [log_probs ll]; Daniel@0: scenarios = [scenarios(:)' inst]; Daniel@0: end Daniel@0: end