Skip to main content

Module math

Module math 

Source
Expand description

Log-space arithmetic helpers.

Salmon performs nearly all of its probability accumulation in log space to avoid underflow. These helpers mirror the conventions in the C++ code where LOG_0 is negative infinity and LOG_1 is zero.

Constants§

LOG_0
log(0) = -inf
LOG_1
log(1) = 0
LOG_EPSILON
A very small log-space epsilon used as an effective “zero” mass in places where strict -inf would propagate NaNs.

Functions§

log_add
Numerically stable log(exp(x) + exp(y)).
log_sub
Numerically stable log(exp(x) - exp(y)), requires x >= y.
log_sum
Log-sum-exp over an iterator of log-space values.