-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
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
Labels
No labels