The following guide shows you the five steps needed to build a machine learning object and use it. Each step has both instructions for JavaScript and C++.

You can find the full C++ example as HelloRapidMix in the /example folder of the C++ downloadable. You can find the full JavaScript example on CodeCircle here.

What are we doing in this example?

It is possible to think of a machine learning algorithm like any other algorithm or transfer function — the user provides an input, the algorithm is applied, and a specific output is returned.

For this example, we are going to try to make a machine learning algorithm, or model, that takes MIDI note numbers as input, and outputs the frequency in Hertz that corresponds with that note. We don’t really need machine learning to do this conversion as there’s a formula we can use. However, we’re looking at a familiar case and seeing if and how we can reproduce it in a new way.

1. Download & Install

Client-side JavaScript:



Download following these instructions.

If you’re using JavaScript, just include the tag in your <head> element. If you’re using C++, you need to include the rapidmix header file.

2. Create Object



There are several kinds of machine learning we can use – and you can find our more about them on our general concepts page. For this example, we’re using a regression model as we wish to create new outputs based on our input, rather than the closest match from what we tell our model.

3. Populate training data



In order to train a model to understand our input, we need to give it some training inputs and the expected outputs. Of course, no machine learning algorithm is going to be able to reproduce an algorithm with one point, so here we add 5. Note in C++ that addElement() expects input and output to be given as a vector out doubles.

4. Train object



Training is the process of adjusting the internal parameters of a given model to the specific training data provided. Ideally, the trained model will give a reasonable approximation of the desired output, given a specific input. The actual computation that does the training can be very different for different algorithms. Neural Networks can take a relatively large amount of computation to train, but then they run quite quickly. Other algorithms offer different compromises between training and running efficiencies. Now our model is good to use…

5. Use object with new inputs



Once an algorithm is trained, you can give it input and get output back.

Finishing up

Congratulations, you’ve now created your first model, trained it, and used it!

You might notice that the frequency values are not very similar to what we would hope for, if you know what the formula. It turns out that the default staticRegression algorithm is not very good at representing this type of function. For better performance, we might try a different algorithm

Next steps

  • Learn about the xmmStaticRegression algorithm for a more accurate result
  • Check out more JavaScript guides
  • Check out more C++ guides