in syne_tune/optimizer/schedulers/searchers/bore/de.py [0:0]
def evolve(self, j):
best_idv = self.de_pop[self.idxbest]
current_idv = self.de_pop[j]
# perform mutation operation
if self.strategy == "rand1":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2, r3 = self.de_pop[np.random.choice(idxs, 3, replace=False)]
# Step 3.1: Perform mutation and checking
temp = r1 + self.mut * (r2 - r3)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
if self.strategy == "best1":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2 = self.de_pop[np.random.choice(idxs, 2, replace=False)]
temp = best_idv + self.mut * (r1 - r2)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
if self.strategy == "rand2":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2, r3, r4, r5 = self.de_pop[np.random.choice(idxs, 5, replace=False)]
temp = r1 + self.mut * (r1 - r2) + self.mut * (r3 - r4)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
if self.strategy == "best2":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2, r3, r4 = self.de_pop[np.random.choice(idxs, 4, replace=False)]
temp = best_idv + self.mut * (r1 - r2) + self.mut * (r3 - r4)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
if self.strategy == "currenttobest1":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2 = self.de_pop[np.random.choice(idxs, 2, replace=False)]
temp = current_idv + self.mut * (best_idv - current_idv) + self.mut * (r1 - r2)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
if self.strategy == "randtobest1":
idxs = [idx for idx in range(self.popsize) if idx != j]
r1, r2, r3 = self.de_pop[np.random.choice(idxs, 3, replace=False)]
temp = r1 + self.mut * (best_idv - r1) + self.mut * (r2 - r3)
vi = np.clip(temp, self.lower_bound, self.upper_bound)
# perform crossover operation
if self.bin == 1:
cross_points = np.random.rand(self.dimensions) < self.crossp
if not np.any(cross_points):
cross_points[np.random.randint(0, self.dimensions)] = True
ui = np.where(cross_points, vi, current_idv)
else:
i = 0
ui = []
fill_point = np.random.randint(0, self.dimensions)
while (i < self.dimensions and
np.random.rand(0, 1) < self.crossp):
ui[fill_point] = vi[fill_point]
fill_point = (fill_point + 1) % self.dimensions
i += 1
return ui