예제 #1
0
def evaluation_function(individual):
    # start_time = time.time()
    weights = individual[0:p.NEEDED_WEIGHTS]
    biases = individual[p.NEEDED_WEIGHTS:(p.NEEDED_WEIGHTS + p.NEEDED_BIASES)]
    splitted_weights = new_ann.convert_weights_to_arrays(p.LAYER_SIZES, weights)
    splitted_biases = new_ann.convert_biases_to_arrays(p.LAYER_SIZES, biases)
    # ann = new_ann.neuralnetwork(splitted_weights, splitted_biases, LAYER_SIZES, activation=[nnet.sigmoid, nnet.sigmoid, nnet.sigmoid, nnet.sigmoid])
    ann = new_ann.neuralnetwork(splitted_weights, splitted_biases, p.LAYER_SIZES,
                                activation=[new_ann.relu, new_ann.relu, new_ann.relu, new_ann.relu])
    reg_ai_player = Player_fast(None, random_start=p.RANDOM_START)
    ann_player = ANN_Player(None, ann)
    game = GomokuGame.playToTheEnd(reg_ai_player, ann_player)

    fit = len(game.moves)
    if game.winner == ann_player.color:
        fit += 10000.0
    elif game.winner == game.DRAW:
        fit += 5000.0
    # print("Moves:", len(game.moves))
    return len(game.moves),
예제 #2
0
#
# ann = LeNetConvPoolLayer(rng, input1d, filter_shape=(2, 3, 5, 5), image_shape=(4,3,20,20), poolsize=(2,2))
#
# print(ann.output)

import numpy as np
from ann import new_ann

layer_sizes = [5, 10, 1]
print("Weights needed", new_ann.get_weights_needed(layer_sizes))
print("Biases needed", new_ann.get_biases_needed(layer_sizes))


test_weights = [0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3,
                0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3,
                0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3]
test_biases = [0.1, 0.3, 0.4, 0.1, 0.2, 0.1, 0.3, 0.4, 0.1, 0.2, 0.1]

actual_weights = [np.array([[0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3], [0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3],
              [0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3], [0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3],
              [0.1, 0.3, 0.4, 0.1, 0.3, 0.1, 0.3, 0.4, 0.1, 0.3]]),
    np.array([[0.1], [0.3], [0.4], [0.1], [0.3], [0.1], [0.3], [0.4], [0.1], [0.3]])]  # in --> [out]
actual_biases = [np.array([0.1, 0.3, 0.4, 0.1, 0.2, 0.1, 0.3, 0.4, 0.1, 0.2]), np.array([0.1])]  # out


splitted_weights = new_ann.convert_weights_to_arrays(layer_sizes, test_weights)
splitted_biases = new_ann.convert_biases_to_arrays(layer_sizes, test_biases)
ann = new_ann.neuralnetwork(splitted_weights, splitted_biases, layer_sizes=layer_sizes)
input_arr = np.array([1, 0, 0, 0, 1])
print(ann.get_ann_prediction(input_arr))