Exemplo n.º 1
0
    #np.random.shuffle(x)
    #np.random.shuffle(y)

    x = x[perm]
    y = y[perm]

    val_x = x[-100:]
    val_y = y[-100:]

    in_x = x[:-200]
    in_y = y[:-200]

    cross_val_x = x[-200:-100]
    cross_val_y = y[-200:-100]

    print('population_count: ' + str(population_count))
    print('population_size: ' + str(population_size))
    print('node_cap: ' + str(node_cap))
    print('generations: ' + str(generations))
    print('target_accuracy: {}%'.format(target_accuracy * 100))
    print('random_seed: ' + str(r))

    best_network = evm.evolve_node_count(in_x, in_y, val_x, val_y,
                                         utils.jit_round_compare,
                                         population_count, population_size,
                                         node_cap, generations,
                                         target_accuracy, r)
    print(
        best_network.validate(cross_val_x, cross_val_y,
                              utils.jit_round_compare))
    utils.display_network(best_network, "wisconsin-breast-cancer")
Exemplo n.º 2
0
    x = np.array([[1, 0] if rand < 0.25 else
                  [0, 1] if rand < 0.5 else [1, 1] if rand < 0.75 else [0, 0]
                  for rand in np.random.random(60000)],
                 dtype=int)
    y = np.array([[
        1,
    ] if np.sum(itm) == 1 else [
        0,
    ] for itm in x],
                 dtype=int)

    # Grab input from the user and print it to stdout
    population_count = int(input('population_count: '))
    print('{}'.format(population_count))
    population_size = int(input('poplation_size: '))
    print('{}'.format(population_size))
    node_cap = int(input('node_cap: '))
    print('{}'.format(node_cap))
    generations = int(input('generations: '))
    print('{}'.format(generations))
    target_accuracy = float(input('target_accuracy: '))
    print('{}%'.format(target_accuracy * 100))
    r = int(input("random_seed: "))
    print(str(r))

    for i in range(50):
        best_xor = evm.evolve_node_count(x, y, x, y, utils.jit_round_compare,
                                         population_count, population_size,
                                         node_cap, generations,
                                         target_accuracy, i * r + r)
Exemplo n.º 3
0
    print(population_size)
    node_cap = int(input('node_cap: '))
    print(node_cap)
    generations = int(input('generations: '))
    print(generations)
    target_accuracy = float(input('target_accuracy: '))
    print('{}%'.format(target_accuracy*100))
    r = float(input('random_number: '))
    print(r)
    
    x = (np.random.random(50000)*2*np.math.pi).reshape(50000, 1)
    y = (np.sin(x)+1).reshape(50000, 1)
    val_x = (np.random.random(1000)*2*np.math.pi).reshape(1000, 1)
    val_y = (np.sin(val_x)+1).reshape(1000, 1)

    network = evolutionary_module.evolve_node_count(x, y, val_x, val_y, utils.jit_near_compare, population_count, population_size, node_cap, generations, target_accuracy, r)

# with utils.OutSplit('cos-50k'.format(d= datetime.datetime.now())):
    
#     print('population_count: ' + str(population_count))
#     print('population_size: ' + str(population_size))
#     print('node_cap: ' + str(node_cap))
#     print('generations: ' + str(generations))
#     print('target_accuracy: {}%'.format(target_accuracy*100))
#     print('random_number: ' + str(r))
    
#     x = (np.random.random(50000)*2*np.math.pi).reshape(50000, 1)
#     y = (np.cos(x)+1).reshape(50000, 1)
#     val_x = (np.random.random(1000)*2*np.math.pi).reshape(1000, 1)
#     val_y = (np.cos(val_x)+1).reshape(1000, 1)
Exemplo n.º 4
0
    # Grab input from the user and print it to stdout
    population_count = int(input('population_count: '))
    print('{}'.format(population_count))
    population_size = int(input('poplation_size: '))
    print('{}'.format(population_size))
    node_cap = int(input('node_cap: '))
    print('{}'.format(node_cap))
    generations = int(input('generations: '))
    print('{}'.format(generations))
    target_accuracy = float(input('target_accuracy: '))
    print('{}%'.format(target_accuracy*100))
    r = int(input("random_seed: "))
    print(str(r))

    for i in range(50):
        best = evm.evolve_node_count(x, y, val_x, val_y, utils.jit_near_compare, population_count, population_size, node_cap, generations, target_accuracy, i*r+r)

with utils.OutSplit('nultiple_cos'.format(d= datetime.datetime.now())):
    
    print('population_count: ' + str(population_count))
    print('population_size: ' + str(population_size))
    print('node_cap: ' + str(node_cap))
    print('generations: ' + str(generations))
    print('target_accuracy: {}%'.format(target_accuracy*100))
    print('random_number: ' + str(r))
    
    x = (np.random.random(50000)*2*np.math.pi).reshape(50000, 1)
    y = (np.cos(x)+1).reshape(50000, 1)
    val_x = (np.random.random(1000)*2*np.math.pi).reshape(1000, 1)
    val_y = (np.cos(val_x)+1).reshape(1000, 1)
Exemplo n.º 5
0
train_labels = utils.jit_to_categorical(
    mnist_io.labels_from_file(
        os.path.join(dataset,
                     "train-labels-idx1-ubyte\\train-labels.idx1-ubyte"),
        60000), 10)

test_images = mnist_io.images_from_file(
    os.path.join(dataset, "t10k-images-idx3-ubyte\\t10k-images.idx3-ubyte"),
    10000)
test_images = test_images.reshape(10000, 784).astype('float32')
test_images /= 255

test_labels = utils.jit_to_categorical(
    mnist_io.labels_from_file(
        os.path.join(dataset, "t10k-labels-idx1-ubyte/t10k-labels.idx1-ubyte"),
        10000), 10)

with utils.OutSplit('mnist_evolution'):
    evolved_network = evolve_node_count(train_images,
                                        train_labels,
                                        test_images,
                                        test_labels,
                                        utils.jit_categorical_compare,
                                        population_count=10,
                                        population_size=15,
                                        node_cap=1500,
                                        generations=50,
                                        target_accuracy=0.95,
                                        r=4)
    print(evolved_network.connections, "\n", evolved_network.weights, "\n",
          evolved_network.learning_rate)