Try again - using resampling and weighted observation model

This commit is contained in:
Danny Staple
2022-12-05 22:27:51 +00:00
parent bac9e4b69c
commit 543f4f3f0b
13 changed files with 1519 additions and 58 deletions
+16
View File
@@ -0,0 +1,16 @@
import random
import math
def get_standard_normal_sample():
"""Using the Marsaglia Polar method"""
# timeit on mac says - 0.915
while True:
u = random.uniform(-1, 1)
v = random.uniform(-1, 1)
s = u * u + v * v
if s >= 1:
continue
return u * math.sqrt(-2 * math.log(s) / s)
def get_gaussian_sample(mean, standard_deviation):
return get_standard_normal_sample() * standard_deviation + mean