def do_cross_over(network1, network2): network_n1 = Network() network_n2 = Network() network_n1.create_weights(False) network_n2.create_weights(False) split = randint(0, 21) for i in range(0, split): network_n1.dictLayers[0].data[0, i] = network1.dictLayers[0].data[0, i] network_n2.dictLayers[0].data[0, i] = network2.dictLayers[0].data[0, i] for i in range(split, 22): network_n1.dictLayers[0].data[0, i] = network2.dictLayers[0].data[0, i] network_n2.dictLayers[0].data[0, i] = network1.dictLayers[0].data[0, i] split = randint(0, 19) for j in range(0, 62): for i in range(0, split): network_n1.dictLayers[1].data[ j, i] = network1.dictLayers[1].data[j, i] network_n2.dictLayers[1].data[ j, i] = network2.dictLayers[1].data[j, i] for i in range(split, 19): network_n1.dictLayers[1].data[ j, i] = network2.dictLayers[1].data[j, i] network_n2.dictLayers[1].data[ j, i] = network1.dictLayers[1].data[j, i] split = randint(0, 2) for j in range(0, 19): for i in range(0, split): network_n1.dictLayers[2].data[ j, i] = network1.dictLayers[2].data[j, i] network_n2.dictLayers[2].data[ j, i] = network2.dictLayers[2].data[j, i] for i in range(split, 3): network_n1.dictLayers[2].data[ j, i] = network2.dictLayers[2].data[j, i] network_n2.dictLayers[2].data[ j, i] = network1.dictLayers[2].data[j, i] return network_n1, network_n2
def activate_networks(): p = [1, 0, 1, 6] networks = [] new_networks = [] for i in range(1, 7): network = Network.read_networks(i)[0] networks.append(network) for i in range(0, 6): temp_i_network = networks[i] for j in range(i, 6): temp_j_network = networks[j] if (temp_i_network.error.data[0] > temp_j_network.error.data[0]): temp_network = networks[i] networks[i] = networks[j] networks[j] = temp_network for i in range(0, 3): network = Network(p) network.create_weights() network_1 = Network(p) network_1.create_weights() parent1_index = randint(0, 4) parent2_index = randint(0, 4) w1 = networks[parent1_index].dict_layers[0] w2 = networks[parent2_index].dict_layers[0] w_new, w_new_1 = create_new_weight(w1, w2) network.dict_layers[0] = w_new network_1.dict_layers[0] = w_new_1 w1 = networks[parent1_index].dict_layers[1] w2 = networks[parent2_index].dict_layers[1] w_new, w_new_1 = create_new_weight(w1, w2) network.dict_layers[1] = w_new network_1.dict_layers[1] = w_new_1 new_networks.append(network) new_networks.append(network_1) print(len(new_networks)) with Pool(6) as p: p.map( worker, [[new_networks[0], 1], [new_networks[1], 2], [new_networks[2], 3], [new_networks[3], 4], [new_networks[4], 5], [new_networks[5], 6]])