-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranking_space.py
62 lines (52 loc) · 1.68 KB
/
ranking_space.py
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
54
55
56
57
58
59
60
61
62
import numpy
__author__ = '@gavruskin'
# Returns a list of permutation neighbors of w.
def give_rank_neighbors(w):
output = []
for i in range(len(w) - 1):
v = [None]*len(w)
for j in range(len(w)):
if j == i:
v[j] = w[i+1]
elif j == i+1:
v[j] = w[i]
else:
v[j] = w[j]
output.append(v)
return output
# A negative number indicates how strong the positive epistasis is.
# Important this is not a metric!
def dist_to_positive_epi(w, positives={1, 5, 6, 7}, negatives={4, 3, 2, 8}):
count = 0
count_values = []
for i in range(len(w)):
if w[i] in negatives:
count -= 1
count_values.append(count)
elif w[i] in positives:
count += 1
count_values.append(count)
else:
print("Your w has an unsigned entry in dist_to_positive_epi.")
return
output = numpy.max(count_values)
return output
# A negative number indicates how strong the negative epistasis is.
# Important this is not a metric!
def dist_to_negative_epi(w, positives={1, 5, 6, 7}, negatives={4, 3, 2, 8}):
count = 0
count_values = []
for i in range(len(w)):
if w[i] in negatives:
count -= 1
count_values.append(count)
elif w[i] in positives:
count += 1
count_values.append(count)
else:
print("Your w has an unsigned entry in dist_to_positive_epi")
return
output = numpy.min(count_values)
return output
print(dist_to_positive_epi([8, 3, 7, 6, 5, 2, 4, 1]))
print(dist_to_negative_epi([8, 3, 7, 6, 5, 2, 4, 1]))