def generatePop(generation): for i in range(POPSIZE): nextMember = Parameters() for j in range(ANN.NODES_PER_LAYER): for k in range(19): nextMember.ih[j][k] = getInitialFloat() nextMember.c[j][k] = getInitialFloat() nextMember.w[j] = getInitialFloat() nextMember.ho[j] = getInitialFloat() generation.append(nextMember)
def mate(parent1, parent2): parentList = [parent1, parent2] child = Parameters() for i in range(ANN.NODES_PER_LAYER): for j in range(19): child.ih[i][j] = parentList[random.randint(0,1)].ih[i][j] child.c[i][j] = parentList[random.randint(0,1)].c[i][j] child.w[i] = parentList[random.randint(0,1)].w[i] child.ho[i] = parentList[random.randint(0,1)].ho[i] return child
def mutate(xman, mutateValue): xmanJr = Parameters() for i in range(ANN.NODES_PER_LAYER): for j in range(19): xmanJr.ih[i][j] = xman.ih[i][j] xmanJr.c[i][j] = xman.c[i][j] xmanJr.w[i] = xman.w[i] xmanJr.ho[i] = xman.ho[i] node = random.randint(0,ANN.NODES_PER_LAYER-1) for i in range(19): xmanJr.ih[node][i] += getMutationValue(mutateValue) xmanJr.c[node][i] += getMutationValue(mutateValue) xmanJr.w[node] += getMutationValue(mutateValue) xmanJr.ho[node] += getMutationValue(mutateValue) return xmanJr