和感知者的权重和偏见是什么



我正在实施和感知,并且在确定组合将其与之匹配和真相表的权重和偏差方面面临困难。

这是我编写的代码:

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和偏差。当有10作为输入时,我会弄错一个输出。

感谢您的帮助。

  • 方程是对称的:两个输入在功能上等效。
  • 将权重作为变量,在三个(现在是两个)变量中有四个(现在是三个)不等式。您在哪里解决该系统?

系统:

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
2*w + b > 0

您应该能够从那里表征可能的解决方案。

和perceptron:

weight1 = 1.0
weight2 = 1.0
bias = -2.0

或perceptron:

weight1 = 1.0
weight2 = 1.0
bias = -1

不感知:

weight1 = 1.0
weight2 = -2.0
bias = 0

偏见是调整线性方程的拦截。

尝试使用relu激活功能,看看它是否解决了您的问题

relu(weight1 * test_input[0] + weight2 * test_input[1] + bias)

1、1和-1.5应该工作。

perceptron算法

预测= 1如果wx+b >=0 and 0 if wx+<0

所以输入为 (0, 0), (0, 1), (1, 0), (1, 1)确保您将输入 stroge1,weight 2和bias 的数字将把< 0作为false和 >=0作为true

  1. 对于输入(0,0)

stright1*0 stright2*0 -2

1*0 1*0-2 = -2

  1. 对于输入(0,1)

1*0 1*1-2 = -1

  1. 对于输入(1,0)

1*1 1*0-2 = -1

  1. 对于输入(1,1)

1*1 1*1-2 = 0

因此,我的重量1 = 1,重量2 = 1,偏见= -2。我把所有答案都作为正确的

只要输出陈述和操作,您就可以使用任何 strige1,weight 2和bibias 值。请记住,您可以申请或其他操作

最新更新