In this example, we're going to solve the XOR problem using a TensorFlow.js feedforward neural network. First, let's explore the XOR problem, and why it's a good starting point for us.
The XOR, or exclusive or operation, is a Boolean operator that returns true if only one, but not both, of its inputs is truth. Compare this to the regular Boolean OR that you're more commonly familiar with, which will return true if both inputs are true—the XOR will return false if both inputs are true. Here is a table comparing XOR to OR; I've highlighted the case where OR and XOR differ:
Input 1 | Input 2 | OR | XOR |
False | False | False | False |
False | True | True | True |
True | False | True | True |
True | True | True | False |
Why is the XOR problem a good test for us? Let's plot the XOR operations on a graph:
Viewing the preceding graph, we can...