def ll_of_count(counts, means, stds):
cm = np.copy(counts)
cm = (cm*255./cm.max()).astype(np.uint8)
cm = cm[np.where(cm.sum(axis=1))]
if cm.shape[0] == 0:
cm = np.zeros((10, 30), dtype = np.uint8)
im = Image.fromarray(cm).resize((30,10), Image.ANTIALIAS)
counts_resized_arr = np.array(im.getdata(), dtype=np.float32).reshape(10,30)/255.
max_ll = -10000000
for roll_by in xrange(30):
resized_counts = np.roll(counts_resized_arr, roll_by, axis=1).flatten()
ll = 0.
for i in xrange(resized_counts.shape[0]):
ll += np.log(scipy.stats.norm.pdf(resized_counts[i], loc=means[i], scale=stds[i]))
if ll > max_ll:
max_ll = ll
return max_ll
评论列表
文章目录