Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 000749add1 | |||
| 3fc312ba9d | |||
| 0716f02766 | |||
| 7b0fbb0262 | |||
| 31b40de191 | |||
| 41294cf3bf | |||
| e8c8f0ed13 | |||
| dfc558ca16 | |||
| 6098da86fa | |||
| f92ed7d66d | |||
| e8781c5ef4 | |||
| e19254a82f | |||
| 15ca83ca76 | |||
| a1fb10842d |
38
src/2026-01-30/gen_correlated_data.py
Normal file
38
src/2026-01-30/gen_correlated_data.py
Normal file
@ -0,0 +1,38 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from numpy.typing import NDArray
|
||||
import argparse
|
||||
|
||||
|
||||
def twodim_array_to_pgfplots_table_string(a: NDArray):
|
||||
return (
|
||||
" \\\\\n".join([" ".join([str(vali) for vali in val]) for val in a]) + "\\\\\n"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
# Parse command line arguments
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--correlation", "-c", type=np.float32, required=True)
|
||||
parser.add_argument("-N", type=np.int32, required=True)
|
||||
parser.add_argument("--plot", "-p", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Generate & plot data
|
||||
|
||||
means = np.array([0, 0])
|
||||
cov = np.array([[1, args.correlation], [args.correlation, 1]])
|
||||
|
||||
x = np.random.multivariate_normal(means, cov, size=args.N)
|
||||
|
||||
print(twodim_array_to_pgfplots_table_string(x))
|
||||
|
||||
if args.plot:
|
||||
plt.scatter(x[:, 0], x[:, 1])
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
40
src/2026-01-30/gen_histogram.py
Normal file
40
src/2026-01-30/gen_histogram.py
Normal file
@ -0,0 +1,40 @@
|
||||
import argparse
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.special import binom
|
||||
|
||||
|
||||
def array_to_pgfplots_table_string(a):
|
||||
return " ".join([f"({k}, {val})" for (k, val) in enumerate(a)]) + f" ({len(a)}, 0)"
|
||||
|
||||
|
||||
def P_binom(N, p, k):
|
||||
return binom(N, k) * p**k * (1 - p) ** (N - k)
|
||||
|
||||
|
||||
def main():
|
||||
# Parse command line arguments
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-N", type=np.int32, required=True)
|
||||
parser.add_argument("-p", type=np.float32, required=True)
|
||||
parser.add_argument("--show", "-s", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Generate and show data
|
||||
|
||||
N = args.N
|
||||
p = args.p
|
||||
|
||||
bars = np.array([P_binom(N, p, k) for k in range(N + 1)])
|
||||
|
||||
print(array_to_pgfplots_table_string(bars))
|
||||
|
||||
if args.show:
|
||||
plt.stem(bars)
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1331
src/2026-01-30/presentation.tex
Normal file
1331
src/2026-01-30/presentation.tex
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user