Created
June 2, 2015 18:24
-
-
Save adusak/90ed43bff049cf8197ae to your computer and use it in GitHub Desktop.
Centrální limitní věta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
cube1 = [x / 21 for x in range(1, 7)] | |
cube2 = list(reversed(cube1)) | |
def cube1_throw(number_throws=1000): | |
return cube_throw(number_throws, cube1) | |
def random_cube_throw(number_throws=1000): | |
results = [] | |
for i in range(number_throws): | |
cn = np.random.choice(2) | |
if cn == 0: | |
cube = cube1 | |
else: | |
cube = cube2 | |
choice = np.random.choice(6, 1, p=cube)[0] | |
results.append(choice + 1) | |
return results | |
# plot_results(results) | |
def one_random_cube_throw(number_throws=1000): | |
cn = np.random.choice(2) | |
if cn == 0: | |
cube = cube1 | |
else: | |
cube = cube2 | |
return cube_throw(number_throws, cube) | |
def cube_throw(number_throws, cube) -> [int]: | |
results = [] | |
for i in range(number_throws): | |
choice = np.random.choice(6, 1, p=cube)[0] | |
results.append(choice + 1) | |
return results | |
def calculate_avgs(results, repeats) -> {}: | |
plotyplot = {} | |
for i in range(6): | |
plotyplot[i + 1] = results.count(i + 1) / repeats | |
return plotyplot | |
def plot_results(results): | |
plotyplot = {} | |
for i in range(6): | |
plotyplot[i + 1] = results.count(i + 1) | |
print(plotyplot) | |
plt.figure() | |
ax = plt.subplot(111) | |
ax.bar(plotyplot.keys(), plotyplot.values()) | |
plt.show() | |
def uk1(): | |
repeats = 1000 | |
results = [] | |
for i in range(repeats): | |
results.append(sum(random_cube_throw(100)) / 100) | |
plt.clf() | |
plt.hist(results, normed=True) | |
# plt.show() | |
plt.savefig("uk1.png") | |
def uk2(): | |
repeats = 1000 | |
results = [] | |
for i in range(repeats): | |
results.append(sum(cube1_throw(100)) / 100) | |
plt.clf() | |
plt.hist(results, normed=True) | |
# plt.show() | |
plt.savefig("uk2.png") | |
def uk3(): | |
repeats = 1000 | |
results = [] | |
for i in range(repeats): | |
results.append(sum(one_random_cube_throw(100)) / 100) | |
plt.clf() | |
plt.hist(results, normed=True) | |
# plt.show() | |
plt.savefig("uk3.png") | |
uk1() | |
uk2() | |
uk3() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment