add SquigglePy

This commit is contained in:
NunoSempere 2023-06-08 19:12:07 -06:00
parent 60ea376a19
commit 3dac5f35cd
4 changed files with 38 additions and 0 deletions

View File

@ -39,6 +39,7 @@ The title of this repository is a pun on two meanings of "time to": "how much ti
| Javascript (NodeJS) | 732ms | 69 |
| Squiggle | 1,536s | 14 |
| R | 7,000s | 49 |
| SquigglePy | 14.305s | 18 |
| Python (CPython) | 16,641s | 56 |
Time measurements taken with the [time](https://man7.org/linux/man-pages/man1/time.1.html) tool, using 1M samples.

10
squigglepy/makefile Normal file
View File

@ -0,0 +1,10 @@
install:
pip3 install squigglepy
pip3 install numpy
run:
python3 samples.py
time:
time python3 samples.py

18
squigglepy/samples.py Normal file
View File

@ -0,0 +1,18 @@
import squigglepy as sq
import numpy as np
p_a = 0.8
p_b = 0.5
p_c = p_a * p_b
dist_0 = sq.discrete({0: 1})
dist_1 = sq.discrete({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))

View File

@ -88,3 +88,12 @@ nim c --verbosity:0 -d:danger samples.nim && time ./samples --verbosity:0
real 0m0.068s
user 0m0.048s
sys 0m0.020s
## Squigglepy
$ time python3 samples.py
0.8847701592663298
real 0m14.305s
user 0m14.130s
sys 0m0.494s