mercredi 23 novembre 2016

How to generate random numbers over a negative range in C++

I want to select a random number from the following sorted list of very small negative numbers:

[-4.61585e+07,-4.61586e+07,-4.61587e+07,-4.61589e+07, -4.6159e+07, 
-4.61591e+07,-4.61592e+07,-4.61593e+07,-4.61594e+07,-4.61596e+07,-4.61597e+07]

These are generated via transferring actual very small positive values into logarithmic space to avoid numerical underflow. Now, I wan to sample from this set while the probability of each value is proportional to its value. If I want to convert these to actual probabilities, I can divided all of them by the SUM (i.e., -5.0775e+08) , and scale it to (0,1], and then call std::uniform_real_distribution<> dis(0, 1) and look at the comulative values in the normalized list. BUT, normalizing via dividing numbers by SUM causes numerical problem setting them to 0. How can I sample?




Aucun commentaire:

Enregistrer un commentaire