Created
October 30, 2021 23:03
-
-
Save russelljjarvis/db8e5d9f28d7d78058390a3979b48c97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from deap import tools | |
def _get_offspring_time_diminishing_eta(parents, toolbox, cxpb, mutpb,gen, ngen): | |
'''return the offspring, use toolbox.variate if possible''' | |
BOUND_LOW = [] | |
BOUND_UP = [] | |
NDIM = len(parents[0]) | |
fit_dim = len(parents[0].fitness.values) | |
for x in range(0,len(parents[0])): | |
BOUND_LOW.append(toolbox.uniformparams.args[0][x]) | |
BOUND_UP.append(toolbox.uniformparams.args[1][x]) | |
ETA = int(30.0*(1-(gen/ngen))) | |
toolbox.register("mate", tools.cxSimulatedBinaryBounded, low=BOUND_LOW, up=BOUND_UP, eta=ETA) | |
toolbox.register("mutate", tools.mutPolynomialBounded, low=BOUND_LOW, up=BOUND_UP, eta=ETA, indpb=1.0/NDIM) | |
if (1-(gen/ngen))/2.0>0.05: | |
mutpb = (1-(gen/ngen))/2.0 | |
else: | |
mutpb = 0.05 | |
if (1-(gen/ngen))>0.4: | |
cxpb = (1-(gen/ngen))/1.1 | |
else: | |
cxpb = 0.4 | |
if hasattr(toolbox, 'variate'): | |
return toolbox.variate(parents, toolbox, cxpb, mutpb) | |
return deap.algorithms.varAnd(parents, toolbox, cxpb, mutpb) | |
def _get_offspring(parents, toolbox, cxpb, mutpb): | |
'''return the offspring, use toolbox.variate if possible''' | |
if hasattr(toolbox, 'variate'): | |
return toolbox.variate(parents, toolbox, cxpb, mutpb) | |
return deap.algorithms.varAnd(parents, toolbox, cxpb, mutpb) | |
def _check_stopping_criteria(criteria, params): | |
for c in criteria: | |
c.check(params) | |
if c.criteria_met: | |
logger.info("Run stopped because of stopping criteria: " + c.name) | |
return True | |
else: | |
return False | |
def filter_parents(parents): | |
""" | |
--synopsis: This method does not work yet. | |
#Remove the genes that represent the cliff | |
#edge. Possibly counter productive. | |
""" | |
import copy | |
parentsc = copy.copy(parents) | |
orig_len = len(parents) | |
cnt = 0 | |
for p in parentsc: | |
flag=False | |
for fv in p.fitness.values: | |
if fv == 1000.0: | |
flag=True | |
if flag: | |
cnt += 1 | |
while cnt > 0: | |
for i, p in enumerate(parentsc): | |
flag=False | |
for fv in p.fitness.values: | |
if fv == 1000.0: | |
flag=True | |
if flag: | |
del parentsc[i] | |
cnt -= 1 | |
cnt=0 | |
while len(parentsc) < orig_len: | |
parentsc.append(parentsc[cnt]) | |
cnt+=1 | |
return parentsc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment