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

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

本文建议使用三个感知器构建一个网络: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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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