Пример #1
0
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]])
Пример #2
0
import torch
from torch.autograd import Variable
from multiprocessing import Pool
from random import randint
from mutate import Mutate
from nueral import Network
from cardata import createCarDataList
import logging


logging.basicConfig(filename='data.log',level=logging.INFO)
car_data_list=createCarDataList()
print("Complete")


networks=Network.read_networks()
def sort(networks):
    for i in range(0,len(networks)):
        temp_i=networks[i]
        for j in range(i+1,len(networks)):
            temp_j=networks[j]
            if(temp_i.error.data[0]>temp_j.error.data[0]):
                temp=temp_i
                networks[i]=networks[j]
                networks[j]=temp
    networks2=[]
    for i in range(0,10):
        networks2.append(networks[i])
    return networks2