haskell / haskell/math-functions
Request for LogSumExp function
- Dominant language
- Haskell
- Stars
- 45
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
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](https://en.wikipedia.org/wiki/LogSumExp#log-sum-exp_trick_for_log-domain_calculations).
**Proposed solution**
A suitable place for this function might be [here](https://hackage.haskell.org/package/math-functions-0.3.4.1/docs/Numeric-SpecFunctions.html#g:5).
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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.