Fastest Way To Iterate Over A Probability Simplex
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Tue May 22 06:29:03 EDT 2007
On May 22, 11:19 am, Efrat Regev:
> I want to iterate over all
> such vectors under the constraint that the granularity of
> each component is at most some delta.
You can think of this like your sum is an integer>=1 and the single
"probabilities" are integers>=1 So given the sum, like 6, you can find
all the parts of it, and then find all the permutations of such parts.
Eppstein has given code for the parts of an integer, and you can can
find the iterable permutations code on the cookbook. But the number of
such possible vectors grows very quickly...
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/218332
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474124
Bye,
bearophile
More information about the Python-list
mailing list