【问题标题】:How to run a 2-layer perceptron to solve XOR如何运行 2 层感知器来解决 XOR
【发布时间】:2017-02-15 20:12:27
【问题描述】:

XOR 不能通过使用具有标准标量积和单位阶跃函数的单个感知器来解决。

这篇文章建议使用3个感知器来做一个网络: http://toritris.weebly.com/perceptron-5-xor-how--why-neurons-work-together.html

我正在尝试以这种方式运行 3 感知器网络,但它不会为 XOR 产生正确的结果:

//pseudocode
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)
  }
}

上面的感知器可以正确解决NOT、AND、OR位运算。这就是我使用 3 个感知器来解决 XOR 的方法:

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 = 0
test_x2 = 1 

//first layer of perceptrons
and_result   = AND_perceptron.compute(test_x1,test_x2)
or_result    = OR_perceptron.compute(test_x1,test_x2)

//second layer
final_result = XOR_perceptron.compute(and_result,or_result)

上面的final_result不一致,有时为0,有时为1。看来我跑错了2层。如何以正确的方式分两层运行这 3 个感知器?

【问题讨论】:

    标签: neural-network artificial-intelligence layer xor perceptron


    【解决方案1】:

    如果你想构建一个带有逻辑连接(and、or、not)的神经网络,你必须考虑以下关于 xor 的等价性:

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

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

    【讨论】:

    • tks,所以我可以使用 2 个感知器,它们可以学习 AND、OR,并根据这 2 个感知器生成 XOR 的结果
    猜你喜欢
    • 2015-08-05
    • 2017-08-29
    • 2018-07-14
    • 2018-07-15
    • 2015-09-27
    • 2013-03-04
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多