import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from scipy.stats import binom
style.use('bmh')
#Not to show warning messages (to keep the notebook clean)
import warnings
warnings.filterwarnings('ignore')
#FOR TESTING
from scipy.stats import poisson
#Array a - Binomial
n=100
p=0.3
array1a = np.random.binomial(n,p, 10000)
print(array1a)
n_bins100 = np.max(array1a) - np.min(array1a)
plt.figure(figsize=(14,5))
plt.hist(array1a, n_bins100, density=True)
#plt.hist(samples_mean2,n_bins2,density=True)
plt.xlabel('$n$')
plt.ylabel('Frequency')
plt.title('Binomial distribution')
plt.xlim([10, 50])
plt.show()
##
n=100
p=0.3
n_arange = np.arange(50)
plt.figure(figsize=(14,5))
plt.step(n_arange, binom.pmf(n_arange, n, p), where='pre', label='$n=100, p=0.3$')
plt.xlabel('$n$')
plt.ylabel('Probability')
plt.title('Binomial distribution')
#plt.ylim([0, 1])
plt.xlim([10, 50])
plt.grid(True) #grid
plt.legend()
plt.show()
plt.figure(figsize=(14,5))
plt.hist(array1a, n_bins100, density=True)
plt.step(n_arange, binom.pmf(n_arange, n, p), where='pre', label='$n=100, p=0.3$')
plt.xlabel('$n$')
plt.ylabel('Frequency of $N = n$')
plt.title('Binomial distribution')
plt.show()
#Array b - Binomial
n2=10000
p=0.6
array1b = np.random.binomial(n2,p, 10000)
print(array1b)
n_bins10k = np.max(array1b) - np.min(array1b)
plt.figure(figsize=(14,5))
plt.hist(array1b, n_bins10k, density=True)
#plt.hist(samples_mean2,n_bins2,density=True)
plt.xlabel('$n$')
plt.ylabel('Frequency')
plt.title('Binomial distribution')
plt.xlim([5750, 6250])
plt.show()
##
n=10000
p=0.6
n_arange2 = np.arange(6250)
plt.figure(figsize=(14,5))
plt.step(n_arange2, binom.pmf(n_arange2, n2, p), where='pre', label='$n=10000, p=0.6$')
plt.xlabel('$n$')
plt.ylabel('Probability')
plt.title('Binomial distribution')
#plt.ylim([0, 1])
plt.xlim([5750, 6250])
plt.grid(True) #grid
plt.legend()
plt.show()
plt.figure(figsize=(14,5))
plt.hist(array1b, n_bins10k, density=True)
plt.step(n_arange2, binom.pmf(n_arange2, n, p), where='pre', label='$n=100, p=0.3$')
plt.xlabel('$n$')
plt.ylabel('Frequency of $N = n$')
plt.title('Binomial distribution')
plt.xlim([5750, 6250])
plt.show()
#Upgrading the library to v2.3
! pip install --upgrade networkx
import networkx as nx #https://networkx.github.io/
import matplotlib.pyplot as plt #https://matplotlib.org/
n = 15
pa = 0.2
era = nx.erdos_renyi_graph(n, pa)
nx.draw_networkx(era, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()
n = 15
pb = 0.5
erb = nx.erdos_renyi_graph(n, pb)
nx.draw_networkx(erb, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()
n = 15
pc = 0.8
erc = nx.erdos_renyi_graph(n, pc)
nx.draw_networkx(erc, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()