wolffd@0: function smallT = marg_table(bigT, bigdom, bigsz, onto, maximize) wolffd@0: % MARG_TABLE Marginalize a table wolffd@0: % smallT = marg_table(bigT, bigdom, bigsz, onto, maximize) wolffd@0: wolffd@0: if nargin < 5, maximize = 0; end wolffd@0: wolffd@0: wolffd@0: smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array wolffd@0: sum_over = mysetdiff(bigdom, onto); wolffd@0: ndx = find_equiv_posns(sum_over, bigdom); wolffd@0: if maximize wolffd@0: for i=1:length(ndx) wolffd@0: smallT = max(smallT, [], ndx(i)); wolffd@0: end wolffd@0: else wolffd@0: for i=1:length(ndx) wolffd@0: smallT = sum(smallT, ndx(i)); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: ns = zeros(1, max(bigdom)); wolffd@0: %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1 wolffd@0: ns(bigdom) = bigsz; wolffd@0: wolffd@0: smallT = squeeze(smallT); % remove all dimensions of size 1 wolffd@0: smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1