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 / CPDs / @discrete_CPD / Old / convert_to_table.m @ 8:b5b38998ef3b
History | View | Annotate | Download (751 Bytes)
| 1 |
function T = convert_to_table(CPD, domain, local_ev, obs_bitv) |
|---|---|
| 2 |
% CONVERT_TO_TABLE Convert a discrete CPD to a table |
| 3 |
% function T = convert_to_table(CPD, domain, local_ev, obs_bitv) |
| 4 |
% |
| 5 |
% We convert the CPD to a CPT, and then lookup the evidence on the discrete parents. |
| 6 |
% The resulting table can easily be converted to a potential. |
| 7 |
|
| 8 |
|
| 9 |
CPT = CPD_to_CPT(CPD); |
| 10 |
obs_child_only = ~any(obs_bitv(1:end-1)) & obs_bitv(end); |
| 11 |
|
| 12 |
if obs_child_only |
| 13 |
sz = size(CPT); |
| 14 |
CPT = reshape(CPT, prod(sz(1:end-1)), sz(end)); |
| 15 |
o = local_ev{end};
|
| 16 |
T = CPT(:, o); |
| 17 |
else |
| 18 |
odom = domain(obs_bitv); |
| 19 |
vals = cat(1, local_ev{find(obs_bitv)}); % undo cell array
|
| 20 |
map = find_equiv_posns(odom, domain); |
| 21 |
index = mk_multi_index(length(domain), map, vals); |
| 22 |
T = CPT(index{:});
|
| 23 |
end |