Neural network 如何运行两层感知器来解决XOR问题

Neural network 如何运行两层感知器来解决XOR问题,neural-network,artificial-intelligence,layer,xor,perceptron,Neural Network,Artificial Intelligence,Layer,Xor,Perceptron,用一个具有标准标量积和单位阶跃函数的感知器无法解XOR 本文建议使用3感知器构建一个网络: 我试图以这种方式运行3-perceptron网络,但它不能为XOR生成正确的结果: //pseudocode class perceptron { constructor(training_data) { this.training_data = training_data } train() { iterate multiple times over traini

用一个具有标准标量积和单位阶跃函数的感知器无法解XOR

本文建议使用3感知器构建一个网络:

我试图以这种方式运行3-perceptron网络,但它不能为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)
  }
}

上述最终结果不一致,有时为0,有时为1。看来我把这两层弄错了。如何正确地在2层中运行这3个感知器?

< P>如果你想构建一个逻辑连接的神经网络(或者,或者,不是),你必须考虑XOR:

的下列等价性。 异或≡ (一)∨ (B)∧ (A)∧ (B)≡ (一)∨ (B)∧ (A)∨ (B)≡ (一)∧ (B)∨ (A)∧ (B)


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

tks,因此我可以使用两个感知器,它们可以学习and和or,并根据这两个感知器生成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)