Created
January 10, 2017 15:32
-
-
Save galeone/a3e4d773bc6c4cbc9b18e9940e246a00 to your computer and use it in GitHub Desktop.
Draw the probability of the binomial distribution, varying the probability
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 matplotlib.pyplot as plt | |
from scipy.stats import binom | |
import numpy as np | |
# number of neurons | |
n = 1024 | |
# number of tests (input examples) | |
size = 500 | |
# histogram bin width, for data visualization | |
binwidth = 5 | |
for p in range(1, 10): | |
# per layer probability | |
prob = p / 10 | |
# generate size values from a bi(n, prob) | |
rnd_values = binom.rvs(n, prob, size=size) | |
# draw histogram of rnd values | |
plt.hist( | |
rnd_values, | |
bins=[x for x in range(0, n, binwidth)], | |
# normalize = extract the probabilities | |
normed=1, | |
# pick a random color | |
color=np.random.rand(3, 1), | |
# label the histogram with its probability | |
label=str(prob)) | |
plt.legend(loc='upper right') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment