/
selection_functions.py
85 lines (50 loc) · 1.58 KB
/
selection_functions.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Module containing various selection functions previously used in the literature.
@author davidrpugh
"""
import sympy as sym
class U(sym.Function):
"""Generic selection function"""
is_real = True
is_nonnegative = True
@classmethod
def eval(cls, x):
"""We require the U(0)=0 and U(1)=1"""
if x.is_Number and x is sym.S.Zero:
return sym.S.Zero
elif x.is_Number and x is sym.S.One:
return sym.S.One
class RandomSelection(U):
@classmethod
def eval(cls, x):
"""We require the U(0)=0 and U(1)=1"""
if x.is_Number and x is sym.S.Zero:
return sym.S.Zero
elif x.is_Number and x is sym.S.One:
return sym.S.One
else:
return x
class UGA(U):
"""Selection function for G females."""
class UgA(U):
"""Selection function for g females."""
def kirkpatrick_selection(x_A, d=1):
return d * x_A / (1 + (d - 1) * x_A)
def kirkpatrick_selection_derivative(x_A, d=1):
return d / (1 + (d - 1) * x_A)**2
def perfect_selection(x_A, d):
return 1
def perfect_selection_derivative(x_A, d):
return 0
def random_selection(x_A, d):
return x_A
def random_selection_derivative(x_A, d):
return 1
def seger_selection(x_A, d=0):
return x_A * (1 + d * (1 - x_A))
def seger_selection_derivative(x_A, d=0):
return 1 + d * (1 - 2 * x_A)
def wright_selection(x_A, d=0):
return (d * x_A + (1 - d) * x_A**2)**0.5
def wright_selection_derivative(x_A, d=0):
return 0.5 * (d + 2 * (1 - d) * x_A) * (d * x_A + (1 - d) * x_A**2)**(-0.5)