MLE示例
- 如圖所示,有兩枚硬幣A、B,每一個實驗隨機取一枚拋擲10次,共5個實驗。
- 如果我們可觀測到每一次所取的硬幣,就可根據極大似然估計求解參數A、B爲正面的概率θ=(θA,θB),。
(30頁)
高斯分佈的MLE示例
- import numpy as np
- import matplotlib.pyplot as plt
- fig = plt.figure()
- mu = 30 # mean of distribution
- sigma = 2 # standard deviation of distribution
- x = mu + sigma * np.random.randn(10000)
- def mle(x):
- u = np.mean(x)
- return u, np.sqrt(np.dot(x - u, (x - u).T) / x.shape[0])
- print(mle(x))
- num_bins = 100
- plt.hist(x, num_bins)
- plt.show()