问题
I need to probabilistically select a sample from a set of data.
Say I had a set of values array[12, 15, 29, 17, 12, 29]
. The standard approach would be calculate the total (12 + 15 + 29 + 17 + 12 + 29) and then create a spinner that favors the higher value. Kinda like a pie chart where we select at random from the sample set but favor the Individual with the highest value.
An example with the numbers above the chance you will randomly select array[0]
is 11% while the chance that array[5]
is 25%. That's fine
What I want to do though is favor the lower numbers and with all my brainstorming power I cannot figure out a way to give the lower number a statistically equal probability of selection as if we were to select the larger number.
One way I have approached the problem is to add array[]
then subtract each value from the total giving you a array2[102, 99, 85, 102, 85]
then recalculating the percents from array2[].
Giving array[0]
a 21%. The problem with this solution is that elements with close statistical probability of selection in array[1]
have distant selection percentages.
We also attempted just swapping the lowest and highest then next lowest with next highest percent values but that gives you the same problem as our first attempt.
I feel like there has to be an easy way to to this.
Note: If you are familiar with Evolutionary/Genetic Computation we are trying to do parent selection based on fitness proportion. However, our fitness value is reversed (the lower the better). So how do we do fitness proportion selection for parents if the lower the fitness the better?
回答1:
Why don't you work with inverses? The base array for the probabilities in your example would be array[1.0/12, 1.0/15, 1.0/29, 1.0/17, 1.0/12, 1.0/29]
, the rest would stay the same.
来源:https://stackoverflow.com/questions/4394724/inverse-probability-selection-inverse-fitness-selection-of-evolutionary-algorit