相关疑难解决方法(0)

log-sum-exp技巧为什么不递归

我一直在研究log-sum-exp问题.我有一个以对数形式存储的数字列表,我希望将它们相加并存储在对数中.

天真的算法是

def naive(listOfLogs):
    return math.log10(sum(10**x for x in listOfLogs))
Run Code Online (Sandbox Code Playgroud)

许多网站包括: 在C中实现logsumexp? 和 http://machineintelligence.tumblr.com/post/4998477107/ 推荐使用

def recommend(listOfLogs):
    maxLog = max(listOfLogs)
    return maxLog + math.log10(sum(10**(x-maxLog) for x in listOfLogs))
Run Code Online (Sandbox Code Playgroud)

又名

def recommend(listOfLogs):
    maxLog = max(listOfLogs)
    return maxLog + naive((x-maxLog) for x in listOfLogs)
Run Code Online (Sandbox Code Playgroud)

我不明白的是,如果推荐算法更好,为什么我们应该递归调用它?那能提供更多的好处吗?

def recursive(listOfLogs):
    maxLog = max(listOfLogs)
    return maxLog + recursive((x-maxLog) for x in listOfLogs)
Run Code Online (Sandbox Code Playgroud)

虽然我问是否还有其他技巧可以让这个计算在数值上更稳定?

math numerical-methods

9
推荐指数
1
解决办法
3559
查看次数

标签 统计

math ×1

numerical-methods ×1