def test_multilayer_perceptron_predict(self): mlnn = MultiLayerNeuralNetwork([2, 1], threshold=1.0, learning_coefficient=1.0, sigmoid_alpha=1.0, print_error=False) mlnn.weights = {1: np.array([[-1, 1, 1]])} assert mlnn.predict([0, 0]) == [1 / (1 + math.e ** 1)] assert mlnn.predict([0, 1]) == [0.5] assert mlnn.predict([1, 0]) == [0.5] assert mlnn.predict([1, 1]) == [1 / (1 + math.e ** -1)] assert mlnn.predict_all_layer([0, 0]) == [[0, 0],[1 / (1 + math.e ** 1)]] assert mlnn.predict_all_layer([0, 1]) == [[0, 1],[0.5]] assert mlnn.predict_all_layer([1, 0]) == [[1, 0],[0.5]] assert mlnn.predict_all_layer([1, 1]) == [[1, 1],[1 / (1 + math.e ** -1)]] # assert mlnn.predict([0, 0], 1) == [1 / (1 + math.e ** 1)] # assert mlnn.predict([0, 1], 1) == [0.5] # assert mlnn.predict([1, 0], 1) == [0.5] # assert mlnn.predict([1, 1], 1) == [1 / (1 + math.e ** -1)] # assert mlnn.predict([0, 0], 0) == [0, 0] # assert mlnn.predict([0, 1], 0) == [0, 1] # assert mlnn.predict([1, 0], 0) == [1, 0] # assert mlnn.predict([1, 1], 0) == [1, 1] # XORが計算できることを重み指定して確認したい. mlnn.weights = {1: np.array([[-0.5, 1, -1], [-0.5, -1, 1]]) , 2: np.array([[-0.5, 1, 1],])}