probcomp / crosscat

A domain-general, Bayesian method for analyzing high-dimensional data tables
http://probcomp.csail.mit.edu/crosscat/
Apache License 2.0
322 stars 42 forks source link

suspicious implementation of sampling from categorical for cluster assignments #55

Open riastradh-probcomp opened 9 years ago

riastradh-probcomp commented 9 years ago

simple_predictive_sample_unobserved (https://github.com/probcomp/crosscat/blob/b0a7c1a8e150d4c918d7c3a0325a09282cc7ae7e/crosscat/utils/sample_utils.py#L547-L549) does this:

        probs = numpy.exp(cluster_logps)
        probs /= sum(probs)
        draw = numpy.nonzero(numpy.random.multinomial(1, probs))[0][0]
axch commented 9 years ago

Which is sad, because that operation is called sampleLogCategorical (in the Venture codebase), and it really should subtract off the maximum of the cluster_logps before starting to exponentiate them, lest loss of precision lead to bad results or crashes.

Separately, it probably shouldn't use numpy's ambient prng for its entropy, but that feels like a more involved problem.

riastradh-probcomp commented 9 years ago

Use of numpy's entropy is now issue #56.