Daniel@0: function smallpot = marginalize_pot(bigpot, onto, maximize) Daniel@0: % MARGINALIZE_POT Marginalize a dpot onto a smaller domain. Daniel@0: % smallpot = marginalize_pot(bigpot, onto, maximize) Daniel@0: % Daniel@0: % 'onto' must be in ascending order. Daniel@0: Daniel@0: if nargin < 3, maximize = 0; end Daniel@0: Daniel@0: ns = zeros(1, max(bigpot.domain)); Daniel@0: ns(bigpot.domain) = bigpot.sizes; Daniel@0: %assert(isequal(bigpot.sizes, mysize(bigpot.T))); % may fail if there are trailing dimensions of size 1 Daniel@0: if issparse(bigpot.T) Daniel@0: smallT = marg_sparse_table(bigpot.T, bigpot.domain, bigpot.sizes, onto, maximize); Daniel@0: else Daniel@0: smallT = marg_table(bigpot.T, bigpot.domain, bigpot.sizes, onto, maximize); Daniel@0: end Daniel@0: smallpot = dpot(onto, ns(onto), smallT);