← back

Artificial Neural Network for XOR Problem

We learned how an Artificial Neural Network can be used to solve the XOR problem.

The XOR function takes 2 inputs - if the inputs are the same, it outputs 0 (false), and if the inputs are different, it outputs 1 (true).

input 1input 2output
000
011
101
110

Early AI couldn't process this until a "hidden layer" was added.

I decided to make my own Artificial Neural Network and test it on the XOR problem.

I drew a diagram of the model.

I tested the weights and biases of the model.

X1X2H1 inputH1 output (ReLU)H2 inputH2 output (ReLU)y inputy output (sigmoid)
000 * -3.234061 + 0 * 3.2338295 + -0.00017982 = -0.00018negative value outputs 00 * 3.3131413 + 0 * -3.3131545 + -0.00036467 = -0.000365negative value outputs 00 * 4.1856656 + 0 * 3.9753308 + -5.779532 = -5.78round(sigmoid(-5.78)) = 0
010 * -3.234061 + 1 * 3.2338295 + -0.00017982 = 3.2343.2340 * 3.3131413 + 1 * -3.3131545 + -0.00036467 = -3.314negative value outputs 03.234 * 4.1856656 + 0 * 3.9753308 + -5.779532 = 7.757round(sigmoid(7.757)) = 1
101 * -3.234061 + 0 * 3.2338295 + -0.00017982 = -3.234negative value outputs 01 * 3.31314137 + 0 * -3.3131545 + -0.00036467 = 3.3133.3130 * 4.1856656 + 3.313 * 3.9753308 + -5.779532 = 7.391round(sigmoid(7.391)) = 1
111 * -3.234061 + 1 * 3.2338295 + -0.00017982 = -0.000411negative value outputs 01 * 3.3131413 + 1 * -3.3131545 + -0.00036467 = -0.000378negative value outputs 00 * 4.1856656 + 0 * 3.9753308 + -5.779532 = -5.78round(sigmoid(-5.78)) = 0

The hidden layer and the weights and biases do produce the correct outputs.

This activity really made it clear to me how the "hidden layers" of an Artificial Neural Network work. I will certainly be using machine learning models such as this in my career as a data scientist!