LoginSignup
0
0

More than 5 years have passed since last update.

Toy-Neural-Network-JSでxor その2

Posted at

概要

Toy-Neural-Network-JSでxorやってみた。

結果

0, 0 = 0.14425495055461737
0, 1 = 0.7930326318458016
1, 0 = 0.7835267831435138
1, 1 = 0.26005143254183366

サンプルコード

let nn;
let training_data = [{
    inputs: [0, 0],
    outputs: [0]
}, {
    inputs: [0, 1],
    outputs: [1]
}, {
    inputs: [1, 0],
    outputs: [1]
}, {
    inputs: [1, 1],
    outputs: [0]
}];
nn = new NeuralNetwork(2, 8, 1);
nn.setLearningRate(0.01);
for (let i = 0; i < 10000; i++) 
{
    let data = training_data[0];
    nn.train(data.inputs, data.outputs);
    data = training_data[1];
    nn.train(data.inputs, data.outputs);
    data = training_data[2];
    nn.train(data.inputs, data.outputs);
    data = training_data[3];
    nn.train(data.inputs, data.outputs);
}
let str = "";
let inputs = [0, 0];
let y = nn.predict(inputs);
str += "0, 0 = " + y + "<br>";
inputs = [0, 1];
y = nn.predict(inputs);
str += "0, 1 = " + y + "<br>";
inputs = [1, 0];
y = nn.predict(inputs);
str += "1, 0 = " + y + "<br>";
inputs = [1, 1];
y = nn.predict(inputs);
str += "1, 1 = " + y + "<br>";
document.write(str);



成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0