5
$\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 frameworks).

At first, I wanted the AI to be able to propose an output by reading pixels. But after some research, I don't really want to get into convnet, recurrent, 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 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!

enter image description here

My questions

  1. Can a simple FNN handle different kinds of data in the input layer?
  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 across this post, which kinda answers my question, but what 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 value of the weights (correcting toward zero) of these inputs will be enough?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

In short

  1. 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. The variable number of inputs is a little bit more tricky. In general, it is not a problem either. The net will compensate for 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 network could be improved.

When building a new ANN, you always have to consider a 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 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$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .