Wednesday 24 April 2019

Even more experiments with Neural Networks

For a while I have been looking at teaching Artificial Neural Networks (https://computingnorthampton.blogspot.com/2018/04/further-experiments-in-teaching-neural.html) but what was missing, I think, is a physical aspect and in response to a question from Carl Simmons (@Activ8Thinking) about has anyone built a microbit simple neuron. I set out to build a neuron (then a small network of neurons) based around the microbit.


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="">



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

The micro:bit objects used in Figure 1 were produced using the micro:bit Frtzing diagram available at https://github.com/microbit-foundation/dev-docs/issues/36 thanks to David Whale (@whalleygeek ) for these.


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)
6. Room for expansion
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




Friday 12 April 2019

Junkbots goes to Duston



via GIPHY

The junkbots project went to Duston Eldean Primary School, Northampton on 3rd April 2019, as part of their STEAM Week.

Each group built a drawing bot from vibrating motors, pens, sometimes a Kinder Egg plastic case (I was asked who eat all the chocolate - I admitted it was me)...and lots of tape. Details on the whole process and how to do it go to Crumble Based Junk Eggbot .

Structure of the session


  • 5 minutes the whole group is together and volunteers come up, face the group and hold the motor - when it is turned on the motor vibrates and often gets a reaction.
  • 10-20 minutes build in smaller groups the drawing bot and get it scribbling.
  • Remaining time put the crumble controller between the battery and the motor. Details on how to do this go to Crumble Based Junk Eggbot .











All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruon