I have a dictionary in python with key->value as str->int. If I have to chose a key based on it’s own value, then as the value gets larger the key has a lower possibility of being chosen.
For example, if key1=2 and key2->1, then the attitude of key1 should be 2:1.
How can I do this?
1. Construct a CDF-like list like this:
This function returns a tuple, the 1st value is the sum of probabilities, and 2nd value is the CDF.
2. Construct the sampler like this:
Usage:
You may want to make this into a class.