Added distribution.py
This commit is contained in:
parent
89001d47a0
commit
28a1123bab
37
src/experiments/algorithms/distribution.py
Normal file
37
src/experiments/algorithms/distribution.py
Normal file
@ -0,0 +1,37 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
|
||||
mean = 125
|
||||
sd = 20
|
||||
N = 255
|
||||
f = np.zeros(N, dtype=np.longdouble)
|
||||
|
||||
def calcNormalFunc(mean, sd, len):
|
||||
f = np.zeros(len, dtype=np.longdouble)
|
||||
|
||||
# calculate PDF
|
||||
for x in range(len):
|
||||
exp = (-(x - mean) ** 2)/(2 * sd ** 2)
|
||||
f[x] = 1 / math.sqrt(2 * np.pi * sd** 20 ) * (math.exp(exp))
|
||||
|
||||
# normalize PDF
|
||||
max = np.amax(f)
|
||||
min = np.amin(f)
|
||||
for x in range(len):
|
||||
f[x] = (f[x] - min) / (max - min)
|
||||
|
||||
return f
|
||||
|
||||
f = calcNormalFunc(mean, sd, N)
|
||||
|
||||
plt.title("PDF: $\mu = %d$, $\sigma = %d$"%(mean, sd))
|
||||
plt.plot(f)
|
||||
plt.grid()
|
||||
plt.xlim(0, 255)
|
||||
plt.ylim(0, 1.05)
|
||||
plt.show()
|
||||
|
||||
print("Score at 1 sigma: %f"%f[sd+mean])
|
||||
print("Score at 2 sigma: %f"%f[2*sd+mean])
|
||||
print("Score at 3 sigma: %f"%f[3*sd+mean])
|
Loading…
Reference in New Issue
Block a user