Exemplo n.º 1
0
def sample():
    X = np.array([[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
    y = np.array([[0], [1], [1], [0]])
    nn = NeuralNetwork(X, y)

    for i in range(1500):
        nn.feedforward()
        nn.backprop()

    print(nn.output)
Exemplo n.º 2
0
        error_count += error

    if error_count == 1:
        network.train(data, resp)
        generation += 1
        score = 0
        error_count = 0

    ball_pos = ball.position[0] - SCREEN_SIZE[0] / 2
    bar_pos = bar.position[0] - SCREEN_SIZE[0] / 2
    bar_pos += bar.size[0] / 2

    ball_pos = ball_pos / 100
    bar_pos = bar_pos / 100

    direction = network.feedforward(np.array([ball_pos, bar_pos]))
    direction = 1 if direction > 0.5 else 0
    '''
    df.loc[index] = [ball_pos, bar_pos, direction]
    index += 1
    '''

    bar.move(direction)

    text = font.render('Score: ' + str(score), 1, (255, 255, 255))
    text2 = font.render('Geração: ' + str(generation), 1, (255, 255, 255))

    screen.fill((0, 0, 0))

    screen.blit(text, (10, 10))
    screen.blit(text2, (10, 40))