I am working on a project which I have to compute the distribution of Dirichlets on a dataset. I found some code in this tutorial which is developed by Benjamin Bengfort.
as a training example I developed this basic code to understand and test the code in the given link:
from collections import Counter
train_list = [1,2,1,2,1,3,4,1,2,3]
counter = Counter(train_list)
votes = [counter.get(n,0) for n in range(1,5)]
prior = [2,2,2,2]
posterior = map(sum, zip(votes, prior))
weights = map(lambda i: (i[0]+1)*i[1], enumerate(posterior))
N = sum(posterior)
print(float(sum(weights)) / N)
I ran the code in both python 3.5 and python 2.7.
I always get the same result in python 3.5 which equals to zero, no matter if I change the train_list or not.
But in python 2.7 I get a float number which I guess happens to be the right answer because it changes whenever I modify the values in train_list.
I don't know why it happens?
The reason might be the difference of procedure in map, lambda or enumerate functions between python 2.7 and python 3.5.
It would be highly appreciated if anyone could help me fix the code in python 3.5.