如何从其组件对数项中计算对数(项之和) [英] How to calculate log(sum of terms) from its component log-terms

查看:174
本文介绍了如何从其组件对数项中计算对数(项之和)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(1)问题的简单版本:

(1) The simple version of the problem:

如何在给定log(P1),log(P2),...,log(Pn)的情况下计算log(P1 + P2 + ... + Pn),而无需花费任何条件来获得原始Pi .我不想获得原始的Pi,因为它们太小了,并且可能导致数字计算机下溢.

How to calculate log(P1+P2+...+Pn), given log(P1), log(P2), ..., log(Pn), without taking the exp of any terms to get the original Pi. I don't want to get the original Pi because they are super small and may cause numeric computer underflow.

(2)问题的长版本:

我正在使用贝叶斯定理来计算条件概率P(Y | E).

I am using Bayes' Theorem to calculate a conditional probability P(Y|E).

P(Y|E) = P(E|Y)*P(Y) / P(E)

我有一千个概率相乘.

P(E|Y) = P(E1|Y) * P(E2|Y) * ... * P(E1000|Y) 

为了避免计算机数字下溢,我使用log(p)并计算1000 log(p)的总和,而不是计算1000 p的乘积.

To avoid computer numeric underflow, I used log(p) and calculate the summation of 1000 log(p) instead of calculating the product of 1000 p.

log(P(E|Y)) = log(P(E1|Y)) + log(P(E2|Y)) + ... + log(P(E1000|Y))

但是,我还需要计算P(E),

However, I also need to calculate P(E), which is

P(E) = sum of P(E|Y)*P(Y)

log(P(E))不等于log (P(E|Y)*P(Y))的总和.如何在不求解P(E|Y)*P(Y)(它们是非常小的数字)并将其相加的情况下获得log(P(E)).

log(P(E)) does not equal to the sum of log(P(E|Y)*P(Y)). How should I get log(P(E)) without solving for P(E|Y)*P(Y) (they are extremely small numbers) and adding them.

推荐答案

您可以使用

log(P1+P2+...+Pn) = log(P1[1 + P2/P1 + ... + Pn/P1]) 
                  = log(P1) + log(1 + P2/P1 + ... + Pn/P1])

适用于任何Pi.因此,排除maxP = max_i Pi会导致

which works for any Pi. So factoring out maxP = max_i Pi results in

log(P1+P2+...+Pn) = log(maxP) + log(1+P2/maxP + ... + Pn/maxP)

所有比率均小于1的地方.

where all the ratios are less than 1.

这篇关于如何从其组件对数项中计算对数(项之和)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆