comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
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