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

Par*_*007 1 python neural-network pandas

我正在实现AND Perceptron,在确定权重和组合的偏向以使其与AND Truth表匹配时遇到困难。

这是我编写的代码:

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))
Run Code Online (Sandbox Code Playgroud)

我必须根据上述值确定weight1,weight2和bias。当有10作为输入时,我得到一个输出错误。

感谢您的帮助。

Jai*_*sco 6

和感知器:

weight1 = 1.0
weight2 = 1.0
bias = -2.0
Run Code Online (Sandbox Code Playgroud)

或感知器:

weight1 = 1.0
weight2 = 1.0
bias = -1
Run Code Online (Sandbox Code Playgroud)

非感知器:

weight1 = 1.0
weight2 = -2.0
bias = 0
Run Code Online (Sandbox Code Playgroud)

偏差充当截距来调整线性方程。


Pru*_*une 5

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

系统:

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
Run Code Online (Sandbox Code Playgroud)

这让你

w + b <= 0
2*w + b > 0
Run Code Online (Sandbox Code Playgroud)

您应该能够从那里描述可能的解决方案。