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