Cake AI v2

Off topicProgramming → Cake AI v2

WIP

So over a year ago, I posted a thread about an “ai”, which was basically just a terrible version of an answerbot. It didn’t think, learn, or do anything other than respond to hard-coded keywords. However, I have somewhat recently begun looking into legitimate artificial intelligence, and after many months of work, I have come up with a crude one of my own. I’m going to divide this post into two sections, the “technical” side (which isn’t too confusing - it just explains what true AI is and how it basically works) and the “actually interesting” side.

###Technical Stuffs###

This isn’t too exact, because the majority of the math used is probably too complex for the majority of people reading this. If you want to know more, tell me in-game.

Artificial intelligence is a program which imitates the learning process of humans. The most common (or maybe the only) kind of this is called a “neural network,” a system of “neurons” which take inputs, modify them, and produce outputs. More specifically, a neuron will be given at least one input, which could be a number, a letter, or even an image, applies a certain algorithm to it (called an activation function), and gives the modified data as output.

The type of neural network I have created is called a feed-forward network. This means that there are multiple “layers” of neurons, and the data is passed directly from one layer to the next from beginning to end. Here’s a diagram which will hopefully explain this well. network diagram In addition to different types of networks, there are also different types of neurons. The ones which I am using are called sigmoid neurons. These take numerical inputs and output a number between 0 and 1 (Pro tip: when evaluating if something is true or false, if the output is < 0.5, it’s false, and if the output is >= 0.5, it’s true). Sigmoid neurons use a certain activation function to modify its inputs, called the - wait for it - sigmoid function.

All of these parts work together to make a network which can learn how to do basic tasks.

###Less Boring Stuffs###

At the end of this post, I will give a link to my prototype of a neural network. It is not finished, and probably won’t be for a while. In this section, I will explain how to use the program.

####Step 1: Making/Loading training data####

Most neural networks use both “training” data and “testing” data. However, I haven’t coded support for “testing” data yet, so only “training” data can be used. When you open the program, you will see two buttons on the right, “Make Training Data” and “Load Training Data.” To make your own, click on the first.

You will be presented with three text boxes. The first asks for a number of sets. This refers to the number of input/output groups your data will have. The other two are fairly self-explanatory. For example, you could an xor table with four sets, two inputs, and one output, and it would look like this:

Set Input 1 Input 2 Output
1 0 0 0
2 0 1 1
3 1 0 1
4 1 1 0

Once you finish setting that up, click on “Generate Chart,” and an empty table will appear. Fill in your data, then choose to save it as a data file (the format is .ydf - yum data file) or confirm and use the data. Remember - due to the nature of sigmoid neurons and the fact that I haven’t had the time to fix this, outputs cannot be larger than 1, or else the network won’t function properly.

Alternatively, if you already have a data file (for your convenience, there are some in the Github project at NeuralNetworks/NeuralNetworks/src/Example data), click on “Load Training Data” and choose the file.

####Step 2: Setting up the network####

Neural networks cannot always learn the given data with only input and output neurons. You need to make the “brain” larger so it can do more, using what are called “hidden layers” (see diagram above). All of the examples in the Github project other than “and.ydf” require at least one hidden layer. Put the number of hidden layers you want into the text box on the main window, and then give how many neurons you want in each of the new boxes that appear. It’s okay if you don’t know much about how the neurons work - usually, the more layers and/or neurons you have, the better the program is at learning the data you gave, but it will also become slower (but usually not by much). Once you have finished the setup, click “Go!” and watch the network learn the data you gave.

####Step 3: Interpretation and revision####

When you start the program, you are shown a crazy mix of changing numbers and buttons. The changing numbers are your outputs, and the stable ones are your inputs, as you could probably figure out. If everything was set up correctly, the outputs should be approaching the ones you gave. You can pause and resume the process. If the numbers are not getting closer to the ones you gave, then “Stop” it entirely with the respective button and close that window. You can then revise the number of hidden layers/neurons.

WARNING: After you have closed the output window, you need to re-make re-select your training data, as it doesn’t currently remember what you chose.

####The End####

Hopefully I explained everything well and clearly. I know that there are many limits in functionality, but I will fix those whenever I have the time.

See the project on github here. There is a download link for the executable in the README file. If you see any bug or potential issue, or have any questions, please contact me in-game or on this thread.

-Yummy

Looks fantastic! :D I wish I could do this kind of things ;-;
Well, this took me a lot of pain and tears, so it’s definitely not something that comes easily. Thanks for the feedback, though!
This is awesome!^teach^me^java^senpai^pls
All right, I updated the thread to give a tutorial on the program.

Ah, I wish you added some comments explaining what the calculations are doing. It would be easier to understand that way. Depending on whether all neurons in all layers should process the same kind of data (numbers, images..) I would suggest that you come up with an interface to support different implementations. Just an idea that comes up would be piping streams. That might be a bit expensive if you operate on single numbers though.

Also, you should consider replacing all those List<Double> with gnu.trove.TDoubleList to avoid excessive boxing/unboxing and the memory strain as well as garbage collection pressure that it introduces. What IDE do you use?

Finally, I gave you some tips and criticism solely on your java, not on the AI logic, because I don’t understand it at a deep level. I’d like to learn more though. Nice job :)

You’ll need to give me some time to get an in-depth explanation. Pretty much every source online is very complicated and causes confusion, even though the concepts aren’t that difficult. I will definitely have documentation for it by the time I finish with the GUI interface, but I may have it done before then.

On the subject of input types, it is much more difficult than one would expect. Images, for example use their own type of network (convolutional) which has a much different setup than a numerical one. Actually, my personal goal is to make a convolutional neural network, so I will know more in the future.

Thanks for the tip about double lists; I hadn’t heard of gnu.trove. My IDE is Eclipse.