Floating-point underflow 2026-10-20
Floating-point underflow occurs when a nonzero numerical result is smaller in magnitude than the representable range or loses precision in the subnormal range. A long product of probabilities can become zero despite a mathematically positive result. Adding logarithms avoids forming the product; adding alternative path probabilities then requires log-sum-exp or controlled rescaling.
Forward algorithm 2026-10-20
The forward algorithm computes sequence likelihoods by summing over all hidden paths through a Hidden Markov model. For emitting states, obeys . It reuses partial sums rather than enumerating exponentially many state sequences. Silent states require additional transitions without consuming an observation. Scaling or log-sum-exp prevents floating-point underflow.
Use a uniform independent DNA background, so each nucleotide has probability . Conditional on length five, its sequence probability is . The requested score, often called log-odds in sequence analysis, is a log-likelihood ratio against this background:Using natural logarithms instead gives . Identically distributed independent positions do not, by themselves, require equal base frequencies. If the intended background instead has specified frequencies , the general answer isThe numerical value above uses the conventional equal-frequency random DNA model.
Taking a logarithm only after multiplying probabilities does not prevent floating-point underflow: the product may already have rounded to zero, and its logarithm is then . Accumulate logarithms before forming tiny products; where alternative paths must be added, use log-sum-exp in the forward algorithm or rescale its intermediate probabilities.