I have a list of very small exponential values (for example exp(n)
, with n<-300
), which are generated from Gaussian PDFs.
I want to compute how much each of them is proportional to the sum, for example like the following python-like pseudo-code does:
s = 0 # sum of all values
for n in exponents:
s += exp(n)
for n in exponents:
k = exp(n)/s # I want to compute k for each n
The problem is, since the values of n
are all very small, the summation s
turns out to be zero sometimes, and I'll get the division-by-zero error.
I know one thing I can do is to add a constant value (say 300) to all n
to prevent underflow, but it'll cause overflow in other cases.
How can I solve this?
I don't know whether I've expressed myself clearly, if any of these doesn't make sense or any grammar mistakes, please correct me. Thanks in advance.