3 ms·
This article is a bit rough around the edges, and they really should make it clear when they mean "pseudorandom" vs "random", especially when one goal of the ar
by benrbray 6y ago
This article is a bit rough around the edges, and they really should make it clear when they mean "pseudorandom" vs "random", especially when one goal of the article is ostensibly to explain pseudorandomness to laymen!
As an aside, using a source of random numbers to generate other random objects is quite an interesting problem! For converting from one probability distribution to another, we have classical methods like rejection/importance sampling, and modern deep learning makes constant use of the "reparameterization trick" [1,2]. Looking beyond just numbers, here's a neat trick for generating a random orthogonal matrix:
A = np.random(n,n)
Q,_ = np.qr(A)
With a small correction [3], we can guarantee that our samples have uniform distribution (Haar measure) on the space of all orthogonal matrices:
def haar_measure(n):
# naive method
Z = randn(n,n) + 1j*randn(n,n) / np.sqrt(2);
Q,R = np.linalg.qr(Z);
# correction
d = np.diag(R);
PH = np.diag(d) / np.absolute(d);
return Q @ PH;
For more, read about random matrix theory! As an exercise for the reader, how would you generate: a random symmetric matrix? a random skew-symmetric matrix? a random positive-definite matrix? a random hamiltonian path in a fixed graph?
[1]: http://gregorygundersen.com/blog/2018/04/29/reparameterization/ http://gregorygundersen.com/blog/2018/04/29/reparameterizati...
[2]: https://timvieira.github.io/blog/post/2014/07/31/gumbel-max-trick/ https://timvieira.github.io/blog/post/2014/07/31/gumbel-max-...
[3]: http://www.ams.org/notices/200705/fea-mezzadri-web.pdf http://www.ams.org/notices/200705/fea-mezzadri-web.pdf