How do you add two tiny masses in log space?

logaddexp returns the natural log of a sum of exponentials from two log values without explicitly materializing both tiny masses.

numpy.logaddexp in practice

Two log masses of minus one thousand combine to about minus 999.307. Use this when masses should add. Multiplying independent probabilities instead adds their logarithms directly.

import numpy as np
np.logaddexp(-1000.,-1000.)

Result -999.3068528194401

中文

两个极小概率怎样在对数域相加?

logaddexp 从两个对数值计算其指数之和的自然对数,避免显式还原两个极小数。

numpy.logaddexp 算例

两个对数质量均为 -1000,相加后的对数约为 -999.307。只有质量本来应相加时才使用;独立概率连乘在对数域是普通加法。

import numpy as np
np.logaddexp(-1000.,-1000.)

结果 -999.3068528194401

References / 参考来源

Keep reading / 继续阅读