commit 3dac5f35cd60a9b0068013ff1fd289ee34f9935b
parent 60ea376a1993ab1341b30ca21b5ab443a7df38d0
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Thu, 8 Jun 2023 19:12:07 -0600
add SquigglePy
Diffstat:
4 files changed, 38 insertions(+), 0 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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