首页 技术 正文
技术 2022年11月11日
0 收藏 428 点赞 2,363 浏览 1378 个字

AND 感知器练习

 神经网络入门——6and感知机 神经网络入门——6and感知机 

AND 感知器的权重和偏置项是什么?

把权重(weight1weight2)和偏置项 bias 设置成正确的值,使得 AND 可以实现上图中的运算。

 

在这个例子中,在上图中可以看出有两个输入(我们把第一列叫做 input1,第二列叫做 input2),根据感知器公式,我们可以计算输出。

首先,线性组合就是所有输入乘以权重后求和:linear_combination = weight1*input1 + weight2*input2,然后我们可以将该值传入加上偏置值的单位越阶函数,这将给我们一个(0 或 1)的输出:

 神经网络入门——6and感知机

import pandas as pd# TODO: Set weight1, weight2, and bias
weight1 = 1
weight2 =1
bias = -2# DON'T CHANGE ANYTHING BELOW
# 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))

  

如果你还需要一点提示,看看这个具体的例子:

对于 AND 感知器来说,input1 和 input2 都为 1 时,我们想要的输出等于 1!这个输出是由权重和单位阶跃函数(Heaviside step function)共同决定的:

output = 1, if  weight1*input1 + weight2*input2 + bias >= 0
or
output = 0, if weight1*input1 + weight2*input2 + bias < 0

所以,你能为权重和偏置项设置一个值,使得两个输入都等于 1 的时候,output = 1 吗?

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,993
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845