disclaimer: this is not my strong side, sorry for any misused vocabulary,
I'm trying to remove random elements from a list of cartesian combinations of values,
so that it affects the items in a less uniform way.
So that for example some items do not exist anymore, or in very low quantities, while others keep their numbers.
but although I'm dropping 200+ items from the total of 625 items, no single items ever gets a distribution lower than around ~70.
I would have expected for some items completely disappear, or at least get a lot less distributed.
I guess it's something simple I'm missing, but I'm stuck...
base = [
['a1', 'a2', 'a3', 'a4', 'a5'],
['b1', 'b2', 'b3', 'b4', 'b5'],
['c1', 'c2', 'c3', 'c4', 'c5'],
['d1', 'd2', 'd3', 'd4', 'd5'],
]
const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat())))
const countDistributions = output => {
const counts = {}
output.forEach(item => {
item.forEach(letter => {
counts[letter] = (counts[letter] || 0) + 1
})
})
return counts
}
const output = cartesian(...base)
console.log(countDistributions(output))
output.sort(() => Math.random() - 0.5)
const dropSize = output.length / 3
truncatedOutput = output.slice(0, output.length - dropSize)
console.log(countDistributions(truncatedOutput))
Aucun commentaire:
Enregistrer un commentaire