示例#1
0
文件: main.py 项目: kokukuma/EoNN
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()
示例#2
0
文件: main.py 项目: kokukuma/EoNN
def simple_perceptron():
    # simple perceptron
    sp = SimplePerceptron(  input_neuron_num     = 2,
                            output_neuron_num    = 1,
                            threshold            = 1.0,
                            learning_coefficient = 0.5,
                            output_function_type = 1)

    # train data
    x_range = [0,30]
    y_range = [0,30]
    liner_data = TrainingData.liner_training_data(x_range, y_range)
    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' )


    # 学習前分離線
    data = get_predict_list(x_range,y_range, sp)
    plot(fig, data)

    # 学習
    sample_border = len(train_data) / 3
    random.shuffle(train_data)

    for i in range(100):
        sp.train(train_data[:sample_border])

    # 学習後分離線
    data = get_predict_list(x_range,y_range, sp)
    plot(fig, data)

    plt.show()
示例#3
0
 def test_change_format(self):
     x_range = [0, 1]
     y_range = [0, 1]
     liner_data = get_training_data.liner_training_data(x_range,y_range)
     train_data = get_training_data.change_format(liner_data)
     self.assertEquals(train_data, [[[0,1],[1]], [[1,0],[1]], [[0,0],[1]], [[1,1],[1]]])