Skip to content

Commit

Permalink
Merge pull request EpistasisLab#363 from weixuanfu2016/varor_bug_fix
Browse files Browse the repository at this point in the history
Fix a bug in varOR
  • Loading branch information
rhiever authored Mar 8, 2017
2 parents 3491dd0 + b3e611b commit 4f700c5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tpot/gp_deap.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ def varOr(population, toolbox, lambda_, cxpb, mutpb):
op_choice = np.random.random()
if op_choice < cxpb: # Apply crossover
idxs = np.random.randint(0, len(population),size=2)
ind1, ind2 = population[idxs[0]],population[idxs[1]]
ind1, ind2 = toolbox.clone(population[idxs[0]]), toolbox.clone(population[idxs[1]])
ind_str = str(ind1)
ind1, ind2 = toolbox.mate(ind1, ind2)
if ind_str != str(ind1): # check if crossover generated a new pipeline
del ind1.fitness.values
offspring.append(ind1)
elif op_choice < cxpb + mutpb: # Apply mutation
idx = np.random.randint(0, len(population))
ind = population[idx]
ind = toolbox.clone(population[idx])
ind_str = str(ind)
ind, = toolbox.mutate(ind)
if ind_str != str(ind): # check if mutation happend
del ind.fitness.values
offspring.append(ind)
else: # Apply reproduction
idx = np.random.randint(0, len(population))
offspring.append(population[idx])
offspring.append(toolbox.clone(population[idx]))

return offspring

Expand Down Expand Up @@ -151,7 +151,7 @@ def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen, pbar,
pbar.update(len(offspring)-len(invalid_ind))
if not (max_time_mins is None) and pbar.n >= pbar.total:
pbar.total += lambda_

fitnesses = toolbox.evaluate(invalid_ind)
for ind, fit in zip(invalid_ind, fitnesses):
ind.fitness.values = fit
Expand Down

0 comments on commit 4f700c5

Please sign in to comment.