diff --git a/README.md b/README.md index 8c16d9a3..ca04eef3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/squigglepy/makefile b/squigglepy/makefile new file mode 100644 index 00000000..3fc3672d --- /dev/null +++ b/squigglepy/makefile @@ -0,0 +1,10 @@ +install: + pip3 install squigglepy + pip3 install numpy + +run: + python3 samples.py + +time: + time python3 samples.py + diff --git a/squigglepy/samples.py b/squigglepy/samples.py new file mode 100644 index 00000000..1d5132b3 --- /dev/null +++ b/squigglepy/samples.py @@ -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)) diff --git a/time.txt b/time.txt index 1cd53214..bafaae51 100644 --- a/time.txt +++ b/time.txt @@ -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