-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlikelihood.py
More file actions
29 lines (20 loc) · 752 Bytes
/
likelihood.py
File metadata and controls
29 lines (20 loc) · 752 Bytes
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
import math
import matplotlib.pyplot as plt
D = [] # distances for each number X in the data set
n = 948 # total number of sites in the data set
X = [] # number of variable sites in the data set
y = [] # set of logarithms for likelihood
for s in range(1, 400, 10):
X.append(s)
for num in X:
d = ((-3/4) * math.log(1 - ((4 / 3) * (num / n))))
D.append(d)
def lkl(x, d):
l = (x * math.log((1 / 16) - ((1 / 16) * (math.exp((-4 * d) / 3))))) + \
((n - x) * math.log((1 / 16) + ((3 / 16) * (math.exp((-4 * d) / 3)))))
return l
# calculates the natural logarithm of likelihood since likelihood itself is generally too small to work with
for i in range(len(X)):
y.append(lkl(X[i], D[i]))
plt.plot(D, y)
plt.show()