This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementation of a chinese restaurant process function for a given list of word vectors. | |
def crp(vecs): | |
clusterVec = [[0.0] * 25] # tracks sum of vectors in a cluster | |
clusterIdx = [[]] # array of index arrays. e.g. [[1, 3, 5], [2, 4, 6]] | |
ncluster = 0 | |
# probablity to create a new table if new customer | |
# is not strongly "similar" to any existing table | |
pnew = 1.0/ (1 + ncluster) | |
N = len(vecs) | |
rands = [random.random() for x in range(N)] # N rand variables sampled from U(0, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vecs: an array of real vectors | |
def crp(vecs): | |
clusterVec = [] # tracks sum of vectors in a cluster | |
clusterIdx = [] # array of index arrays. e.g. [[1, 3, 5], [2, 4, 6]] | |
ncluster = 0 | |
# probablity to create a new table if new customer | |
# is not strongly "similar" to any existing table | |
pnew = 1.0/ (1 + ncluster) | |
N = len(vecs) | |
rands = random.rand(N) # N rand variables sampled from U(0, 1) |