comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function smallT = marg_table(bigT, bigdom, bigsz, onto, maximize)
2 % MARG_TABLE Marginalize a table
3 % smallT = marg_table(bigT, bigdom, bigsz, onto, maximize)
4
5 if nargin < 5, maximize = 0; end
6
7
8 smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array
9 sum_over = mysetdiff(bigdom, onto);
10 ndx = find_equiv_posns(sum_over, bigdom);
11 if maximize
12 for i=1:length(ndx)
13 smallT = max(smallT, [], ndx(i));
14 end
15 else
16 for i=1:length(ndx)
17 smallT = sum(smallT, ndx(i));
18 end
19 end
20
21
22 ns = zeros(1, max(bigdom));
23 %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1
24 ns(bigdom) = bigsz;
25
26 smallT = squeeze(smallT); % remove all dimensions of size 1
27 smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1