source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/logsumexp.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 614 bytes
Line 
1function s = logsumexp(a, dim)
2% Returns log(sum(exp(a),dim)) while avoiding numerical underflow.
3% Default is dim = 1 (columns).
4% logsumexp(a, 2) will sum across rows instead of columns.
5% Unlike matlab's "sum", it will not switch the summing direction
6% if you provide a row vector.
7
8% Written by Tom Minka
9% (c) Microsoft Corporation. All rights reserved.
10
11if nargin < 2
12  dim = 1;
13end
14
15% subtract the largest in each column
16[y, i] = max(a,[],dim);
17dims = ones(1,ndims(a));
18dims(dim) = size(a,dim);
19a = a - repmat(y, dims);
20s = y + log(sum(exp(a),dim));
21i = find(~finite(y));
22if ~isempty(i)
23  s(i) = y(i);
24end
Note: See TracBrowser for help on using the repository browser.