【问题标题】:How to find Perceptron : weight1, weight2, and bias mathematically如何找到感知器:权重1、权重2和数学偏差
【发布时间】:2018-03-14 18:57:27
【问题描述】:

如何求weight1、weight2和bias的值?找到任何问题的这 3 个值的通用数学方法是什么!

import pandas as pd


weight1 = 0.0
weight2 = 0.0
bias = 0.0

test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
correct_outputs = [False, False, False, True]
outputs = []

for test_input, correct_output in zip(test_inputs, correct_outputs):
    linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias
    output = int(linear_combination >= 0)
    is_correct_string = 'Yes' if output == correct_output else 'No'
    outputs.append([test_input[0], test_input[1], linear_combination, output, is_correct_string])


num_wrong = len([output[4] for output in outputs if output[4] == 'No'])
output_frame = pd.DataFrame(outputs, columns=['Input 1', '  Input 2', '  Linear Combination', '  Activation Output', '  Is Correct'])
if not num_wrong:
    print('Nice!  You got it all correct.\n')
else:
    print('You got {} wrong.  Keep trying!\n'.format(num_wrong))
print(output_frame.to_string(index=False))

【问题讨论】:

    标签: python pandas perceptron bias-neuron


    【解决方案1】:

    当您的输入为 [(0,0), (0,1), (1,0), (1,1)] 时,该问题要求您评估 weight1、weight2 和偏差,以便产生 [False ,假,假,真]。 在这种情况下,“假”将是一个负数的结果。相反,“真”将是一个正数的结果。 因此,您评估以下内容:

    x1*weight1 + x2*weight2 + bias' 是正还是负

    例如设置weight1=1,weight2=1,bias=-1.1(可能的解决方案) 你得到第一个输入:

    0*1 + 0*1 + (-1.1) = -1.1 这是负数,意味着它的计算结果为 False

    下一个输入:

    0*1 + 1*1 + (-1.1) = -0.1 这是负数,意味着它的计算结果为 False

    下一个输入:

    1*1 + 0*1 + (-1.1) = -0.1 这是负数,意味着它的计算结果为 False

    最后一个输入:

    1*1 + 1*1 + (-1.1) = +0.9 这是正数,意味着它的评估结果为 True

    【讨论】:

      【解决方案2】:

      以下内容也对我有用:

      weight1 = 1.5
      weight2 = 1.5
      bias = -2
      

      【讨论】:

        【解决方案3】:

        在正规方程的情况下,您不需要偏置单元。因此,这可能就是您所追求的(请记住,我已将您的 TrueFalse 值分别重铸为 10):

        import numpy as np
        
        A = np.matrix([[0, 0], [0, 1], [1, 0], [1, 1]])
        b = np.array([[0], [0], [0], [1]])
        
        x = np.linalg.inv(np.transpose(A)*A)*np.transpose(A)*b
        
        print(x)
        

        产量:

        [[ 0.33333333]
         [ 0.33333333]]
        

        有关解决方案的更多详细信息,请参见here

        【讨论】:

          【解决方案4】:

          以下对我有用:

          weight1 = 1.5
          weight2 = 1.5
          bias = -2
          

          当我更好地理解原因时会更新

          【讨论】:

            【解决方案5】:

            X1w1 + X2W2 + 偏差 测试是:

            linear_combination >= 0
            

            根据给定的输入值:

            test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
            

            AND 值仅在测试中计算为 true 一次,因此典型 AND 运算的输出应为:

            1   1   True 
            1   0   False
            0   1   False
            0   0   False
            

            假设,当我们在等式中输入测试输入时:X1w1 + X2W2 + 偏差,应该只有一个真实的结果。如上所述,我们的测试是方程的线性组合应该大于或等于零。我相信问题正在寻找的是,从测试运行中可以看出,这个输出只有一个是真的。 因此,要获得错误值,输出应该是负计算。 最简单的方法是用小值和负偏差来测试方程。 我试过了

            weight1 = 1
            weight2 = 1
            bias = -2
            

            【讨论】:

              猜你喜欢
              • 2018-01-09
              • 1970-01-01
              • 2020-07-27
              • 2019-12-01
              • 1970-01-01
              • 1970-01-01
              • 2019-12-29
              • 2018-03-05
              • 2019-09-26
              相关资源
              最近更新 更多