Ejemplo n.º 1
0
def multilayer_perceptron():

    mlnn = MultiLayerNeuralNetwork( [2, 4, 1],
                                    threshold=0.5,
                                    learning_coefficient=0.5,
                                    sigmoid_alpha=5)

    x_range = [0,10]
    y_range = [0,10]
    # liner_data = TrainingData.liner_training_data(x_range, y_range)
    #liner_data = TrainingData.quadratic_function_data(x_range, y_range)
    liner_data = TrainingData.sin_function_data(x_range, y_range, 5)

    train_data = TrainingData.change_format(liner_data)

    # 教師データのプロット
    fig = plt.figure()
    scat(fig, [key for key, value in liner_data.items() if value == 0], color='g' )
    scat(fig, [key for key, value in liner_data.items() if value == 1], color='b' )

    # 学習
    sample_border = len(train_data)
    random.shuffle(train_data)
    #mlnn.train(train_data[:20])
    mlnn.train(train_data[:sample_border])

    # xに対応するyを算出
    data = get_predict_list(x_range,y_range, mlnn)

    # 学習後分離線
    plot(fig, data)

    plt.show()
Ejemplo n.º 2
0
    def test_sin_function_data(self):
        x_range = [0, int(math.pi * 2)]
        y_range = [0, 15]
        height  = 10
        liner_training_data = get_training_data.sin_function_data(x_range, y_range, height)

        self.assertEquals(liner_training_data[(0, 1)], 1)
        self.assertEquals(liner_training_data[(int(math.pi/2), 6)], 0)
        self.assertEquals(liner_training_data[(int(math.pi), 1)], 0)
        self.assertEquals(liner_training_data[(int(math.pi*3/2), 1)], 1)