Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/max_mult.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function y=max_mult(A,x) |
matthiasm@8 | 2 % MAX_MULT Like matrix multiplication, but sum gets replaced by max |
matthiasm@8 | 3 % function y=max_mult(A,x) y(i) = max_j A(i,j) x(j) |
matthiasm@8 | 4 |
matthiasm@8 | 5 %X=ones(size(A,1),1) * x(:)'; % X(j,i) = x(i) |
matthiasm@8 | 6 %y=max(A.*X, [], 2); |
matthiasm@8 | 7 |
matthiasm@8 | 8 % This is faster |
matthiasm@8 | 9 if size(x,2)==1 |
matthiasm@8 | 10 X=x*ones(1,size(A,1)); % X(i,j) = x(i) |
matthiasm@8 | 11 y=max(A'.*X)'; |
matthiasm@8 | 12 else |
matthiasm@8 | 13 %this works for arbitrarily sized A and x (but is ugly, and slower than above) |
matthiasm@8 | 14 X=repmat(x, [1 1 size(A,1)]); |
matthiasm@8 | 15 B=repmat(A, [1 1 size(x,2)]); |
matthiasm@8 | 16 C=permute(B,[2 3 1]); |
matthiasm@8 | 17 y=permute(max(C.*X),[3 2 1]); |
matthiasm@8 | 18 % this is even slower, as is using squeeze instead of permute |
matthiasm@8 | 19 % Y=permute(X, [3 1 2]); |
matthiasm@8 | 20 % y=permute(max(Y.*B, [], 2), [1 3 2]); |
matthiasm@8 | 21 end |