Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- import numpy as np
- n = 10
- z = np.random.random(n)
- z = z / np.sum(z)
- total_cnt = 100000
- cnts = defaultdict(int)
- for i in range(total_cnt):
- u = np.random.uniform(size=n)
- g = -np.log(-np.log(u))
- x = np.argmax(g + np.log(z))
- cnts[x] += 1
- print(np.var(np.array([cnts[x] for x in cnts.keys()]) / float(total_cnt) - z))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement