time-to-botec/squigglepy/samples.py
Peter Wildeford 05566faf75
Fix squigglepy
Corrects the "ValueError: You cannot nest discrete distributions within mixture distributions"

Runs in 4.6s on my laptop (M2 chip)
2023-06-09 22:00:20 +01:00

19 lines
356 B
Python

import squigglepy as sq
import numpy as np
p_a = 0.8
p_b = 0.5
p_c = p_a * p_b
dist_0 = 0
dist_1 = 1
dist_some = sq.to(1, 3)
dist_many = sq.to(2, 10)
dists = [dist_0, dist_1, dist_some, dist_many]
weights = [(1 - p_c), p_c/2, p_c/4, p_c/4 ]
result = sq.mixture(dists, weights)
result_samples = sq.sample(result, 1000000)
print(np.mean(result_samples))