Mike Simmons wrote:Aside from the extra collection, I'm a bit troubled by doing all the summation on floating-point values. Seems like it would be less error prone to do the summation on longs, with nice precise values, and then divide by the observation count at the end. In this way you can better guarantee that the total probability will be 1.0, rather than 0.999999999756 or some such.
In several places, we could also replace List and TreeMap with more general types like Collection and NavigableMap. But I get used to the short versions of each, even when they're unnecessarily specific.
Here are the tweaks I came up with, for your consideration:
Piet Souris wrote:thanks for the critiques, even if it is not very egoless!
As you see, it is just a very clear short one-liner.
Hmm, cdf is a very much used abbreviation, so for me it was very clear.
Correct, but for now I limit myself to numeric random variables, with their in-built natural ordering.