Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMtools/marginalize_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 = marginalize_table(bigT, bigdom, bigsz, onto, maximize) | |
2 % MARG_TABLE Marginalize a table | |
3 % function smallT = marginalize_table(bigT, bigdom, bigsz, onto, maximize) | |
4 | |
5 % Like marg_table in BNT, except we do not assume the domains are sorted | |
6 | |
7 if nargin < 5, maximize = 0; end | |
8 | |
9 | |
10 smallT = myreshape(bigT, bigsz); % make sure it is a multi-dim array | |
11 sum_over = mysetdiff(bigdom, onto); | |
12 ndx = find_equiv_posns(sum_over, bigdom); | |
13 if maximize | |
14 for i=1:length(ndx) | |
15 smallT = max(smallT, [], ndx(i)); | |
16 end | |
17 else | |
18 for i=1:length(ndx) | |
19 smallT = sum(smallT, ndx(i)); | |
20 end | |
21 end | |
22 | |
23 | |
24 ns = zeros(1, max(bigdom)); | |
25 %ns(bigdom) = mysize(bigT); % ignores trailing dimensions of size 1 | |
26 ns(bigdom) = bigsz; | |
27 | |
28 % If onto has a different ordering than bigdom, the following | |
29 % will produce the wrong results | |
30 | |
31 %smallT = squeeze(smallT); % remove all dimensions of size 1 | |
32 %smallT = myreshape(smallT, ns(onto)); % put back relevant dims of size 1 | |
33 | |
34 % so permute dimensions to match desired ordering (as specified by onto) | |
35 | |
36 | |
37 % like find_equiv_posns, but keeps ordering | |
38 outdom = [onto sum_over]; | |
39 for i=1:length(outdom) | |
40 j = find(bigdom==outdom(i)); | |
41 match(i) = j; | |
42 end | |
43 outdom = [onto sum_over]; | |
44 for i=1:length(outdom) | |
45 j = find(bigdom==outdom(i)); | |
46 match(i) = j; | |
47 end | |
48 if match ~= 1 | |
49 smallT = permute(smallT, match); | |
50 end |