I'm new to Math.NET Numerics and I'm looking for an implementation of LogSumExp, is there an existing function for that?
Asked
Active
Viewed 153 times
1 Answers
1
Seems to be missing, you can try the following method:
double LogSumExp(params double[] x) => Math.Log(x.Select(xVal => Math.Exp(xVal)).Sum());

Access Denied
- 8,723
- 4
- 42
- 72
-
that's a very concise implementation, but usually [this trick](https://en.wikipedia.org/wiki/LogSumExp#A_strictly_convex_log-sum-exp_type_function) should be used for numerical stability – dontloo Sep 10 '18 at 05:52
-
another extension method with Kahan Sum should solve the issue: https://stackoverflow.com/a/2456422/1099716 – Access Denied Sep 10 '18 at 08:46