Say I have a function that returns a weighted selection from a set of resources, according to a desired distribution. For argument's sake let that resource be string colors.
const distribution = {
red: .1666, // We want 1/6th of colors in the world to be 'red'
yellow: .3333, // ... 1/3 to be 'yellow'
blue: .5 // ... and 1/2 to be 'blue'
}
// returns ~1/6 'red', ~1/3 'yellow', ~1/2 'blue'
function getWeightedColor() {...}
If I wanted to further weight the return value based on existing data with the purpose of guiding the data toward the desired distribution more quickly, how would I achieve that?
// Accepts a counts dict in the format `{<color>: count, ...}` and based on
// the distribution of that dict, further weights the selection such that
// the return value adjusts the dict toward the desired distribution.
function getWeightedColor(colorCounts) {...}
// Examples:
getWeightedColor({red: 100, yellow: 200, blue: 300});
// given distribution already normal, so we'd use the unadjusted weights
getWeightedColor({red: 100, yellow: 250, blue: 10});
// given distribution has far too few blues and somewhat too many yellows,
// so the weights would be adjusted to compensate. The odds of 'blue'
// would be greatly increased, red somewhat decreased and yellow moreso.