To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / general / enumerate_scenarios.m @ 8:b5b38998ef3b
History | View | Annotate | Download (691 Bytes)
| 1 |
function [scenarios, log_probs] = enumerate_scenarios(bnet, evidence) |
|---|---|
| 2 |
% ENUMERATE_SCENARIOS Enumerate all assignments, and return the prob. of the non-zeros ones |
| 3 |
% function [scenarios, log_probs] = enumerate_scenarios(bnet, evidence) |
| 4 |
|
| 5 |
assert(isempty(bnet.cnodes)); |
| 6 |
n = length(bnet.dag); |
| 7 |
observed = ~isemptycell(evidence); |
| 8 |
vals = cat(1,evidence{observed});
|
| 9 |
vals = vals(:)'; |
| 10 |
ns = bnet.node_sizes; |
| 11 |
|
| 12 |
log_probs = []; |
| 13 |
scenarios = []; |
| 14 |
for i=1:prod(ns) |
| 15 |
inst = ind2subv(ns, i); % i'th instantiation |
| 16 |
if isempty(vals) | inst(observed) == vals % agrees with evidence |
| 17 |
ll = log_lik_complete(bnet, num2cell(inst(:))); |
| 18 |
log_probs = [log_probs ll]; |
| 19 |
scenarios = [scenarios(:)' inst]; |
| 20 |
end |
| 21 |
end |