|
@@ 85-117 (lines=33) @@
|
| 82 |
|
x = [x_b[i] + f * (pop[r[0]][i] - pop[r[1]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 83 |
|
return asarray(x) |
| 84 |
|
|
| 85 |
|
def CrossRand2(pop, ic, x_b, f, cr, rnd=rand, *args): |
| 86 |
|
r"""Mutation strategy with crossover. |
| 87 |
|
|
| 88 |
|
Mutation strategy uses five different random individuals from population. |
| 89 |
|
|
| 90 |
|
Mutation: |
| 91 |
|
Name: de/best/1 |
| 92 |
|
|
| 93 |
|
:math:`\mathbf{v}_{i, G} = \mathbf{x}_{r_1, G} + F \cdot (\mathbf{x}_{r_2, G} - \mathbf{x}_{r_3, G}) + F \cdot (\mathbf{x}_{r_4, G} - \mathbf{x}_{r_5, G})` |
| 94 |
|
where :math:`r_1, r_2, r_3, r_4, r_5` are random indexes representing current population individuals. |
| 95 |
|
|
| 96 |
|
Crossover: |
| 97 |
|
Name: Binomial crossover |
| 98 |
|
|
| 99 |
|
:math:`\mathbf{x}_{i, G+1} = \begin{cases} \mathbf{u}_{i, G+1}, & \text{if $f(\mathbf{u}_{i, G+1}) \leq f(\mathbf{x}_{i, G})$}, \\ \mathbf{x}_{i, G}, & \text{otherwise}. \end{cases}` |
| 100 |
|
|
| 101 |
|
Args: |
| 102 |
|
pop (numpy.ndarray[Individual]): Current population. |
| 103 |
|
ic (int): Index of individual being mutated. |
| 104 |
|
x_b (Individual): Current global best individual. |
| 105 |
|
f (float): Scale factor. |
| 106 |
|
cr (float): Crossover probability. |
| 107 |
|
rnd (mtrand.RandomState): Random generator. |
| 108 |
|
*args (list): Additional arguments. |
| 109 |
|
|
| 110 |
|
Returns: |
| 111 |
|
numpy.ndarray: mutated and mixed individual. |
| 112 |
|
""" |
| 113 |
|
j = rnd.randint(len(pop[ic])) |
| 114 |
|
p = [1 / (len(pop) - 1.0) if i != ic else 0 for i in range(len(pop))] if len(pop) > 5 else None |
| 115 |
|
r = rnd.choice(len(pop), 5, replace=not len(pop) >= 5, p=p) |
| 116 |
|
x = [pop[r[0]][i] + f * (pop[r[1]][i] - pop[r[2]][i]) + f * (pop[r[3]][i] - pop[r[4]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 117 |
|
return asarray(x) |
| 118 |
|
|
| 119 |
|
def CrossBest2(pop, ic, x_b, f, cr, rnd=rand, *args): |
| 120 |
|
r"""Mutation strategy with crossover. |
|
@@ 151-181 (lines=31) @@
|
| 148 |
|
x = [x_b[i] + f * (pop[r[0]][i] - pop[r[1]][i]) + f * (pop[r[2]][i] - pop[r[3]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 149 |
|
return asarray(x) |
| 150 |
|
|
| 151 |
|
def CrossCurr2Rand1(pop, ic, x_b, f, cr, rnd=rand, *args): |
| 152 |
|
r"""Mutation strategy with crossover. |
| 153 |
|
|
| 154 |
|
Mutation: |
| 155 |
|
Name: de/curr2rand/1 |
| 156 |
|
|
| 157 |
|
:math:`\mathbf{v}_{i, G} = \mathbf{x}_{i, G} + F \cdot (\mathbf{x}_{r_1, G} - \mathbf{x}_{r_2, G}) + F \cdot (\mathbf{x}_{r_3, G} - \mathbf{x}_{r_4, G})` |
| 158 |
|
where :math:`r_1, r_2, r_3, r_4` are random indexes representing current population individuals |
| 159 |
|
|
| 160 |
|
Crossover: |
| 161 |
|
Name: Binomial crossover |
| 162 |
|
|
| 163 |
|
:math:`\mathbf{x}_{i, G+1} = \begin{cases} \mathbf{u}_{i, G+1}, & \text{if $f(\mathbf{u}_{i, G+1}) \leq f(\mathbf{x}_{i, G})$}, \\ \mathbf{x}_{i, G}, & \text{otherwise}. \end{cases}` |
| 164 |
|
|
| 165 |
|
Args: |
| 166 |
|
pop (numpy.ndarray[Individual]): Current population. |
| 167 |
|
ic (int): Index of individual being mutated. |
| 168 |
|
x_b (Individual): Current global best individual. |
| 169 |
|
f (float): Scale factor. |
| 170 |
|
cr (float): Crossover probability. |
| 171 |
|
rnd (mtrand.RandomState): Random generator. |
| 172 |
|
*args (list): Additional arguments. |
| 173 |
|
|
| 174 |
|
Returns: |
| 175 |
|
numpy.ndarray: mutated and mixed individual. |
| 176 |
|
""" |
| 177 |
|
j = rnd.randint(len(pop[ic])) |
| 178 |
|
p = [1 / (len(pop) - 1.0) if i != ic else 0 for i in range(len(pop))] if len(pop) > 4 else None |
| 179 |
|
r = rnd.choice(len(pop), 4, replace=not len(pop) >= 4, p=p) |
| 180 |
|
x = [pop[ic][i] + f * (pop[r[0]][i] - pop[r[1]][i]) + f * (pop[r[2]][i] - pop[r[3]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 181 |
|
return asarray(x) |
| 182 |
|
|
| 183 |
|
def CrossCurr2Best1(pop, ic, x_b, f, cr, rnd=rand, **kwargs): |
| 184 |
|
r"""Mutation strategy with crossover. |
|
@@ 119-149 (lines=31) @@
|
| 116 |
|
x = [pop[r[0]][i] + f * (pop[r[1]][i] - pop[r[2]][i]) + f * (pop[r[3]][i] - pop[r[4]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 117 |
|
return asarray(x) |
| 118 |
|
|
| 119 |
|
def CrossBest2(pop, ic, x_b, f, cr, rnd=rand, *args): |
| 120 |
|
r"""Mutation strategy with crossover. |
| 121 |
|
|
| 122 |
|
Mutation: |
| 123 |
|
Name: de/best/2 |
| 124 |
|
|
| 125 |
|
:math:`\mathbf{v}_{i, G} = \mathbf{x}_{best, G} + F \cdot (\mathbf{x}_{r_1, G} - \mathbf{x}_{r_2, G}) + F \cdot (\mathbf{x}_{r_3, G} - \mathbf{x}_{r_4, G})` |
| 126 |
|
where :math:`r_1, r_2, r_3, r_4` are random indexes representing current population individuals. |
| 127 |
|
|
| 128 |
|
Crossover: |
| 129 |
|
Name: Binomial crossover |
| 130 |
|
|
| 131 |
|
:math:`\mathbf{x}_{i, G+1} = \begin{cases} \mathbf{u}_{i, G+1}, & \text{if $f(\mathbf{u}_{i, G+1}) \leq f(\mathbf{x}_{i, G})$}, \\ \mathbf{x}_{i, G}, & \text{otherwise}. \end{cases}` |
| 132 |
|
|
| 133 |
|
Args: |
| 134 |
|
pop (numpy.ndarray[Individual]): Current population. |
| 135 |
|
ic (int): Index of individual being mutated. |
| 136 |
|
x_b (Individual): Current global best individual. |
| 137 |
|
f (float): Scale factor. |
| 138 |
|
cr (float): Crossover probability. |
| 139 |
|
rnd (mtrand.RandomState): Random generator. |
| 140 |
|
*args (list): Additional arguments. |
| 141 |
|
|
| 142 |
|
Returns: |
| 143 |
|
numpy.ndarray: mutated and mixed individual. |
| 144 |
|
""" |
| 145 |
|
j = rnd.randint(len(pop[ic])) |
| 146 |
|
p = [1 / (len(pop) - 1.0) if i != ic else 0 for i in range(len(pop))] if len(pop) > 4 else None |
| 147 |
|
r = rnd.choice(len(pop), 4, replace=not len(pop) >= 4, p=p) |
| 148 |
|
x = [x_b[i] + f * (pop[r[0]][i] - pop[r[1]][i]) + f * (pop[r[2]][i] - pop[r[3]][i]) if rnd.rand() < cr or i == j else pop[ic][i] for i in range(len(pop[ic]))] |
| 149 |
|
return asarray(x) |
| 150 |
|
|
| 151 |
|
def CrossCurr2Rand1(pop, ic, x_b, f, cr, rnd=rand, *args): |
| 152 |
|
r"""Mutation strategy with crossover. |