単一のパーセプトロンを標準スカラー積とユニットステップ関数で使用することでXORを解くことはできません。2層パーセプトロンを実行して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ビット演算を正しく解くことができます。これは私がXORを解決するために3つのパーセプトロンを使用する方法である:
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は時々1.私が間違って2層を実行しているようだ、時々、0一貫性がありません。これらの3つのパーセプトロンを2つのレイヤーで正しい方法で実行するにはどうすればよいですか?
tksなので、2つのパーセプトロンを使用することができます。これは、これらの2つのパーセプトロンに基づいてAND、ORを学習し、XORの結果を作ることができます – johnlowvale