Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 和感知器的权重和偏差是多少?_Python_Pandas_Neural Network - Fatal编程技术网

Python 和感知器的权重和偏差是多少?

Python 和感知器的权重和偏差是多少?,python,pandas,neural-network,Python,Pandas,Neural Network,我正在实现和感知器,并且在确定组合的权重和偏差以使其与和真值表相匹配时面临困难 以下是我编写的代码: import pandas as pd # Set weight1, weight2, and bias weight1 = 2.0 weight2 = -1.0 bias = -1.0 # Inputs and outputs test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)] correct_outputs = [False, False, Fa

我正在实现和感知器,并且在确定组合的权重和偏差以使其与和真值表相匹配时面临困难

以下是我编写的代码:

import pandas as pd

# Set weight1, weight2, and bias
weight1 = 2.0
weight2 = -1.0
bias = -1.0

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

# Generate and check output
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])

# Print output
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))
我必须根据所提到的值来决定权重1、权重2和偏差。当有
1
0
作为输入时,我得到一个输出错误

谢谢你的帮助。

  • 方程是对称的:两个输入在功能上是等价的
  • 以你的权重作为变量,你有四个(现在是三个)不等式在三个(现在是两个)变量中。你在解决那个系统上遇到了什么困难
系统:

w = weight (same for both inputs)
b = bias

0*w + 0*w + b <= 0
1*w + 0*w + b <= 0
1*w + 1*w + b >  0
w=重量(两个输入相同)
b=偏差

0*w+0*w+b尝试使用relu激活功能,看看它是否能解决您的问题

relu(权重1*测试输入[0]+权重2*测试输入[1]+偏差)


1、1和-1.5应该可以工作。

感知器算法

如果wx+b>=0,则预测值为1;如果wx+=0,则预测值为0

  • 用于输入(0,0)
  • 权重1*0+权重2*0+-2

    1*0+1*0-2=-2

  • 用于输入(0,1)
  • 1*0+1*1-2=-1

  • 用于输入(1,0)
  • 1*1+1*0-2=-1

  • 用于输入(1,1)
  • 1*1+1*1-2=0

    因此,我的权重1=1,权重2=1,偏差=2。我得到的答案都是正确的

    只要输出状态为and操作,就可以使用所需的任何weight1、weight2和bias值。请记住,您可以应用于或和其他操作

    和感知器:

    weight1 = 1.0
    weight2 = 1.0
    bias = -2.0
    
    weight1 = 1.0
    weight2 = 1.0
    bias = -1
    
    weight1 = 1.0
    weight2 = -2.0
    bias = 0
    
    或感知器:

    weight1 = 1.0
    weight2 = 1.0
    bias = -2.0
    
    weight1 = 1.0
    weight2 = 1.0
    bias = -1
    
    weight1 = 1.0
    weight2 = -2.0
    bias = 0
    
    不是感知器:

    weight1 = 1.0
    weight2 = 1.0
    bias = -2.0
    
    weight1 = 1.0
    weight2 = 1.0
    bias = -1
    
    weight1 = 1.0
    weight2 = -2.0
    bias = 0
    

    偏差作为截距来调整线性方程。

    1,1,-1.5对我有效,但不需要relu激活函数。int(线性组合>=0)在某种意义上作为relu函数。如果将其更改为int(线性组合>0),它将成为一个relu激活函数。如Prune所述,有许多解决方案。谢谢@Lufy yes 1,1和-1.5是为OR运算符与我一起工作的,关于and运算符呢?