A
A
Andrey_Dolg2020-06-14 16:07:43
Algorithms
Andrey_Dolg, 2020-06-14 16:07:43

How to implement a probability distribution depending on the values?

Good afternoon.
Let's say we have an array of values ​​(2,22,41,25,64,33,2,3,4,...etc)
How to distribute weights depending on the value in order, the smaller the value, the greater the probability of choosing a given element. The sum of all probabilities will be equal to 1, and the maximum should be for elements with the number 2.
It's a shame to admit, but nothing comes to mind.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-06-14
@Andrey_Dolg

If we assume that there is an error in the wording of the question (see the comment above), then the natural answer is the following:
1. We consider the sum of all elements. We get some S.
2. For each element of your array s[i], we consider p[i]=s[i]/S.
(3. If there are identical elements in the array, add their p[] values. - The item is related to the incomplete formulation of the task. Whether it is needed or not, figure it out yourself.)
It is clear that the sum of all p[i] is equal to 1. It is
clear that the value p[i] is directly proportional to the value of s[i].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question