Here is a quick example that uses a neural network (regression) to generate a MIDI note to frequency in Hertz converter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#include <iostream> #include "rapidmix.h" int main(int argc, const char * argv[]) { //Machine Learning rapidmix::staticRegression mtofRegression; //Create a machine learning object rapidmix::trainingData myData; //Create a place to hold training Data //Setting up the first element of training data std::vector<double> input = { 48 }; std::vector<double> output = { 130.81 }; myData.addElement(input, output); //More elements input = { 54 }; output = { 185.00 }; myData.addElement(input, output); input = { 60 }; output = { 261.63 }; myData.addElement(input, output); input = { 66 }; output = { 369.994 }; myData.addElement(input, output); input = { 72 }; output = { 523.25 }; myData.addElement(input, output); //Train the machine learning model with the data mtofRegression.train(myData); //Get some user input int newNote = 0; std::cout << "Type a MIDI note number.\n"; std::cin >> newNote; //Run the trained model on the user input std::vector<double> inputVec = { double(newNote) }; double freqHz = mtofRegression.run(inputVec)[0]; std::cout << "MIDI note " << newNote << " is " << freqHz << " Hertz" << std::endl; return 0; } |