Rev | Line | |
---|
[37] | 1 | function x = ndlogsumexp(x,dim)
|
---|
| 2 | % NDLOGSUMEXP Sum over multiple dimensions in the log domain.
|
---|
| 3 | % ndlogsumexp(X,DIM) sums out the dimensions in DIM (using logsumexp),
|
---|
| 4 | % and squeezes the result.
|
---|
| 5 |
|
---|
| 6 | % Written by Tom Minka
|
---|
| 7 | % (c) Microsoft Corporation. All rights reserved.
|
---|
| 8 |
|
---|
| 9 | sz = size(x);
|
---|
| 10 | for i=1:length(dim)
|
---|
| 11 | x = logsumexp(x, dim(i));
|
---|
| 12 | end
|
---|
| 13 | nbig = prod(sz);
|
---|
| 14 | nsmall = prod(size(x));
|
---|
| 15 | addflops((nbig-nsmall)*(1+flops_exp) + nsmall*flops_log);
|
---|
| 16 | %x = mysqueeze(x);
|
---|
| 17 | sz(dim) = [];
|
---|
| 18 | x = reshape(x,[sz 1 1]);
|
---|
Note: See
TracBrowser
for help on using the repository browser.