Select items at random probabilistically - smaller is more likely

19 Views Asked by At

Forgive my limited vocabulary. I have a list of values representing scores:

scores = (4, 8, 15, 16, 23, 42)

I want to select two elements at random, but with the probability of an element being selected being relative to its value. For example, if I divide each value by the sum of that list, I get values summing up to 1, which can be interpreted as the probability of selecting that element:

(val / sum(scores) for val in scores)
# (0.04, 0.07, 0.14, 0.15, 0.21, 0.39)

That is, there's a 4% chance that the first element is selected, and 39% that the last is selected.

The catch: I want the probabilities to be inverted. That is, the smaller the score, the more likely it should be selected.

my question

How can I computer the probability of each element being selected, with the smaller value receiving a higher probability?

I guess one way could be to compute the probabilities as I did above, and assign the probabilities in reverse (39% gets associated with the first element). This seems too naive to be a sound mathematical solution.

1

There are 1 best solutions below

0
On

Let's call the scores $s_i$, so that $s_1=4,\ldots,s_5=42$. Your method is to assign a probability of $s_i/(s_1+\cdots+s_5)$ to element $s_i$. To invert, you can assign instead a probability of $$ \frac{\tfrac{1}{s_i}}{\frac{1}{s_1}+\cdots+\frac{1}{s_5}} $$ to element $s_i$.