c++ - Efficiently summing log quantities -
working in c++, i'd find sum of quantities, , take log of sum:
log(a_1 + a_2 + a_3 + ... + a_n)
however, not have quantities themselves, have log'd values:
l_1 = log(a_1), l_2 = log(a_2), ... , l_n = log(a_n)
is there efficient way log sum of a_i's? i'd avoid
log(s) = log(exp(l_1) + exp(l_2) + ... + exp(l_n))
if possible - exp becomes bottleneck calculation done many times.
how large n?
this quantity known log-sum-exp , lieven vandenberghe talks on page 72 of book. has optimization package uses operation, , brief look, seems if doesn't special there, exponentiates , adds. perhaps exponentiation not serious bottleneck when n small enough vector fit memory.
this operation comes in modeling , bottleneck there sheer number of terms. magnitude of n=2^100 common, terms implicitly represented. in such cases, there various tricks approximating quantity relying on convexity of log-sum-exp. simplest trick -- approximate log(s) max(l1,l2,....,ln)
Comments
Post a Comment