Skip to content

Commit 6a3cf62

Browse files
committed
rayl
1 parent c057ff3 commit 6a3cf62

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
3+
def comp_theta_mle(d):
4+
"""
5+
Computes the Maximum Likelihood Estimate for a given 1D training
6+
dataset for a Rayleigh distribution.
7+
8+
"""
9+
theta = len(d) / sum([x^2 for x in d])
10+
return theta
11+
12+
def likelihood_ray(x, theta):
13+
"""
14+
Computes the class-conditional probability for an univariate
15+
Rayleigh distribution
16+
17+
"""
18+
return 2*theta*x*np.exp(-theta*(x**2))
19+
20+
if __name__ == "__main__":
21+
training_data = [10, 18, 19, 22, 24, 29, 33, 40, 68]
22+
theta = comp_theta_mle(training_data)
23+
24+
# Plot Probability Density Function
25+
from matplotlib import pyplot as plt
26+
27+
x_range = np.arange(0, 20, 0.1)
28+
y_range = [likelihood_ray(theta, x) for x in x_range]
29+
30+
plt.figure(figsize=(10,8))
31+
plt.plot(x_range, y_range, lw=2)
32+
plt.title('Probability density function for the Rayleigh distribution')
33+
plt.ylabel('p(x)')
34+
plt.xlabel('random variable x')
35+
36+
plt.show()

0 commit comments

Comments
 (0)