3
$\begingroup$

After learning the basics of neural networks and coding one working with the MNIST dataset, I wanted to go to the next step by making one which is able to play a game. I wanted to make it work on a game like slither.io, so in order to be able to create multiple instances of snakes and accelerate the speed of the game, i recreated a simple version of the game:

enter image description here

The core features being almost done, now comes the work on the AI. I want to keep the script very simple by using only numpy (not that tensorflow, pytorch or spark does not interest me, but I want to understand things at a "low level" before using those framworks).

At first, I wanted the AI to be able to propose an output by reading pixels. But after some research, I don't realy want to get into convnet, recurent and recursive neural net. I'd like to re-use the simple feed forward NN I did with MNIST and adapt it.

So instead of using pixels, I think i'm going to use the following data:

  • {x,y} snake's position
  • {x,y} foods positions
  • food value
  • Time, in order to get the snake eat the more food in a short time.
  • Distance from the center, not die outside the area

enter image description here

That's a lot of different data to handle !

1/2 Can a simple FNN handle different kinds of Data in the Input layer ?

enter image description here

Moreover that comes an other problem:

2/2 Will it properly work with a variable number of inputs?

In fact, in a specific area around the snake, the quantity of food will be variable. I came accross this post that kinda answer my question, but wath if I want the Neural network to forget some input if they are not being used, can Dropout be of any use in this case. Or the weights value (correcting toward zero) of these Inputs will be enough?

$\endgroup$
  • 1
    $\begingroup$ Welcome to AI! (Nice work, btw. I can testify from firsthand experience that you're making a strong choice foregoing frameworks at the moment in favor of fundamental understanding.) $\endgroup$ – DukeZhou May 10 '18 at 20:30
1
$\begingroup$

In short:
1/2 -> ANNs don't have problems with "different types" of data as long as they are represented using real numbers: the inputs for your ANN represent lengths and are easy to understand and process.
2/2 -> The variable number of inputs is a little bit more tricky. In general it is not a problem either. The net will compensate the absence of some inputs from time to time (when food is too far away?). You don't necessarily have to use RNNs for your case.

In full:
I think that the inputs of your net could be improved.

When building a new ANN you always have to consider few aspects:

  • Neural Nets are just stateless functions that map inputs to outputs.
  • There is no magic here: with good inputs you can get good outputs.
  • Think about how you would write an algorithm to solve that problem. Which would the best set of inputs be? Can some computation be done somewhere else? (using other ANNs, if you want to create ANN chains, or traditional algorithms).
  • Preprocessing can do a big difference!
  • Think about the space separation that your inputs require/cause.

All these points are related one to each other and they're only about the inputs you're providing to your net.

Now, keeping these points in mind, you can check again your inputs to see if you can improve something:

Objective 1: eat food
To be sure the snake will get toward the food we definitely need to pass the ANN the position of the food. But you're sure that a long list of coordinates is the best option? Maybe the coordinate of the nearest food can be enough.
If you were THAT snake what would you like to receive? Or what would you receive if you were a real snake? Imagine your snake has a sensor that determines the best place to get food. It'll be like a compass, outputting only one value, from 0 to 365 (or choose whatever range you like). This compass will point at the closest bigger cluster of food or at the closest food. Remember: 1 value is always better than N and you should try to avoid a variable number of inputs, it's always a smell that something doesn't go well.

Objective 2: don't die
The distance from the centre works well. It's a simple threshold that the ANN will consider when moving, that's effective and easy to achieve. Why don't you also add another compass that will always tell you the position of the centre instead of the coordinates of the snake? In this way you've used 2 values related to each other instead of 3, more difficult to decipher for an ANN.

The time is not really necessary. You're inserting a value that isn't related to any other, or the environment, or the food. Any possible behaviour is not influenced by its value (if the ANN knew that it has only 15 seconds left, it wouldn't change its behaviour. The same if it knew that it's "alive" since 1 minute or 4000).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.