Evolutionary-Algorithm icon indicating copy to clipboard operation
Evolutionary-Algorithm copied to clipboard

DNA_SIZE > 1 error.

Open gcl916 opened this issue 3 years ago • 0 comments

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

gcl916 avatar Oct 29 '22 13:10 gcl916