To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / CPDs / @discrete_CPD / Old / convert_to_pot.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.26 KB)

1
function pot = convert_to_pot(CPD, pot_type, domain, evidence)
2
% CONVERT_TO_POT Convert a tabular CPD to one or more potentials
3
% pots = convert_to_pot(CPD, pot_type, domain, evidence)
4
%
5
% pots{i} = CPD evaluated using evidence(domain(:,i))
6
% If 'domains' is a single row vector, pots will be an object, not a cell array.
7

    
8
ncases = size(domain,2);
9
assert(ncases==1); % not yet vectorized
10

    
11
sz = dom_sizes(CPD);
12
ns = zeros(1, max(domain));
13
ns(domain) = sz;
14

    
15
local_ev = evidence(domain);
16
obs_bitv = ~isemptycell(local_ev);
17
odom = domain(obs_bitv);
18
T = convert_to_table(CPD, domain, local_ev, obs_bitv);
19

    
20
switch pot_type
21
 case 'u',
22
  pot = upot(domain, sz, T, 0*myones(sz));  
23
 case 'd',
24
  ns(odom) = 1;
25
  pot = dpot(domain, ns(domain), T);          
26
 case {'c','g'},
27
  % Since we want the output to be a Gaussian, the whole family must be observed.
28
  % In other words, the potential is really just a constant.
29
  p = T;
30
  %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1)));
31
  ns(domain) = 0;
32
  pot = cpot(domain, ns(domain), log(p));       
33
 case 'cg',
34
  T = T(:);
35
  ns(odom) = 1;
36
  can = cell(1, length(T));
37
  for i=1:length(T)
38
    can{i} = cpot([], [], log(T(i)));
39
  end
40
  pot = cgpot(domain, [], ns, can);   
41
 otherwise,
42
  error(['unrecognized pot type ' pot_type])
43
end
44