Mercurial > hg > camir-ismir2012
comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@gaussian_CPD/convert_to_pot.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cc4b1211e677 |
---|---|
1 function pot = convert_to_pot(CPD, pot_type, domain, evidence) | |
2 % CONVERT_TO_POT Convert a Gaussian CPD to one or more potentials | |
3 % pot = convert_to_pot(CPD, pot_type, domain, evidence) | |
4 | |
5 sz = CPD.sizes; | |
6 ns = zeros(1, max(domain)); | |
7 ns(domain) = sz; | |
8 | |
9 odom = domain(~isemptycell(evidence(domain))); | |
10 ps = domain(1:end-1); | |
11 cps = ps(CPD.cps); | |
12 dps = ps(CPD.dps); | |
13 self = domain(end); | |
14 cdom = [cps(:)' self]; | |
15 ddom = dps; | |
16 cnodes = cdom; | |
17 | |
18 switch pot_type | |
19 case 'u', | |
20 error('gaussian utility potentials not yet supported'); | |
21 | |
22 case 'd', | |
23 T = convert_to_table(CPD, domain, evidence); | |
24 ns(odom) = 1; | |
25 pot = dpot(domain, ns(domain), T); | |
26 | |
27 case {'c','g'}, | |
28 [m, C, W] = gaussian_CPD_params_given_dps(CPD, domain, evidence); | |
29 pot = linear_gaussian_to_cpot(m, C, W, domain, ns, cnodes, evidence); | |
30 | |
31 case 'cg', | |
32 [m, C, W] = gaussian_CPD_params_given_dps(CPD, domain, evidence); | |
33 % Convert each conditional Gaussian to a canonical potential | |
34 cobs = myintersect(cdom, odom); | |
35 dobs = myintersect(ddom, odom); | |
36 ens = ns; % effective node size | |
37 ens(cobs) = 0; | |
38 ens(dobs) = 1; | |
39 dpsize = prod(ens(dps)); | |
40 can = cell(1, dpsize); | |
41 for i=1:dpsize | |
42 if isempty(W) | |
43 can{i} = linear_gaussian_to_cpot(m(:,i), C(:,:,i), [], cdom, ns, cnodes, evidence); | |
44 else | |
45 can{i} = linear_gaussian_to_cpot(m(:,i), C(:,:,i), W(:,:,i), cdom, ns, cnodes, evidence); | |
46 end | |
47 end | |
48 pot = cgpot(ddom, cdom, ens, can); | |
49 | |
50 case 'scg', | |
51 [m, C, W] = gaussian_CPD_params_given_dps(CPD, domain, evidence); | |
52 cobs = myintersect(cdom, odom); | |
53 dobs = myintersect(ddom, odom); | |
54 ens = ns; % effective node size | |
55 ens(cobs) = 0; | |
56 ens(dobs) = 1; | |
57 dpsize = prod(ens(dps)); | |
58 cpsize = size(W, 2); % cts parents size | |
59 ss = size(m, 1); % self size | |
60 cheaddom = self; | |
61 ctaildom = cps(:)'; | |
62 pot_array = cell(1, dpsize); | |
63 for i=1:dpsize | |
64 pot_array{i} = scgcpot(ss, cpsize, 1, m(:,i), W(:,:,i), C(:,:,i)); | |
65 end | |
66 pot = scgpot(ddom, cheaddom, ctaildom, ens, pot_array); | |
67 | |
68 otherwise, | |
69 error(['unrecognized pot_type' pot_type]) | |
70 end | |
71 |