Lecture1
Likehood possibility¶
\[L(H|E) = P(E|H) \]
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats
mu = 3.0
sigma = 0.5
data = np.random.randn(100000) * sigma + mu
hx, hy, _ = plt.hist(data, bins=50,color="lightblue")
plt.ylim(0.0,max(hx)+0.05)
plt.title(r'Normal distribution $\mu_0 = 3$ and $\sigma_0 = 0.5$')
plt.grid()
Calculate the log-likelihood¶
scipy.stats.norm.pdf(6,2.0,1.0)
print( np.log(scipy.stats.norm.pdf(data,2.0,1.0)).sum() )
x = np.linspace(-10, 10, 1000, endpoint=True)
y = []
for i in x:
y.append(np.log(scipy.stats.norm.pdf(data,i,0.5)).sum())
plt.plot(x,y)
plt.title(r'Log-Likelihood')
plt.xlabel(r'$\mu$')
plt.grid()
-154314.14596206427
print('mean ---> ', np.mean(data))
print('std deviation ---> ', np.std(data))
mean ---> 2.999606326069087
std deviation ---> 0.4991923934863224
y_min = y.index(max(y))
print('mean (from max log likelohood) ---> ', x[y_min])
mean (from max log likelohood) ---> 2.9929929929929937