From 9bb51aaf8ca585b90c3f877972a39eb1e0f3821f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 22 Jan 2020 18:17:08 -0800 Subject: [PATCH] updates --- train.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index be92c514..ae4b3515 100644 --- a/train.py +++ b/train.py @@ -448,13 +448,14 @@ if __name__ == '__main__': # Select parent(s) parent = 'single' # parent selection method: 'single' or 'weighted' x = np.loadtxt('evolve.txt', ndmin=2) - n = min(5, len(x)) # number of previous results to consider + n = min(8, len(x)) # number of previous results to consider x = x[np.argsort(-fitness(x))][:n] # top n mutations + w = fitness(x) - fitness(x).min() # weights 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)] # random selection + x = x[random.choices(range(n), weights=w)[0]] # weighted selection elif parent == 'weighted': - w = fitness(x) - fitness(x).min() # weights - x = (x * w.reshape(n, 1)).sum(0) / w.sum() # select weighted combination + x = (x * w.reshape(n, 1)).sum(0) / w.sum() # weighted combination # Mutate method = 3