神经网络入门——6and感知机
2024-08-31 22:13:21
AND 感知器练习
AND 感知器的权重和偏置项是什么?
把权重(weight1
, weight2
)和偏置项 bias
设置成正确的值,使得 AND 可以实现上图中的运算。
在这个例子中,在上图中可以看出有两个输入(我们把第一列叫做 input1
,第二列叫做 input2
),根据感知器公式,我们可以计算输出。
首先,线性组合就是所有输入乘以权重后求和:linear_combination = weight1*input1 + weight2*input2
,然后我们可以将该值传入加上偏置值的单位越阶函数,这将给我们一个(0 或 1)的输出:
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 吗?
最新文章
- PC虚拟现实应用的性能分析与优化:从CPU角度切入
- 设置statusBarStyle
- spring-test测试demo
- Windows phone 8.1布局控件
- zmq中zmq_poll()函数介绍
- WLAN信道
- 【POJ】1151 Atlantis(线段树)
- iframe中的jquery ui modal dialog 覆盖父窗口
- JavaScript之常用方法讲解
- UI布局
- C++中对sprintf()函数的说明(转)
- hdu4414(DFS 找十字架数量)
- Result Maps collection does not contain value for com.man.impet.dao.OrderBeanMapper.map
- DB 查询分析器 6.03 在Windows 8 上安装与运行演示
- kubernetes进阶之四:Label和Label Selector
- mysql获取表中数据行数
- L1-030 一帮一(15)(代码)
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
- JavaOne 2016主旨演讲畅谈Java近期及远期规划
- The web application [ ] registered the JDBC driver [net.sourceforge.jtds.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver
热门文章
- ant详细介绍
- 只需一步,DLA开启TableStore多元索引查询加速!
- Windows Phpstrom svn 配置
- SAS之大话PDV
- Hibernate:**not found while looking for property: id https://blog.csdn.net/weixin_43827144/article/details/88935334
- Java加密AES算法及spring中应用
- day38 20-Spring与Junit整合
- Webpack ERROR in Path must be a string. Received undefined
- Centos7搭建Django出现的问题(Centos7+Django1.11.1+Nginx+uwsgi)
- JavaScript--关于实例对象带不带参数和构造函数带不带参数的关系