I'm normalizing a vector to make its sum 1 so that the vector will be used for a parameter in multinomial distribution.
Here's a toy example. Let x
be a vector with positive values and sigma
is very small positive number. When I run this R code, y
is all zero due to underflow, so is its sum.
x <- rep(1, 10)
sigma <- 1e-3
y <- exp(-x/sigma) # 0's
prob <- y / sum(y) # NaNs
Do you have any idea to handle this?
Thanks in advance.