annotate toolboxes/FullBNT-1.0.7/bnt/potentials/Tables/marg_tableM.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function smallT = marg_tableM(bigT, bigdom, bigsz, onto, maximize)
wolffd@0 2 % MARG_TABLE Marginalize a table
wolffd@0 3 % smallT = marg_table(bigT, bigdom, bigsz, onto, maximize)
wolffd@0 4
wolffd@0 5 % marg_tableM is the same as marg_table.m, but we are sure
wolffd@0 6 % it is not marg_table.c
wolffd@0 7
wolffd@0 8 if nargin < 5, maximize = 0; end
wolffd@0 9
wolffd@0 10
wolffd@0 11 smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array
wolffd@0 12 sum_over = mysetdiff(bigdom, onto);
wolffd@0 13 ndx = find_equiv_posns(sum_over, bigdom);
wolffd@0 14 if maximize
wolffd@0 15 for i=1:length(ndx)
wolffd@0 16 smallT = max(smallT, [], ndx(i));
wolffd@0 17 end
wolffd@0 18 else
wolffd@0 19 for i=1:length(ndx)
wolffd@0 20 smallT = sum(smallT, ndx(i));
wolffd@0 21 end
wolffd@0 22 end
wolffd@0 23
wolffd@0 24
wolffd@0 25 ns = zeros(1, max(bigdom));
wolffd@0 26 %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1
wolffd@0 27 ns(bigdom) = bigsz;
wolffd@0 28
wolffd@0 29 smallT = squeeze(smallT); % remove all dimensions of size 1
wolffd@0 30 smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1