In [1]:
import sys
import os
sys.path.insert(0,'..')
sys.path.insert(0,'../layeredneuralnetwork/')
Let us create an LNN with 2 dimension input.
In [2]:
from layered_neural_network import LayeredNeuralNetwork
input_dimension = 2
lnn = LayeredNeuralNetwork(input_dimension=input_dimension)
In [3]:
from school.binary import Binary
Binary.teach_and(lnn)
Binary.teach_or(lnn)
Binary.teach_xor(lnn)
Out[3]:
In [4]:
%pylab inline
weights = lnn.get_weights()
print(weights.shape)
In [5]:
plt.imshow(weights, cmap='gray', interpolation='none')
plt.title('Weights of LNN')
plt.xlabel('Inputs')
plt.ylabel('Classifiers')
Out[5]:
The above shown matrix corresponds to the weights of classifier. Lighter shade indicates higher value, gray = 0, black = negative. Each row is a calssifier, with each column indicating the weight given to different input, previous classifier.
and classifier The first row shows AND classifier. Note the high value for input 0 and input 1 and the high bias. This is ON only when both inputs are high.
or classifier The second row shows OR classifier. Note the relatively low values for both inputs and bias.
xor classifier A linear classifier cannot learn XOR, but with the help of AND and OR classifier even a linear classifier can solve the dreaded XOR task. XOR -> big negative value for AND, positive value for OR.
In [ ]: