(phi)
| 39 | |
| 40 | |
| 41 | def sample_cluster_identity(phi): |
| 42 | # phi is a dictionary: cluster index -> probability of that cluster |
| 43 | # print "dictionary sample from:", phi |
| 44 | p = np.random.random() |
| 45 | cumulative = 0 |
| 46 | for j, q in phi.iteritems(): |
| 47 | cumulative += q |
| 48 | if p < cumulative: |
| 49 | return j |
| 50 | # print "cumulative:", cumulative |
| 51 | assert(False) # should never get here because cumulative = 1 by now |
| 52 | |
| 53 | |
| 54 | def sample_from_prior(c0, m0, a0, B0): |