Hi!
To use a package like this, it’s good to know how a usual neural network works, and what all the parts are called. There are many youtube videos to explain things like forward- and backward-propagation. This helps to understand why each step is done.
Normally, the layer of input neurons fire according to the input. This activates neurons in the next layers, until the output layer is reached. Because the activations travel from input to output, this is called ‘forward propagation’. The output layer is like the ‘answer’ to a question. For example, if I activate the input neurons in some way, what is the output it gives?
Then comes the step where you decide if the answer that the NN gave as output was correct. The answer is just one, or a few, activated neurons, and in this step you give the neural network a score for its answer. A good answer gets a high score, a bad answer a low score. The function that does this is called the ‘Scoring function’.
Then you train the network to do better next time: if it received a bad (or good) score, a signal travels from output to input, to adjust the behaviour of each neuron. This is done using differential equations and derivatives. Basically, it goes something like ‘if I adjust the neurons parameters like this, would the answer have been better this time?’. Because this signal travels from the output layer to the input layer, it is called ‘backward propagation’.
The way a neuron decides if it will fire depends on two things:
-its individual parameters, which is just a set of values (‘bias’ and ‘weights’). This is what is adjusted during the training step, and decides how ‘sensitive’ it is to also fire when it is activated by neurons in the previous layer.
-its activation function, for example relu or sigmoid. This is normally the same for all neurons in a layer and doesn’t change during the simulation. This is a hyperparameter that you normally set in the settings of a neural network script.
So, when you use a package or library, normally most of the steps are pre-built for you. You can just tell the library:
I want a NN with 4 layers, each layer has 20 neurons, it uses relu activation function for all layers, and the scoring function is as follows, etc.
This saves you a lot of work. And that is exactly what the code you linked to is doing. So to understand all these steps and their names, helps you to use the library to really quickly create neural network simulations.
Now, you probably know, neural networks have come to be used for a lot of things, and they are part of many bigger applications. They are part of convolutional neural networks, generative adverserial networks, etc. Those kinds of networks can process images and see what is in them, or create pictures of humans that never existed.
In the case of your link, the neural network is used to create an ‘evolutionary algorithm’. In evolution, there is a group of neural networks. Each NN is called an individual and the group is called the ‘population’. Each NN, as before, gets input and uses it to generate answers. A scoring function decides how well it does. But now, the scores of all the individuals in the population is compared, and the worst ones are deleted (on average, there is some randomnes added). The best ones have a chance to be copied, so that the population stays the same size. Sometimes in an evolutionary algorithm, several of the best ones are combined, instead of making copies. But that doesn’t work well for neural networks, because normally trying to combine two neural networks into one of the same size, breaks them completely.
So in theory, this can be used instead of the backpropagation, or it can be used on top of it. Results have traditionally not been very efficient, but it’s an interesting strategy that looks a lot like natural evolution in biology. Personally I expect future breakthroughs in this area.
What you see in those scripts you linked, is a definition of all the steps I wrote above:
It imports the classes it needs from the package library
It defines the hyperparameters as settings. For example, the relu activation function for a particular layer of neurons.
Then it creates a new neural network using the library, telling it how many layers, and how many neurons in each layer, etc.
Then it starts to work training the model: it gives it an input, calculates the output, sends the output to the scoring function, receives a score back, and uses the score or multiple scores for backpropagation (‘learning’). By repeating this proces, the NN or population of NN become better at solving the problem.
Finally it decides it has trained enough, in these scripts simply after X runs. Now it goes to the testing phase: one last time it gives the NN a set of inputs, asks the output and sends it to the scoring function, and finally it reports how well the network(s) did after training.
Then the script is done. Normally you would want to save the Neural Networks you trained, so you can use it to solve problems for you. You know how good it is (or should be) because of the testing phase.
So that’s basically the whole thing. You have to be careful of a lot of things, such as the training set and the test set being ‘independent’ (not the same items from a list used again, etc). But just for learning about this, you can try to get some of these scripts to run, adjust some hyperparameters, neural network sizes, the scoring function, etc. Look at some online courses about neural networks. You will learn a lot and it’s super interesting!
One note is that, it’s very easy to create simulations that run for days, or even longer! Computers are fast, but not fast enough! Evolutionary algorithms especially are very heavy to run. Normally, you would not run this kind of program on a CPU, but on a GPU with parallel processing. A common language to do all this in is Python, which has libraries to accomodate this. I am a big fan of lua, but the roblox API does not allow parallel GPU computations (yet ;P), and so you can only run very simple neural networks on here (which is fine, for now! ). Training a neural network is the heaviest part, when you use it to just give an answer it is not actually that heavy. So you could train a neural network elsewhere, import the parameters of all neurons, and use it in a game. You could also use HTTP-service to train bigger NN in realtime on your own system. But very small NN are fine to train in ROBLOX if you are not in a hurry.
Hope this helps, I highly recommend diving more into this, the future of AI is huge!