Skip to content

Commit ac87d79

Browse files
committed
Merge remote-tracking branch 'origin/custom_diff_evo' into constrained_optimization_tunable
2 parents 7be2d86 + 19d5127 commit ac87d79

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kernel_tuner/strategies/diff_evo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def mutate_de_2(best_idx, randos_idx, F, min_idx, max_idx, best):
337337
def binomial_crossover(donor_vector, target, CR):
338338
"""Performs binomial crossover of donor_vector with target given crossover rate CR."""
339339
# Create the trial vector by mixing parameters from the target and donor vectors
340-
trial_vector = np.copy(target)
340+
trial_vector = target.copy()
341341
dimensions = len(donor_vector)
342342

343343
# Generate a random array of floats for comparison with the crossover rate CR
@@ -349,9 +349,11 @@ def binomial_crossover(donor_vector, target, CR):
349349
crossover_points[np.random.randint(0, dimensions)] = True
350350

351351
# Apply crossover
352-
trial_vector[crossover_points] = np.array(donor_vector)[crossover_points]
352+
for i, d in enumerate(donor_vector):
353+
if crossover_points[i]:
354+
trial_vector[i] = donor_vector[i]
353355

354-
return list(trial_vector)
356+
return trial_vector
355357

356358

357359
def exponential_crossover(donor_vector, target, CR):
@@ -362,7 +364,7 @@ def exponential_crossover(donor_vector, target, CR):
362364
from the donor vector and the rest from the target vector.
363365
"""
364366
dimensions = len(target)
365-
trial_idx = np.copy(target)
367+
trial_vector = target.copy()
366368

367369
# 1. Select a random starting point for the crossover block.
368370
start_point = np.random.randint(0, dimensions)
@@ -373,10 +375,10 @@ def exponential_crossover(donor_vector, target, CR):
373375
l = 0
374376
while np.random.rand() < CR and l < dimensions:
375377
crossover_point = (start_point + l) % dimensions
376-
trial_idx[crossover_point] = np.array(donor_vector)[crossover_point]
378+
trial_vector[crossover_point] = donor_vector[crossover_point]
377379
l += 1
378380

379-
return list(trial_idx)
381+
return trial_vector
380382

381383

382384
def repair(trial_vector, searchspace):

0 commit comments

Comments
 (0)