Slide 180
Slide 180 text
// › examples/xor.php
$inputs = [
[0, 0], // 0
[0, 1], // 1
[1, 0], // 1
[1, 1] // 0
];
$targets = [0, 1, 1, 0];
$neuralNetwork = new NeuralNetwork(
new Activation\Sigmoid(),
new CostFunction\MeanSquaredError()
);
$neuralNetwork->train($inputs, $targets);
echo "Predicting...\n";
echo sprintf("* Input: [0,0] Prediction: %.2f Target: 0\n", $neuralNetwork->predict([0,0]]));
echo sprintf("* Input: [0,1] Prediction: %.2f Target: 1\n", $neuralNetwork->predict([0,1]]));
echo sprintf("* Input: [1,0] Prediction: %.2f Target: 1\n", $neuralNetwork->predict([1,0]]));
echo sprintf("* Input: [1,1] Prediction: %.2f Target: 0\n", $neuralNetwork->predict([1,1]]));