Skip to content

Instantly share code, notes, and snippets.

@galeone
Created January 10, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galeone/a3e4d773bc6c4cbc9b18e9940e246a00 to your computer and use it in GitHub Desktop.
Save galeone/a3e4d773bc6c4cbc9b18e9940e246a00 to your computer and use it in GitHub Desktop.
Draw the probability of the binomial distribution, varying the probability
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