Skip to content

DNA_SIZE > 1 error. #23

@gcl916

Description

@gcl916

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions