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 / @softmax_CPD / convert_to_pot.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.41 KB)
| 1 |
function pot = convert_to_pot(CPD, pot_type, domain, evidence) |
|---|---|
| 2 |
% CONVERT_TO_POT Convert a softmax CPD to a potential |
| 3 |
% pots = convert_to_pot(CPD, pot_type, domain, evidence) |
| 4 |
% |
| 5 |
% pots = CPD evaluated using evidence(domain) |
| 6 |
|
| 7 |
ncases = size(domain,2); |
| 8 |
assert(ncases==1); % not yet vectorized |
| 9 |
|
| 10 |
sz = dom_sizes(CPD); |
| 11 |
ns = zeros(1, max(domain)); |
| 12 |
ns(domain) = sz; |
| 13 |
|
| 14 |
odom = domain(~isemptycell(evidence(domain))); |
| 15 |
T = convert_to_table(CPD, domain, evidence); |
| 16 |
|
| 17 |
switch pot_type |
| 18 |
case 'u', |
| 19 |
pot = upot(domain, sz, T, 0*myones(sz)); |
| 20 |
case 'd', |
| 21 |
ns(odom) = 1; |
| 22 |
pot = dpot(domain, ns(domain), T); |
| 23 |
|
| 24 |
case {'c','g'},
|
| 25 |
% Since we want the output to be a Gaussian, the whole family must be observed. |
| 26 |
% In other words, the potential is really just a constant. |
| 27 |
p = T; |
| 28 |
%p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1))); |
| 29 |
ns(domain) = 0; |
| 30 |
pot = cpot(domain, ns(domain), log(p)); |
| 31 |
|
| 32 |
case 'cg', |
| 33 |
T = T(:); |
| 34 |
ns(odom) = 1; |
| 35 |
can = cell(1, length(T)); |
| 36 |
for i=1:length(T) |
| 37 |
can{i} = cpot([], [], log(T(i)));
|
| 38 |
end |
| 39 |
ps = domain(1:end-1); |
| 40 |
dps = ps(CPD.dpndx); |
| 41 |
cps = ps(CPD.cpndx); |
| 42 |
ddom = [dps CPD.self]; |
| 43 |
cdom = cps; |
| 44 |
pot = cgpot(ddom, cdom, ns, can); |
| 45 |
|
| 46 |
case 'scg' |
| 47 |
T = T(:); |
| 48 |
ns(odom) = 1; |
| 49 |
pot_array = cell(1, length(T)); |
| 50 |
for i=1:length(T) |
| 51 |
pot_array{i} = scgcpot([], [], T(i));
|
| 52 |
end |
| 53 |
pot = scgpot(domain, [], [], ns, pot_array); |
| 54 |
|
| 55 |
otherwise, |
| 56 |
error(['unrecognized pot type ' pot_type]) |
| 57 |
end |
| 58 |
|