This is second in a two-post series on building a neural network using microbits with micropython. In the first post python was used to produce a neural network without the microbits. In this post the network is as shown in figure 1 is developed.
The figure below shows the arrangement of the connections to be built; pin 2 is the output of each neuron. The two micro:bits/neurons on the left of the picture taking in the two same inputs; the output from these neurons are the two inputs to the output neuron on the right.
The figure below shows the arrangement of the connections to be built; pin 2 is the output of each neuron. The two micro:bits/neurons on the left of the picture taking in the two same inputs; 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 Fritzing diagram available at https://github.com/microbit-foundation/dev-docs/issues/36 thanks to David Whale (@whalleygeek ) for this.
The Inputs neurons
Neuron 1:
from microbit import *W=[-1,-1,1]
while True:
x1=pin0.read_digital()
x2=pin1.read_digital()
net = W[0]+W[1]*x1+W[2]*x2
if net>=0:
display.scroll("T")
pin2.write_digital(1)
else:
display.scroll("F")
pin2.write_digital(0)
Neuron 2
from microbit import *
W=[-1,1,-1]
while True:
x1=pin0.read_digital()
x2=pin1.read_digital()
net = W[0]+W[1]*x1+W[2]*x2
if net>=0:
display.scroll("T")
pin2.write_digital(1)
else:
display.scroll("F")
pin2.write_digital(0)
Output Neuron.
Feeding the inputs from Neuron 1 and Neuron 2 as inputs
from microbit import *
W=[-1,1,1]
while True:
x1=pin0.read_digital()
x2=pin1.read_digital()
net = W[0]+W[1]*x1+W[2]*x2
if net>=0:
display.scroll("T")
pin2.write_digital(1)
else:
display.scroll("F")
pin2.write_digital(0)
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