logsumexp 在 C 中的实现?
有人知道提供 logsumexp 函数的开源数字 C 库吗?
logsumexp(a)
函数计算数组 a 各分量的指数 log(e^{a_1}+...e^{a_n}) 之和,避免数值溢出。
Does anybody know of an open source numerical C library that provides the logsumexp
-function?
The logsumexp(a)
function computes the sum of exponentials log(e^{a_1}+...e^{a_n}) of the components of the array a, avoiding numerical overflow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个从头开始的非常简单的实现(至少经过测试):
它的技巧是有效地将所有参数除以最大的参数,然后在最后添加其日志以避免溢出,因此它对于添加表现良好大量类似比例的值,如果某些参数比其他参数大许多数量级,则错误会逐渐出现。
如果你希望它在给定 0 个参数时运行而不崩溃,你必须为此添加一个案例:)
Here's a very simple implementation from scratch (tested, at least minimally):
This does the trick of effectively dividing all of the arguments by the largest, then adding its log back in at the end to avoid overflow, so it's well-behaved for adding a large number of similarly-scaled values, with errors creeping in if some arguments are many orders of magnitude larger than others.
If you want it to run without crashing when given 0 arguments, you'll have to add a case for that :)