xxxxxxxxxx
39
/* source github: https://github.com/CodingTrain/website/blob/master/Courses/natureofcode/10.18-toy_neural_network/lib */
let training_data = [{
inputs: [1, 1],
targets: [0]
}, {
inputs: [0, 0],
targets: [0]
}, {
inputs: [1, 0],
targets: [1]
}, {
inputs: [0, 1],
targets: [1]
}];
function setup() {
createCanvas(400, 400);
let nn = new NeuralNetwork(2, 2, 1);
for(let i = 0; i < 1000; i++) {
let data = random(training_data);
nn.train(data.inputs, data.targets);
}
nn.weights_ih.print();
nn.weights_ho.print();
nn.bias_h.print();
nn.bias_o.print();
console.log(nn.feedforward([0,1]));
console.log(nn.feedforward([0, 0]));
console.log(nn.feedforward([1, 0]));
console.log(nn.feedforward([1, 1]));
}
function draw() {
// background(220);
}