The AI / Neural Networks extension is finally here!
Iām warning you right now. THIS IS A LONG POST. It is well over A THOUSAND WORDS. If just the explanation of the extension is THIS long, the extension must be much more complicated! This is not meant for beginners, although with dedication you can definitely learn.
Iām so excited to finally unveil the extension!! It took me a while, and you can see my progress here in the making thread.
Blocks
MakeNet
Parameters:
- Inputs: The number of inputs of your neural network
- Outputs: The number of outputs in your neural network
Creates a neural network in the form of a nested array. See image 1 for a visual description. Each value is automatically set to 0.
RandomNet
Parameters:
- Inputs, Outputs: See MakeNet description
Creates a neural network in the form of a nested array. See image 1 for a visual description. Each value is automatically set to a random number between 0.00 and 1.00.
Mix
Parameters:
- Net 1: The first neural network
- Inputs, Outputs: See MakeNet description
- Net 2: The second neural network
Randomly mixes two arrays together, mimicking how animals share DNA with offspring. Creates a net that is similar to both parents. Most useful for creating a batch of neural networks similar to the best 2 nets so you can pick the best one using the āAccuracyā function described below. (This is how the neural networks reproduce and become better)
Think
Parameters:
- Net: The neural network that is doing the thinking
- Inputs: An array of the inputs being fed into the net. Even if there is only one input, this should still be an array.
- Outputs: See MakeNet description.
Feeds inputs into the neural network to get its response. This is the most complicated part of the neural network, beware! If you want a quick description, a neural network is actually a REALLY big math problem. You run the inputs into the neural network, and get a result between 0-1 for each output. You could also think of it as the inputs being the āeyesā of the net, it takes in what it sees, processes it, and spits out a response such as ā0 - run!!ā or ā1 - Fight!!ā. Iāll be happy to describe in detail how it actually works, but Iām not the best teacher, so try this website!
Accuracy
Parameters:
- Net: The neural network you are testing.
- Inputs, Outputs: See MakeNet description.
- InputOutput: An array, filled with a bunch of arrays, which are each filled with an array of inputs and an array of desired outputs each.
Okay, this one sounds complicated, but itās really just a shortcut to help with training! The Input/Output array is formatted uniquely, so check Image 2 for a visual representation. Each array inside of it has an array of the inputs the neural network is given and an array of the outputs that you WANT it to give out. This is like a test sheet for the neural network, with questions and answers! The function takes the average amount of error of the neural networkās answers. If the function returns 0, or something close, then it has high accuracy. If the value is farther from 0, such as being closer to -1 or 1, then the net has low accuracy. (For all of you math-brains out there, yes, this could be better measured with standard deviation instead. Maybe a future update, but it works for now.)
How to use a Neural Network
Itās great to know what the blocks are, but you probably still donāt know how a neural network answers a question. Hereās a step by step to use your own neural network!
1. Think of Inputs and Outputs!
Think of the outputs first: What do I want my Network to put out? In my color guessing game, the frogs had to output 1 number between 0-1 representing how much they thought you liked that color.
For the inputs, think of what information your Net needs to know to figure out what to do. A tip for making the net work better is making your inputs more āspecializedā- basically, choose a form that works best. Thatās not very intuitive, but hereās an example: In a fighting game, instead of just giving the enemy the x and y coordinates of the player, instead gave it the DISTANCE of it to the player on the x and y axes. This is more useful info! In my color guessing game, the frogs had to know the color that was on the screen, which is represented in RGB format. RGB values are 3 values ranging from 0-255, but all inputs and outputs are between 0-1, so I divided the numbers by 255!
2. Get the Inputs and wanted Outputs! (The data / the test)
This step will vary a lot depending on what youāre using the net for. (Feel free to ask me if you need help!) For the color guessing game AI, I gathered a bunch of inputs in the form of the RBG values of a color, and gathered a bunch of wanted outputs in the form of a 0-1 value of how much the player liked the color. You can then run all of this data through the accuracy block to get the netās score!
4. Run the tests, pick the 2 best nets, mix them, and repeat!
On each of your many neural networks (yes, many! I suggest at least 5, but more speeds up the process.) check their accuracy. Pick the 2 networks that have the best accuracy (the ones with the least distance to 0, which you can get by taking the absolute value of the accuracy) and mix them a few times. Test the new mixes/offspring and pick the best 2 of THOSE nets. Repeat until satisfied! See image 3 for details.
5. Show off your super awesome net!
Show the player your net! In the AI color guessing game, this means telling the player what the AI thinks your favorite colors are. This is mostly up to you, but Iām happy to help!
Images
(Did you like my little images? :3)
There will be a demo game coming soon! AND a YouTube video about this extension for my online school newspaper! (If you give me permission in your reply, I would love to include your comments on this extension!)
Seriosly, thanks for reading my super long extension. It has taken me nearly half a year to get this out. One of the key features even had to be scrapped simply because makecode arcade couldnāt handle that many computations. This is probably the most complicated coding, math, or research project Iāve ever done! Iād love to hear feedback, good or bad. Iām 100% open to help you use the extension! I just cant wait to have someone put my research to good use!
ā Randomuser / Dragondoodle