annotate toolboxes/FullBNT-1.0.7/KPMtools/marg_table.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_table(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 if nargin < 5, maximize = 0; end
Daniel@0 6
Daniel@0 7
Daniel@0 8 smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array
Daniel@0 9 sum_over = mysetdiff(bigdom, onto);
Daniel@0 10 ndx = find_equiv_posns(sum_over, bigdom);
Daniel@0 11 if maximize
Daniel@0 12 for i=1:length(ndx)
Daniel@0 13 smallT = max(smallT, [], ndx(i));
Daniel@0 14 end
Daniel@0 15 else
Daniel@0 16 for i=1:length(ndx)
Daniel@0 17 smallT = sum(smallT, ndx(i));
Daniel@0 18 end
Daniel@0 19 end
Daniel@0 20
Daniel@0 21
Daniel@0 22 ns = zeros(1, max(bigdom));
Daniel@0 23 %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1
Daniel@0 24 ns(bigdom) = bigsz;
Daniel@0 25
Daniel@0 26 smallT = squeeze(smallT); % remove all dimensions of size 1
Daniel@0 27 smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1