1
Fork 0

Add tram stat problem and python directory

This commit is contained in:
Matei Adriel 2024-01-25 22:50:19 +01:00
parent bbc524d5fd
commit 53be1edb66
No known key found for this signature in database
4 changed files with 56 additions and 0 deletions

View file

@ -12,3 +12,4 @@ The experiments are currently organized based on the language they use:
- [Lua](./lua/) - [Lua](./lua/)
- [Idris](./idris/) - [Idris](./idris/)
- [Typst](./typst/) - [Typst](./typst/)
- [Python](./python/)

5
python/README.md Normal file
View file

@ -0,0 +1,5 @@
# Python
| Name | Description |
| ---------------------------------------- | ------------------------------------------------------------------ |
| [tram-stat-problem](./tram-stat-problem) | Quick script to visualize a dumb stat problem I was thinking about |

View file

@ -0,0 +1,40 @@
import numpy as np
import matplotlib.pyplot as plt
size = 100000
fig, axes = plt.subplots(3, 3, figsize=(15, 15))
fig.subplots_adjust(hspace=0.5)
def check(label, tram, ax):
bugun = np.random.uniform(0, 100, size=size)
tram = np.clip(tram, 0, 100)
result = (tram - 10 <= bugun) & (bugun < tram)
count = np.sum(result)
print(f"{label}: {count}")
# ax.hist(bugun, alpha=0.5, label="Bugun", histtype="step", bins="auto")
# ax.hist(tram, alpha=0.5, label="Tram", histtype="step", bins="auto")
ax.hist(tram - bugun, label="Difference", bins="auto")
ax.set_title(label)
ax.legend()
distributions = [
("uniform", np.random.uniform(0, 100, size=size)),
("normal(1)", np.random.normal(50, 1, size=size)),
("normal(10)", np.random.normal(50, 10, size=size)),
("normal(30)", np.random.normal(50, 30, size=size)),
("normal(50)", np.random.normal(50, 50, size=size)),
("normal(70)", np.random.normal(50, 70, size=size)),
("normal(100)", np.random.normal(50, 100, size=size)),
("normal(10000)", np.random.normal(50, 10000, size=size)),
]
for i in range(len(distributions)):
check(*distributions[i], axes.flat[i])
plt.show()

View file

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
packages = [
(pkgs.python3.withPackages (ps: with ps; [
numpy
matplotlib
]))
];
}