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] for j in range(ANN.NODES_PER_LAYER): xmanJr.hh[i][j] = xman.hh[i][j] xmanJr.c2[i][j] = xman.c2[i][j] xmanJr.w[i] = xman.w[i] xmanJr.w2[i] = xman.w2[i] xmanJr.ho[i] = xman.ho[i] node = random.randint(0, ANN.NODES_PER_LAYER-1) if random.choice([True, False]): for i in range(19): xmanJr.ih[node][i] += getMutationValue(mutateValue) xmanJr.c[node][i] += getMutationValue(mutateValue) xmanJr.w[node] += getMutationValue(mutateValue) for i in range(ANN.NODES_PER_LAYER): xmanJr.hh[i][node] += getMutationValue(mutateValue) else: for i in range(ANN.NODES_PER_LAYER): xmanJr.hh[i][node] += getMutationValue(mutateValue) xmanJr.c2[i][node] += getMutationValue(mutateValue) xmanJr.w2[node] += getMutationValue(mutateValue) xmanJr.ho[node] += getMutationValue(mutateValue) return xmanJr
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() for n in range(ANN.NODES_PER_LAYER): nextMember.hh[j][n] = getInitialFloat() nextMember.c2[j][n] = getInitialFloat() nextMember.w[j] = getInitialFloat() nextMember.w2[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] for j in range(ANN.NODES_PER_LAYER): child.hh[i][j] = parentList[random.randint(0,1)].hh[i][j] child.c2[i][j] = parentList[random.randint(0,1)].c2[i][j] child.w[i] = parentList[random.randint(0,1)].w[i] child.w2[i] = parentList[random.randint(0,1)].w2[i] child.ho[i] = parentList[random.randint(0,1)].ho[i] return child
def main(annfile): randSample = random.Random(input.SAMPLE_SEED) inp = input.Input("train3-std.tsv", randSample) print "Test set:", inp.testSet.show() param = Parameters.from_file(annfile) tester = SampleTester() tester.prepare(inp.testSet, randSample) tester.showSampleSets() avg, std = tester.test(param) print "Lift:", "avg: %.03f" % avg, "std: %.03f" % std