Code covered by the BSD License  

Highlights from
maxstar

4.0

4.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 2.37 KB File ID: #10209

maxstar

by Robert Dickson

 

02 Mar 2006 (Updated 30 Mar 2006)

Natural log of a sum of exponentials

| Watch this File

File Information
Description

maxstar(x) is the natural log of a sum of exponentials overcoming the numerical failure of log(sum(exp(x))) for extreme values of an argument vector x.

maxstar(x,[],dim) has the N-D array features of the MATLAB max function.
maxstar(x,w,dim) is the natural log of a weighted sum of exponentials.

The max* function is described in Lin & Costello, Error Control Coding, 2nd Edition, equation 12.127.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
08 Mar 2006 John D'Errico

Good help with a reference. It works when the direct alternative expression fails. But there are other (faster) alternatives that should be as accurate. Off hand, its not at all obvious to me why maxstar is better. (Perhaps if I've read the reference.)

x = randn(1,100)*100000;

tic,r1=log(sum(exp(x(:))));toc
Elapsed time is 0.000178 seconds.

tic,r2=maxstar(x);toc
Elapsed time is 0.017096 seconds.

tic,M=max(x(:));r3=M+log(sum(exp(sort(x(:))/M)));toc
Elapsed time is 0.000342 seconds.

[r1,r2,r3]
ans =
          Inf 2.7718e+05 2.7718e+05

Its also arguable that this should have a similar syntax to most other matlab operators with similar functionality. It should operate on a specified dimension. (See help for mean, max, etc.)

Please login to add a comment or rating.
Updates
30 Mar 2006

Major revision to reproduce the N-D array features of the MATLAB max function, following a suggestion by John D'Errico.

Tag Activity for this File
Tag Applied By Date/Time
coding theory Robert Dickson 22 Oct 2008 08:17:20
information theory Robert Dickson 22 Oct 2008 08:17:20
precision Robert Dickson 22 Oct 2008 08:17:20
metric Robert Dickson 22 Oct 2008 08:17:20
coding Robert Dickson 22 Oct 2008 08:17:20
natural log Robert Dickson 22 Oct 2008 08:17:20
numerical failure Robert Dickson 22 Oct 2008 08:17:20
extreme Robert Dickson 22 Oct 2008 08:17:20

Contact us at files@mathworks.com