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