-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (40 loc) · 1.39 KB
/
utils.py
File metadata and controls
53 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
import matplotlib.pyplot as plt
def estimate_gaussian_params(sample):
### START CODE HERE ###
mu = np.mean(sample)
sigma = np.std(sample)
### END CODE HERE ###
return mu, sigma
def estimate_binomial_params(sample):
### START CODE HERE ###
n = 30
p = (sample / n).mean()
### END CODE HERE ###
return n, p
def estimate_uniform_params(sample):
### START CODE HERE ###
a = sample.min()
b = sample.max()
### END CODE HERE ###
return a, b
def plot_gaussian_distributions(gaussian_0, gaussian_1, gaussian_2):
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.hist(gaussian_0, alpha=0.5, label="gaussian_0", bins=32)
ax.hist(gaussian_1, alpha=0.5, label="gaussian_1", bins=32)
ax.hist(gaussian_2, alpha=0.5, label="gaussian_2", bins=32)
ax.set_title("Histograms of Gaussian distributions")
ax.set_xlabel("Values")
ax.set_ylabel("Frequencies")
ax.legend()
plt.show()
def plot_binomial_distributions(binomial_0, binomial_1, binomial_2):
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.hist(binomial_0, alpha=0.5, label="binomial_0")
ax.hist(binomial_1, alpha=0.5, label="binomial_1")
ax.hist(binomial_2, alpha=0.5, label="binomial_2")
ax.set_title("Histograms of Binomial distributions")
ax.set_xlabel("Values")
ax.set_ylabel("Frequencies")
ax.legend()
plt.show()