使用单个感知器和标准标量乘积以及单位阶跃函数无法解决异或问题。
本文建议使用三个感知器构建一个网络: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)
所以如果你想使用你的感知器,你至少需要三个与-或感知器和一个否定操作,如果我理解正确的话。在文章中,他们使用了三个具有特殊权重的感知器来处理异或。这些与与-或感知器不同。