samedi 13 janvier 2024

reduce a list of objects given an associated list of likelyhoods

I have a list (aka, slice) of objects. I also have a list of the same size that contains the likelyhood that each object will be useful in the future. I need to reduce my object list length so that it has n or fewer elements. (It may or may not have n+ elements to start.) How can I do this efficiently?

I was thinking I could sort the object list according to the probabilities and then truncate it. However, I want the low-probability objects to have a chance of remaining. I was also thinking that I could check the probability on each item against a random number to see if it lives or dies, but then I might end up with fewer than n items in the end.




Aucun commentaire:

Enregistrer un commentaire