In R, I have a vector of logged values (denoted log_w
).
I need to calculate sum(exp(log_w))
however due to the sizes of the values held in log_w
, as soon as I exponentiate log_w
I get a vector of zeros.
Example in R, showing a small vector of similar values:
log_w<-c(-14781.5000092473, -1.68703503244454e+46, -4.24636436410052e+36,
-1.90459568391779e+30, -6565872478811.07, -1.58627856636904e+32,
-1.41504360955663e+84, -9.09553094112168e+52, -1.8247785275833e+40,
-10566415795189.4)
exp(log_w)
sum(exp(log_w))
I am aware of the LogSumExp (https://en.wikipedia.org/wiki/LogSumExp) to calcuate the log of a sum of exponentiated values, however I cannot see how this can be used to calculate the sum of a vector of exponentiated logged values. Are there any other similar approximations that anyone could point me towards to calculate the sum of the exponential of logged values? Any advice greatly appreciated.
EDIT
Further information - log_w
are logged weights. I need to be able to normalise the weights, i.e. calculate w/sum(w), however I currently only have the logged weights (log(w)).
EDIT
Using library Brobdingnag (https://cran.r-project.org/web/packages/Brobdingnag/index.html) I can calculate exp(log_w)
however using that package, sum(exp(log_w))
results in +exp(0)