Gauss test.py
From Werner KRAUTH
Revision as of 22:03, 22 September 2015; view current revision
←Older revision | Newer revision→
←Older revision | Newer revision→
This page presents the program gauss_test.py, a direct-sampling algorithm for two independent Gaussian random numbers. This algorithm is used to illustrate the concept of "sample transformation"
Contents |
[edit]
Description
[edit]
Program
import random, math def gauss_test(sigma): phi = random.uniform(0.0, 2.0 * math.pi) Upsilon = random.uniform(0.0, 1.0) Psi = - math.log(Upsilon) r = sigma * math.sqrt(2.0 * Psi) x = r * math.cos(phi) y = r * math.sin(phi) return [x, y] nsamples = 50 for sample in range(nsamples): [x, y] = gauss_test(1.0) print x, y
[edit]
Version
See history for version information.