Exemplo n.º 1
0
network.print_data()
folds = 4
result = [0]
i = 0
start_time = time()
while sum(result) / folds < 90:
    results = network.learn_kfolds(folds, times=1)
    scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
    stuff = Counter(scores)
    result = [stuff[(i, True)] / (stuff[(i, False)] + stuff[(i, True)]) * 100 for i in range(folds)]
    print("folds results: ", result)
    i += 1
    if i % 10 == 0:
        print("saving dump")
        network.dump_network('snek-play-7-new1.yaml')
        new_learning_rate = uniform(0.0, 1.0)
        for layer in network.layers:
            for neuron in layer.neurons:
                neuron.learning_factor = new_learning_rate
    print("learning for: %s" % (time() - start_time))

end_time = time()
print("learning time: %s" % (end_time - start_time))

try:
    network.dump_cypher('snek2.cypher')
except:
    pass

network.dump_network('snek-play-awesome.yaml')
Exemplo n.º 2
0
    {"inputs": [0, 0], "outputs": [0]},
    {"inputs": [0, 1], "outputs": [1]},
    {"inputs": [1, 1], "outputs": [0]},
    {"inputs": [1, 0], "outputs": [1]}
]

network.load_learning_data(learning_data)
network.normalize_learning_data()
print("------- learn -------")
network.print_data()

network.learn(times=10000)


i = [[0, 0], [0, 1], [1, 1], [1, 0]]
o = [network.test(io) for io in i]


print("------- test -------")
network.print_io(i, o)

print("------ weights -----")
network.print_weights()

bias = BiasNeuron(0.1)
bias.set_network_name(net_name)
middle.neurons[0].connect(bias, 'right')

network.dump_network('../data/trained_networks/xor-dump2.yaml', prompt=True)

network.dump_cypher('../data/cypher/xor.cypher', additional_neurons=[bias])
Exemplo n.º 3
0
        })

inputs = InputLayer([1, 1, 1, 1])
middle = Layer(5)
middle2 = Layer(3)
output = OutputLayer([1, 1, 1])

network = Network([inputs, middle, middle2, output], 'iris')
network.connect()

network.load_learning_data(learning_data)
network.normalize_learning_data()
print("------- learn -------")
network.print_data()

folds = 4
results = network.learn_kfolds(folds, times=1000)
scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
stuff = Counter(scores)
print("folds results: ", [stuff[(i, True)] / (stuff[(i, False)] + stuff[(i, True)]) * 100 for i in range(folds)])

i = [
    [6.9, 3.1, 5.1, 2.3],  # Iris-virginica
    [5.0, 2.0, 3.5, 1.0],  # Iris-versicolor
    [5.4, 3.7, 1.5, 0.2]   # Iris-setosa
]
o = [network.test(io) for io in i]
network.print_io(i, o, output_names=['Iris-virginica', 'Iris-versicolor', 'Iris-setosa'])

network.dump_network('../data/trained_networks/iris.yaml', prompt=True)
network.dump_cypher('../data/cypher/iris.cypher')
Exemplo n.º 4
0
network.connect()

network.load_learning_data(learning_data)
#network.normalize_learning_data()
print("------- learn -------")
network.print_data()

#network.learn(times=100)
results = network.learn_kfolds(4, times=100)
scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
stuff = Counter(scores)
print([
    stuff[(i, True)] / (stuff[(i, False)] + stuff[(i, True)]) * 100
    for i in range(4)
])

i = [
    [tic_tac_map[x]
     for x in ['x', 'x', 'x', 'o', 'b', 'x', 'b', 'o', 'o']],  # positive
    [tic_tac_map[x]
     for x in ['x', 'o', 'o', 'x', 'x', 'o', 'b', 'x', 'o']]  # negative
]
o = [network.test(io) for io in i]

network.print_io(i, o, output_names=['positive/negative'])

print("------ weights -----")
network.print_weights()

network.dump_network('data/trained_networks/tictactoe.yaml', prompt=True)