Try to combine the gates we discussed. It's already if you do so by trial and error. To help you out, the code below specifies that our combination first passes the inputs to two separate hidden gates or hidden neurons, and then passes the outcome of that to a single output neuron
In[26]:
nand_gate = Neuron(w1=-1, w2=-1, b=2)
In[27]:
nor_gate = Neuron(w1= -1, w2= -1, b= 1)
In[28]:
and_gate = Neuron(w1=1, w2=1, b=-1)
In[29]:
or_gate = Neuron(w1=2, w2=4, b=-1)
make_truth_table(or_gate)
0, 0: 0.0 0, 1: 1.0 1, 0: 1.0 1, 1: 1.0
In[46]:# Uncomment the xor_gate line and find out which neurons besides the or_gate neuron the
# network should have in its hidden and output layer to produce the right values.
class Network():
def __init__(self, gate1, gate2, out_gate):
self.hidden_neuron1 = gate1
self.hidden_neuron2 = gate2
self.out_neuron = out_gate
def activate(self, x1, x2):
z1 = self.hidden_neuron1.activate(x1, x2)
z2 = self.hidden_neuron2.activate(x1, x2)
return self.out_neuron.activate(z1, z2)
xor_gate = Network(nor_gate,nand_gate, and_gate) #tried alll gates here ....., cannot get output to show value above
make_truth_table(xor_gate)
0, 0: 1.0 0, 1: 1.0 1, 0: 1.0 1, 1: 0.0