annotate toolboxes/FullBNT-1.0.7/bnt/potentials/Tables/marg_tableM.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 smallT = marg_tableM(bigT, bigdom, bigsz, onto, maximize)
Daniel@0 2 % MARG_TABLE Marginalize a table
Daniel@0 3 % smallT = marg_table(bigT, bigdom, bigsz, onto, maximize)
Daniel@0 4
Daniel@0 5 % marg_tableM is the same as marg_table.m, but we are sure
Daniel@0 6 % it is not marg_table.c
Daniel@0 7
Daniel@0 8 if nargin < 5, maximize = 0; end
Daniel@0 9
Daniel@0 10
Daniel@0 11 smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array
Daniel@0 12 sum_over = mysetdiff(bigdom, onto);
Daniel@0 13 ndx = find_equiv_posns(sum_over, bigdom);
Daniel@0 14 if maximize
Daniel@0 15 for i=1:length(ndx)
Daniel@0 16 smallT = max(smallT, [], ndx(i));
Daniel@0 17 end
Daniel@0 18 else
Daniel@0 19 for i=1:length(ndx)
Daniel@0 20 smallT = sum(smallT, ndx(i));
Daniel@0 21 end
Daniel@0 22 end
Daniel@0 23
Daniel@0 24
Daniel@0 25 ns = zeros(1, max(bigdom));
Daniel@0 26 %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1
Daniel@0 27 ns(bigdom) = bigsz;
Daniel@0 28
Daniel@0 29 smallT = squeeze(smallT); % remove all dimensions of size 1
Daniel@0 30 smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1