7

(avery) #1

Make your Arduino learn


TUTORIAL


bad. The process involves finding out how many of the
user data cases a combination would have predicted
correctly. For example, here are the prediction scores
for three random variable value combinations :

Flip_flag : true, thresh : 500
100 – on wrong
300 – on wrong
600 – off correct
800 – off wrong
850 – off wrong

Total correct = 1

Flip_flag : false, thresh : 200
100 – off correct
300 – on wrong
600 – on wrong
800 – on correct
850 – on correct

Total correct = 3

Flip_flag : false, thresh : 700
100 – off correct
300 – off correct
600 – off correct
800 – on correct
850 – on correct

Total correct = 5

Above
You can do this
using either the
Arduino IDE or
create.arduino.cc

MORE ADVANCED LEARNING


Usually, machine learning systems have far more
than two values to optimise (there can be millions
of values in advanced image-detection systems). To
train those systems it’s not feasible to just try every
combination, so instead they’ll use something called
gradient descent, which is a lot more efficient but
more complex to implement.

Now imagine we scored the performance of every
combination of threshold and flip_flag; that’s roughly
2000 different combinations. The Arduino does it in
a blink of an eye. Here is the Arduino code that loops
through each combination of variable values:
void optimise(){
// do brute force search to optimial coef and
intercept values
int best_score = 0;
int current_score = 0;

        for (int    flip_flag   =   0;  flip_flag   <=  1;  flip_flag++){
for (int thresh = 0; thresh < 1000; thresh +=
30){
current_score = score(thresh, flip_flag);
if (current_score > best_score){
learnt_thresh = thresh;
learnt_flip_flag = flip_flag;
best_score = current_score;
}
}
}
}

You can see that we score the performance of each
value combination and save the value combination that
performs best. You may think of this as automated
‘trial and error’, that’s because machine learning is
effectively trial and error – but isn’t human learning
also trial and error? Try something, evaluate your
performance, change what you’re doing, repeat!
To score the performance, we are counting
how many of the saved user data points the value
combination correctly predicts. So if we only stored
three data points, the best possible score a value
combination can get is three.

DATA COLLECTION
We want this system to learn based on the most
recent user input only. This will allow the system to
quickly adapt to new user behaviour. We can achieve
this by just storing the last ten times the user toggled
Free download pdf