Quick Overview
- Inputs are going to be binary
- Weighted sum is bias+W1*input1+w2*input2
- If weighted sum>=0 then the output is True (T on the LEDs) or '1'
- If weighted sum<0 false="" font="" is="" leds="" on="" or="" output="" the="" then="">0>
First attempt - A simple gate using the buttons A and B
So first attempt uses the A and B buttons on the Microbit as the two inputs and it produces T for true and F for false on the LEDs. So the weights produce an AND if the bias is changed from -2 to -1 you get an OR.
More Physical Solution for Single Neuron
So in this case the buttons are removed and P0 and P1 formed the inputs the weights are the same as in the previous example with the bias of -2 being used to produce a AND gate. Programming-wise this is a simpler solution than the previous one, no converting button presses into inputs.
Figures below show the 'neuron' in action.
First, one shows the case when both inputs are '0' ie. not connected to 3v connection. The output is False (F on the LEDs)
This figure shows when only one input is '1', the output is False.
Finally what happens when both inputs are '1', the output goes to True (T on the LEDs).
Where next?
The XOR - it needs a network of neurons
Essentially for the two input case, if the two inputs are different then the output is True.
The figure below shows the arrangement of the connections; pin 2 is the output of the neurons. The two micro:bits/neurons on the left of the picture taking in the two inputs, the same inputs go to these two neurons; the output from these neurons are the two inputs to the output neuron on the right.
figure 1 |
Neuron 1
This is the top left neurone in figure 1. This neurone is set to produce an output of TRUE (pin 2 going high) when the first input goes low and the second input goes high. The code for it is shown below.
Neuron 2
This is the bottom left neuron in figure 1. This neurone is set to produce an output of TRUE (pin 2 going high) when the first input goes high and the second input goes low. The code for it is shown below.
Output Neuron
Neuron 1
This is the right-hand neurone in figure 1. This neurone is set to produce an output of TRUE (pin 2 going high) when either inputs (outputs from neurons 1 and 2) goes high - in other words acting as an OR gate . The code for it is shown below.
The overall effect is when the two inputs to the network are high/TRUE then the output of the network (this neuron) is TRUE.
In Action
The wiring is messy but the effect is possible to see in these images. The top neuron is the output neuron.
figure 2: inputs to the network (input 1 low and input 2 high) |
Figure 3: inputs to the network (input 1 high and input 2 low) |
figure 4: inputs to the network (both inputs the same) |
The neurons were 'trained' in this case by selecting the weights by hand, an improvement would be to get them to learn. How to do this on a micro:bit takes a bit more thinking about, but I would be interested in seeing how others solve that problem.
All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon
No comments:
Post a Comment