Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNA_SIZE > 1 error. #23

Open
gcl916 opened this issue Oct 29, 2022 · 0 comments
Open

DNA_SIZE > 1 error. #23

gcl916 opened this issue Oct 29, 2022 · 0 comments

Comments

@gcl916
Copy link

gcl916 commented Oct 29, 2022

when DNA_SIZE > 1, index out of boundary at
good_idx = idx[fitness.argsort()][-POP_SIZE:]

so, suggestion is :
def kill_bad(pop, kids):
# put pop and kids together
for key in ['DNA', 'mut_strength']:
pop[key] = np.vstack((pop[key], kids[key]))

fitness = get_fitness(F(pop['DNA']))            # calculate global fitness
w,h = pop['DNA'].shape
idx = np.arange(w*h)    
good_idx = idx[fitness.argsort()][-POP_SIZE*DNA_SIZE:]   # selected by fitness ranking (not value)
for key in ['DNA', 'mut_strength']:
    pop[key] = pop[key].flatten()
    pop[key] = pop[key][good_idx]
    pop[key] = pop[key].reshape((POP_SIZE,DNA_SIZE))
return pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant