-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPM_mutation.py
27 lines (22 loc) · 1.07 KB
/
PM_mutation.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
import numpy as np
def pm_mutation(pop_dec, boundary):
pro_m = 1
dis_m = 20
pop_dec = pop_dec[:(len(pop_dec)//2)*2, :]
n, d = np.shape(pop_dec)
site = np.random.random((n, d)) < pro_m / d
mu = np.random.random((n, d))
temp = site & (mu <= 0.5)
lower, upper = np.tile(boundary[0], (n, 1)), np.tile(boundary[1], (n, 1))
norm = (pop_dec[temp] - lower[temp]) / (upper[temp] - lower[temp])
pop_dec[temp] += (upper[temp] - lower[temp]) * \
(np.power(2. * mu[temp] + (1. - 2. * mu[temp]) * np.power(1. - norm, dis_m + 1.),
1. / (dis_m + 1)) - 1.)
temp = site & (mu > 0.5)
norm = (upper[temp] - pop_dec[temp]) / (upper[temp] - lower[temp])
pop_dec[temp] += (upper[temp] - lower[temp]) * \
(1. - np.power(
2. * (1. - mu[temp]) + 2. * (mu[temp] - 0.5) * np.power(1. - norm, dis_m + 1.),
1. / (dis_m + 1.)))
offspring_dec = np.maximum(np.minimum(pop_dec, upper), lower)
return offspring_dec