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

History | View | Annotate | Download (1.23 KB)

1
function pot = convert_to_pot(CPD, pot_type, domain, evidence)
2
% CONVERT_TO_POT Convert a gmux CPD to a Gaussian potential
3
% pot = convert_to_pot(CPD, pot_type, domain, evidence)
4
  
5
switch pot_type
6
 case {'d', 'u', 'cg', 'scg'},
7
  error(['can''t convert gmux to potential of type ' pot_type])
8

    
9
 case {'c','g'},
10
  % We create a large weight matrix with zeros in all blocks corresponding
11
  % to the non-chosen parents, since they are effectively disconnected.
12
  % The chosen parent is determined by the value, m,  of the discrete parent.
13
  % Thus the potential is as large as the whole family.
14
  ps = domain(1:end-1);
15
  dps = ps(CPD.dps); % CPD.dps is an index, not a node number (because of param tying)
16
  cps = ps(CPD.cps);
17
  m = evidence{dps};
18
  if isempty(m)
19
    error('gmux node must have observed discrete parent')
20
  end
21
  bs = CPD.sizes(CPD.cps);
22
  b = block(m, bs);
23
  sum_cpsz = sum(CPD.sizes(CPD.cps));
24
  selfsz = CPD.sizes(end);
25
  W = zeros(selfsz, sum_cpsz);
26
  W(:,b) = CPD.weights(:,:,m);
27

    
28
  ns = zeros(1, max(domain));
29
  ns(domain) = CPD.sizes;
30
  self = domain(end);
31
  cdom = [cps(:)' self];
32
  pot = linear_gaussian_to_cpot(CPD.mean(:,m), CPD.cov(:,:,m), W, domain, ns, cdom, evidence);
33
  
34
 otherwise,
35
  error(['unrecognized pot_type' pot_type])
36
end
37