This commit is contained in:
Glenn Jocher 2019-09-20 20:31:37 +02:00
parent eeb4cbc5c1
commit db49211d70
1 changed files with 8 additions and 9 deletions

View File

@ -429,15 +429,14 @@ if __name__ == '__main__':
if os.path.exists('evolve.txt'): # if evolve.txt exists: select best hyps and mutate if os.path.exists('evolve.txt'): # if evolve.txt exists: select best hyps and mutate
# Select parent(s) # Select parent(s)
x = np.loadtxt('evolve.txt', ndmin=2) x = np.loadtxt('evolve.txt', ndmin=2)
if len(x) > 1: parent = 'weighted' # parent selection method: 'single' or 'weighted'
parent = 'weighted' # parent selection method: 'single' or 'weighted' if parent == 'single' or len(x) == 1:
if parent == 'single': x = x[fitness(x).argmax()]
x = x[fitness(x).argmax()] elif parent == 'weighted': # weighted combination
elif parent == 'weighted': # weighted combination n = min(10, x.shape[0]) # number to merge
n = min(10, x.shape[0]) # number to merge x = x[np.argsort(-fitness(x))][:n] # top n mutations
x = x[np.argsort(-fitness(x))][:n] # top n mutations w = fitness(x) - fitness(x).min() # weights
w = fitness(x) - fitness(x).min() # weights x = (x[:n] * w.reshape(n, 1)).sum(0) / w.sum() # new parent
x = (x[:n] * w.reshape(n, 1)).sum(0) / w.sum() # new parent
for i, k in enumerate(hyp.keys()): for i, k in enumerate(hyp.keys()):
hyp[k] = x[i + 7] hyp[k] = x[i + 7]