Skip to content

Commit 44fb830

Browse files
committed
first week for 10601ML
1 parent 1b719d3 commit 44fb830

File tree

11 files changed

+71
-0
lines changed

11 files changed

+71
-0
lines changed
Binary file not shown.
Binary file not shown.

10601ML-CMU/lec3/Joint_MLE_MAP.pdf

315 KB
Binary file not shown.

10601ML-CMU/lec3/homework2.pdf

190 KB
Binary file not shown.

10601ML-CMU/lec3/homework2_sol.pdf

246 KB
Binary file not shown.

10601ML-CMU/lec3/hw2.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
beta_3_3 = 0.0333
5+
6+
def theta_MLE(theta,n,positive):
7+
return (theta ** positive)*((1 - theta) **(n-positive))
8+
9+
10+
def theta_MAP(theta,n,positive):
11+
return theta_MLE(theta,n,positive) *(theta**2) * (1-theta) ** 2 / beta_3_3
12+
13+
def problem2():
14+
theta = np.linspace(0,1,endpoint= False)
15+
l_theta = theta_MLE(theta,n=10,positive=6)
16+
plt.plot(theta,l_theta,label = 'n=10,positive=6')
17+
plt.plot(theta, theta_MLE(theta,5,3),label ='n=5,positive=3')
18+
plt.plot(theta,theta_MLE(theta,100,60),label ='n=100,positive = 60')
19+
plt.legend()
20+
plt.show()
21+
22+
def problem3():
23+
theta = np.linspace(0,1,num=100,endpoint=False)
24+
y = theta_MAP(theta,10,6)
25+
plt.plot(theta,y,label = 'n=10,positive = 3')
26+
plt.plot(theta, theta_MAP(theta,5,3),label ='n=5,positive=3')
27+
plt.plot(theta,theta_MAP(theta,100,60),label ='n=100,positive = 60')
28+
29+
plt.legend()
30+
plt.show()
31+
32+
33+
if __name__ == "__main__":
34+
# problem2()
35+
problem3()

10601ML-CMU/lec3/hw2solution.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# problem 2
2+
3+
1. <br>
4+
5+
$$
6+
\begin{aligned}
7+
L(\theta) &= \prod \theta^{X_i}(1- \theta) ^{1-X_i}\\
8+
&= \theta^{\sum X_i}(1-\theta)^{n-\sum X_i}
9+
\end{aligned}
10+
$$
11+
12+
2. <br>
13+
14+
[code](./hw2.py)
15+
16+
![Ltheta](img/pb2.png)
17+
18+
3. <br>
19+
20+
$$
21+
\begin{aligned}
22+
Ln\ L(\theta) &= ln\ \theta\sum X_i +(n - \sum X_i)ln(1-\theta)\\
23+
\frac{\partial Ln\ L(\theta)}{\partial \theta} &= \frac{\sum X_i}{\theta} + -1\frac{n - \sum X_i}{1 - \theta} = 0\\
24+
\theta& = \frac{\sum X_i}{\theta} = 0.6
25+
\end{aligned}
26+
$$
27+
28+
4. <br>
29+
30+
![pb2-3.png](img/pb2-3.png)
31+
32+
# problem 3
33+
34+
35+
![pb3-1](img/pb3-1.png)
36+

10601ML-CMU/lec3/img/pb2-3.png

28.9 KB
Loading

10601ML-CMU/lec3/img/pb2.png

22.3 KB
Loading

10601ML-CMU/lec3/img/pb3-1.png

27 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)