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 / convert_to_pot.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.58 KB)

1
function pot = convert_to_pot(CPD, pot_type, domain, evidence)
2
% CONVERT_TO_POT Convert a discrete CPD to a potential
3
% pot = 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
CPT1 = CPD_to_CPT(CPD);
15
spar = issparse(CPT1);
16
odom = domain(~isemptycell(evidence(domain)));
17
if spar
18
   T = convert_to_sparse_table(CPD, domain, evidence);
19
else 
20
   T = convert_to_table(CPD, domain, evidence);
21
end
22

    
23
switch pot_type
24
 case 'u',
25
  pot = upot(domain, sz, T, 0*myones(sz));  
26
 case 'd',
27
  ns(odom) = 1;
28
  pot = dpot(domain, ns(domain), T);          
29
 case {'c','g'},
30
  % Since we want the output to be a Gaussian, the whole family must be observed.
31
  % In other words, the potential is really just a constant.
32
  p = T;
33
  %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1)));
34
  ns(domain) = 0;
35
  pot = cpot(domain, ns(domain), log(p));       
36

    
37
 case 'cg',
38
  T = T(:);
39
  ns(odom) = 1;
40
  can = cell(1, length(T));
41
  for i=1:length(T)
42
    if T(i) == 0 
43
      can{i} = cpot([], [], -Inf); % bug fix by Bob Welch 20/2/04
44
    else
45
      can{i} = cpot([], [], log(T(i)));
46
    end;
47
  end
48
  pot = cgpot(domain, [], ns, can); 
49
  
50
 case 'scg'
51
  T = T(:);
52
  ns(odom) = 1;
53
  pot_array = cell(1, length(T));
54
  for i=1:length(T)
55
    pot_array{i} = scgcpot([], [], T(i));
56
  end
57
  pot = scgpot(domain, [], [], ns, pot_array);   
58

    
59
 otherwise,
60
  error(['unrecognized pot type ' pot_type])
61
end
62