This commit is contained in:
Glenn Jocher 2020-01-22 11:06:52 -08:00
parent c7bf7f3d60
commit f18913736b
1 changed files with 4 additions and 4 deletions

View File

@ -446,13 +446,13 @@ if __name__ == '__main__':
for _ in range(1): # generations to evolve
if os.path.exists('evolve.txt'): # if evolve.txt exists: select best hyps and mutate
# Select parent(s)
x = np.loadtxt('evolve.txt', ndmin=2)
parent = 'single' # parent selection method: 'single' or 'weighted'
if parent == 'single' or len(x) == 1:
x = x[fitness(x).argmax()]
elif parent == 'weighted': # weighted combination
n = min(10, len(x)) # number to merge
x = np.loadtxt('evolve.txt', ndmin=2)
n = min(3, len(x)) # number of previous results to consider
x = x[np.argsort(-fitness(x))][:n] # top n mutations
if parent == 'single' or len(x) == 1:
x = x[random.randint(0, n - 1)] # select one of the top n
elif parent == 'weighted': # weighted combination
w = fitness(x) - fitness(x).min() # weights
x = (x * w.reshape(n, 1)).sum(0) / w.sum() # new parent