Skip to content

Request for LogSumExp function #65

@aezarebski

Description

@aezarebski

Could a LogSumExp function be included please?

Motivation
Working with small probabilities can quickly lead to underflow problems. The LogSumExp function is often used as a way to avoid this. There is a definition of the function and motivation for its use in numerical computing on the Wikipedia page.

Proposed solution
A suitable place for this function might be here.

Here is an example implementation

-- | The log-sum-exp function
logSumExp :: (Floating a, Ord a) => [a] -> a
logSumExp xs = x' + log (sum [exp (x - x') | x <- xs])
               where x' = maximum xs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions