如何运行两层感知器来解决异或问题

使用单个感知器和标准标量乘积以及单位阶跃函数无法解决异或问题。

本文建议使用三个感知器构建一个网络:http://toritris.weebly.com/perceptron-5-xor-how–why-neurons-work-together.html

我尝试以这种方式运行三感知器网络,但它无法为异或产生正确的结果:

//伪代码class perceptron {  constructor(training_data) {    this.training_data = training_data     }  train() {    iterate multiple times over training data    to train weights  }  unit_step(value) {    if (value<0) return 0    else return 1  }  compute(input) {    weights = this.train()    sum     = scalar_product(input,weights)    return unit_step(sum)  }}

上面的感知器可以正确解决非、与、或位运算。我使用三个感知器来解决异或的方式如下:

AND_perceptron = perceptron([  {Input:[0,0],Output:0},  {Input:[0,1],Output:0},  {Input:[1,0],Output:0},  {Input:[1,1],Output:1}])OR_perceptron = perceptron([  {Input:[0,0],Output:0},  {Input:[0,1],Output:1},  {Input:[1,0],Output:1},  {Input:[1,1],Output:1}])XOR_perceptron = perceptron([  {Input:[0,0],Output:0},  {Input:[0,1],Output:1},  {Input:[1,0],Output:1},  {Input:[1,1],Output:0}])test_x1 = 0test_x2 = 1 //第一层感知器and_result   = AND_perceptron.compute(test_x1,test_x2)or_result    = OR_perceptron.compute(test_x1,test_x2)//第二层final_result = XOR_perceptron.compute(and_result,or_result)

上面的final_result不一致,有时为0,有时为1。看起来我运行这两层的方式有误。如何正确地运行这两个层中的三个感知器?


回答:

如果你想构建一个使用逻辑连接词(与、或、非)的神经网络,你需要考虑以下关于异或的等价关系:

A xor B ≡ (A ∨ B) ∧ ¬(A ∧ B) ≡ (A ∨ B) ∧ (¬A ∨ ¬B) ≡ (A ∧ ¬B) ∨ (¬A ∧ B)

所以如果你想使用你的感知器,你至少需要三个与-或感知器和一个否定操作,如果我理解正确的话。在文章中,他们使用了三个具有特殊权重的感知器来处理异或。这些与与-或感知器不同。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注