# Multinomial must receive a machine size number

I need to use the multinomial distribution.

In a certain step, by coincidence, the input probability vector is {2.6662875218*^-903, 6.180318409067*^-751, 0.5, 6.180318409*^-751, 0.5}.

When I do

RandomVariate[
MultinomialDistribution[
1, {2.6662875218*^-903, 6.180318409067*^-751,  0.5,
6.180318409*^-751, 0.5}], 1]


I get an error message for the values 2.6662875218*^-903, and 6.180318409*^-751, not being machine-size real numbers... When I run my programme on data, the vector of probabilities number of components will be of magnitude of 10^3.

What's the most efficient way to solve this?

Edit: In the above vector, the true values were slightly different. The values 0.5 aren't truly 0.5, since if we sum all the probabilities we must obtain 1. I just changed them to simplify the problem, but I now understand it may induce people into disregarding an important detail. Sorry.

You may use Threshold to push these tiny numbers towards 0. For example,

ϵ = \$MachineEpsilon/2;
RandomVariate[
MultinomialDistribution[
1,
Normalize[
Threshold[
{2.6662875218*^-903, 6.180318409067*^-751, 0.5, 6.180318409*^-751, 0.5},
ϵ
],
Total
]
],
1
]

• Thanks for the answer Henrik. However, one thing that I didn't say, but I thought it was implicit is that the probabilities in the vector must sum to 1. If I just use the threshould, mathematica will realise they don't and stop all computations... – An old man in the sea. Nov 28 '18 at 9:57
• Ah, I see. Normalize can cure the summation problem. Please have a look at my edit. – Henrik Schumacher Nov 28 '18 at 10:09
• Numerical issues tend to be solved with logarithms, so the OP would be using log probabilities. Is that feasible in this case? I doubt it, but it may be worth considering. – Titus Nov 28 '18 at 10:13