February 5, 2021

Coding15 - Creative applications of machine learning

This session is about familiarising yourself with the basics of machine learning; it’s also about getting a better understanding of what machine learning systems do, and how they can be manipulated for creative purposes. As a result, we are going to focus on simple machine learning algorithms, rather than more complex ones. However, what we will learn is just how powerful even simple machine learning systems can be!

Simple can be powerful

Some of these approaches are a little bit complicated when you are starting out, and it’s easy to not fully understand what you are doing. Also, some machine learning approaches require some extra hardware. We are not going to cover some of these generative approaches in this session, as it’s just an introduction.

First, we are going to concentrate of getting comfortable with basic concepts. These are surprisingly easy to get started with using a little bit of JavaScript, and some starter code. We are going to have a look at some code examples that make it easier to get started, without introducing too many complex ideas.

Supervised learning using RAPID Lib

We are mostly going to be using what we call “supervised” learning approaches; supervised learning uses examples to train models; the supervised learning algorithms that will be covered in the course can be broadly grouped into two types: Classification and Regression.

We will be using a JavaScript machine learning library called RAPIDLib. We will also get ‘control data’ from sliders, the mouse and keyboard and other places.

For this first part we are just going to get comfortable with using a machine learning system called RapidLib. RapidLib takes an input, for example the mouse, and records it alongside some output, we will them train a model and use this to map 2 dimensional mouse input(x,y) to control 4 synthesis parameters.

You can try: RAPIDMIX

This explains how you can start to create your own machine learning system very quickly without any prior experience.

How it works

Use the example below to randomise synth parameters until you find a sound you like, you can also use the sliders to control the sound in more detail. Move the mouse to somewhere on the screen, then click and hold to record samples.

When you have a few, hit ‘t’ to train; now when you move the mouse around you will be able to explore your newly trained sound space.

Try clearing the dataset ‘x’, change the training examples to see how this changes the behavior of the system after it is re-trained. Spend some time experimenting with the trained models to start to understand how the models are changed.

We have learned how to create a basic dataset, and train a simple regression model to explore and control a range of sounds created by a synthesizer. We did not need to worry that much about the actural synthesizer controls(the parameters), or what they did instead we used machine learning to make up a range of sounds based on some random examples. We then moved through the sound world produced by the machine learning system using some simple inputs.

Classification

We are going to look in more detail at Classification, we will explore how classification models work using a simple visualization, also will use machine listening technology and simple classification model to detect different types of sounds automatically.

When relationship between your inputs and your outputs is complex, classification algorithms can allow you to build things that would be challenging or impossible to program yourself by hand. This is what makes machine learning so exciting, you can create highly complex systems without having to program them manually. This is really powerful, and also pretty simple.

Now we are going to create a very simple classification model, use something called ‘K-Nearest Neighbour’ to classify some inputs. So what is K-Nearest Neighbour?

K-Nearest Neighbour, or KNN, can be used for Classification or Regression. We are going to use it for Classification. This means it is going to tell us waht kind of input we have, based on its similarity to other inputs we have told the model about. KNN does this by comparing the current input with a previous stored inputs using a distance measurement, one simple example of a distance measurement is the euclidean distance. You definitely already know what this is, but possibly have not thought about it this way.

Getting the distance between two points in 2D is identical to working out the length of the hypotenuse of a rightangled triangle, with the two points being at each end. Square the two straight sides, add them, and the square root of this is the length of the diagonal side. This works no matter how many dimensions your shape has. It’s a fundamental concept taht is used all the time.

The KNN gives a new input the same ‘class’ or label as a certain number of its nearest neighbors, the number of neighbours that it checks against is a small value, represented by the letter K. If K = 1, them the new input is given the same class as its nearest neighbor. If K is > 1, say 5, them the 5 nearest nearest neighbours are checked. The new input gets the most common class of those nearest neighbours. Often they are weighted based on how similar they are. K-Nearest Neighbour is not that great, but it is super simple and pretty effective for the stuff we are doing today. When deciding on an approach to take, we compared algorithm’s sensitivity to noise and their capacity to learn complexity. Often this choice can be a payoff between the two.

Recap

So we looked at Classification in more detail, we also thought about the problems that can occurwith classification, we then looked at how we can use a simple form of classification to detect different types of sounds, we found out that this was pretty impressive.

Regression

Let’s think about Regression in more detail. We can use this using the MIMIC regression explorer. Regression models can be used to map continuous inputs. As with Classification, different algorithms produce different types of lines or curves given the same data. As such, it is important to pick an algorithm that can model the appropriate complexity. As with classification, there is currently no choice of regression algorithm in Rapidlib. “Many to many mappings” are when we map lots of inputs to lots of outputs, they can allow us to quickly build a complicated system. With this, you can design interactions that react to people’s movements or actions without directly having to consider the exact mathematical relationship between input and output.

Later on, we will see how you can use regression to control 3 parameters of a granular synth with just 1 slider. Although we could literally use loads. First we are going to look at the Regression Explorer. This will help us get a more intuitive grasp of waht is going on when we create and use regression models. You can use the Regression Explorer on the MIMIC platform.

About this Post

This post is written by Siqi Shu, licensed under CC BY-NC 4.0.