diff options
| author | KunoiSayami <[email protected]> | 2022-06-21 07:55:51 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2022-06-21 07:55:51 +0800 |
| commit | 985dfaf9f1b541b51e020561ccc9b91d9c982510 (patch) | |
| tree | 2a70518d24b9754d7e6fb086ee81dd00baaacbe7 /ex_normal_distribution.py | |
| parent | 85296957a8d755cda80c5dc00dcef4555ff14ebc (diff) | |
feat(script): Optimize normal distribution generator
* feat(script): Finish experiment 1 and 2
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'ex_normal_distribution.py')
| -rwxr-xr-x | ex_normal_distribution.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/ex_normal_distribution.py b/ex_normal_distribution.py index f82df93..272b9b6 100755 --- a/ex_normal_distribution.py +++ b/ex_normal_distribution.py @@ -1,24 +1,35 @@ #!/usr/bin/env python3 +import numpy as np import matplotlib.pyplot as plt +from matplotlib.ticker import PercentFormatter def function_pdf(element: list[int]): - plt.hist(element, bins=500) + plt.hist(element, bins=500, histtype='step') plt.show() def function_cdf(element: list[int]): - plt.hist(element, bins=500, cumulative=True) + plt.hist(element, bins=500, cumulative=True, histtype='step') plt.show() -def normal_distribution(): +def function_1000_cdf(element: list[int]): + plt.hist(element, bins=250, histtype='step', label='x', cumulative=True, + weights=np.ones(len(element)) / len(element)) + plt.hist(element[:1000], bins=100, histtype='step', label='y', cumulative=True, weights=np.ones(1000) / 1000) + plt.gca().yaxis.set_major_formatter(PercentFormatter(1)) + plt.show() + + +def normal_distribution() -> list[int]: with open('normal_distribution.txt') as fin: context = fin.read() - elements = list(map(int, context.splitlines())) - function_pdf(elements) - function_cdf(elements) + return list(map(int, context.splitlines())) if __name__ == '__main__': - normal_distribution() + elements = normal_distribution() + function_pdf(elements) + function_cdf(elements) + function_1000_cdf(elements) |
