Skip to content

Instantly share code, notes, and snippets.

@jfae
jfae / crp_generator.py
Created November 1, 2017 21:14 — forked from beaucronin/crp_generator.py
A Python generator for the Chinese Restaurant Process
from random import random
def crpgen(N = None, alpha = 1.0):
"""
A generator that implements the Chinese Restaurant Process
"""
counts = []
n = 0
while N == None or n < N:
# Compute the (unnormalized) probabilities of assigning the new object