Algorithmic Intelligence Tutorial

Algorithmic Intelligence explores some of the features of Machine Learning (ML) and Artificial Intelligence (AI). Both AI and ML have strong connotations which have varied definitions and usages. All the talk of AI, ML and Data Science is rooted in algorithms, hence the name Algorithmic Intelligence. This tutorial gets you started on a journey to discover what exactly AI and ML are, what is happening behind the scenes. It is done, hopefully, in a fun, entertaining and visual way to help you understand the mechanisms involved so that you can develop your own journey.

The coding language used is p5.js. This is a JavaScript library that lends itself to creative and visual coding. This is very people friendly and can be used by anyone of any age and skill set. It is web based, that means that you don’t have to download anything, you can do all this in your browser. It is also free to use and doesn’t require any sign up unless you want to save your work (recommended).

To enhance the learning we need a machine learning library to handle all the maths and heavy lifting. You can build a machine learning model from scratch but why re-invent the wheel. for this we use ml5.js which as the name suggests is also a JavaScript library that dovetails beautifully with p5.js.

To get started I will take you step by small step through the process. I will include short videos as well as downloadable pdfs. They are free to use as you wish, either have them on a separate monitor (tablet or smartphone for instance) or print them off.

Each unit is a separate unit of work, with a specific focus. The modules are collections of units that have a similar focus. It is expected and assumed that you have worked through each unit of each module as next one often builds on the previous one. If you jump ahead you may miss some key elements that could be significant.

The pace you go at will depend on your abilities, skill and experience. So feel free to go as fast as you want or as slow as you feel. I would recommend doing some each day to build up memory muscle, the more you do the better you become and the more intuitive it becomes. also play, experiment, try to break it, enhance it, change something and see what happens. This is the best way to learn.

Introduction

This first section is important. especially if you are new to this. Take the time to read them, also watch the videos, they are quite short (5 mins-ish). These will give you the background necessary to tackling the units to come.

A Brief Summary of Algorithmic Intelligence

This quick read through gives you some background information on Algorithmic Intelligence, Machine Learning and in particular to Neural Networks and what they are.

An Exploration of p5.js

To access this tutorial you will need a basic understanding what p5.js is and also how the web based editor and all its buttons and settings work and benefit you.

Videos

video #1: how to start using the editor

video #2: some of the buttons used in the editor

video #3: looking at the editor in a little more detail

video #4: creating a new file

An Overview of ml5.js

Although p5.js is the main coding environment it the ml5.js library that does all the heaving lifting when it comes to the Artificial Intelligence and Machine Learning units.

Module A

Building a model

Module A is where we start our journey, work through each unit and I recommend that you don’t skip a unit. The coding snippets have been kept as brief as possible so that when you are working through the AI units you have some understanding of p5.js while attempting to grasp the concepts of AI. This module uses ml5.js and explores some simple examples that will demonstrate key features.

Module A Unit #1 p5.js Code Snippets Part 1

To create your AI models you do need to code, this is a quick introduction to the key concepts that you will need, it is ideal for those who have never coded before and a good introduction to p5.js for those who have.

Module A Unit #2 Linear Regression

In this first unit we plot points for a straight line with some variance (randomness). The neural network (ml5.js) will be trained on these data points and will approximate to the line. This is a regression task where you will train it on some synthetic data and then predict the outcome.

Module A Unit #3 Sine Wave Regression

This is similar to unit #1 but a bit more challenging for the neural network to learn, here we will introduce some more hyperparameters to help in the learning process, hopefully with improved accuracy.

Module A Unit #4 Mouse Gesture

This is a classification task. We will give the neural network a small amount of synthetic data on the movement of the mouse, it will try to predict whether the mouse is moving up, down, left or right.

Module A Unit #5 p5.js Code Snippets Part 2

An introduction to some key concepts used in the next section, such as using video and exploring pixels.

Module A Unit #6 Cluster Classification

This is a supervised learning model. We are going to click on the canvas in four areas. In each quadrant we will create a set of ten circles then we will predict the colour in the space between the circles

Module A Unit #7 Cluster Regression

Here we will click on the canvas to create a cluster of white circles and a cluster of black circles. We will train it on those data points and then predict what shade of grey the canvas is between those data points.

Module A Unit #8 Colour Predictor

Train the neural network to predict three colour groups using synthetic data and testing with sliders.

Module A Unit #9 Pixel Predictor

In this unit we take the pixels from an image (webcam) and train the neural network to move a circle with your head

Module A Unit #10 Save and Load

This unit covers saving/loading data, and saving/loading models once trained

Module B

Pretrained models

Module B looks at some pretrained models which means that they have done all the hard work of collecting the data and training the models. The reason for this module is that you can use these pretrained models to develop other applications and creative endeavours. It is also quite fun.

Module B Unit #1 p5.js Code Snippets Part 3

A short unit as background coding snippets useful for the remainder of this section.

Module B Unit #2 Pretrained Face Mesh

This pretrained model can identify over 400 points on your face, we will use some of those points to draw a box around your mouth and locate your eyes.

Module B Unit #3 Pretrained Hand Pose

This pretrained model can identify key parts of your hand (both hands at once). In this example you will control a circle on the canvas with your fingers.

Module B Unit #4 Pretrained Body Pose

This pretrained model can identify the main parts of the body, such as hands, arms, legs, eyes and so on. We can also draw a skeleton between these points.

Module B Unit #5 Pretrained Speech Classification

This pretrained model has been trained on 18 key words, so that when you say one of those words it would recognise it. As an exercise you will move a circle round the canvas with your voice.

Module B Unit #6 Pretrained Body Segmentation

This pretrained model can detect key body parts and follow their motion

Module C Neuro Evolution

Module C is a bit more challenging, it is looking at Reinforcement Learning through the use of Genetic Algorithms. The algorithm we will be using is a neuro evolution approach which means that we put a neural network in a car and a bird respectfully. We allow them to reproduce and over time we select the ones that perform best according to their fitness scores.

Module C Unit #1 p5.js Coding Snippets Part 4

These snippets will help you when you are working through the next set of units for neuroevolution smart cars and flappy bird game.

Module C Unit #2 Introduction to Genetic Algorithms

Although we will be using a neural network which means that it is a neural evolution approach, the fundamentals are based on genetic algorithms where we select the fittest and mate them to reproduce a better next generation. This is offers a bit more explanation.

Module C Unit #3 Smart Cars

This is the first example where cars are given their own brain and through a process of selection chase a target that is moving randomly according to perlin noise. They don’t know that they are meant to do that but only that they are rewarded for doing so.

Module C Unit #4 Flappy Bird Brain

In this example we create a simple version of the flappy bird game and then give the bird a brain. Then using a neuroevolution approach allow successive generations to play the game until a bird can navigate the pipes without hitting them.