This commit is contained in:
Glenn Jocher 2020-01-22 11:08:03 -08:00
parent f18913736b
commit 3de61b1fa5
1 changed files with 2 additions and 2 deletions

View File

@ -452,9 +452,9 @@ if __name__ == '__main__':
x = x[np.argsort(-fitness(x))][:n] # top n mutations x = x[np.argsort(-fitness(x))][:n] # top n mutations
if parent == 'single' or len(x) == 1: if parent == 'single' or len(x) == 1:
x = x[random.randint(0, n - 1)] # select one of the top n x = x[random.randint(0, n - 1)] # select one of the top n
elif parent == 'weighted': # weighted combination elif parent == 'weighted':
w = fitness(x) - fitness(x).min() # weights w = fitness(x) - fitness(x).min() # weights
x = (x * w.reshape(n, 1)).sum(0) / w.sum() # new parent x = (x * w.reshape(n, 1)).sum(0) / w.sum() # select weighted combination
# Mutate # Mutate
method = 3 method = 3