I made a GANN program for evolving creatures. The genes that get put into the GA for each ind are the weights that go into the neural net for each creature. The NN is a basic 1 hidden layer NN with bias neurons and it uses TANH so the weights are from -1 to 1. The GA uses .8 crossover rate (.3 elitism) and .003 mutation chance per gene/weight. Ranked selection is used and 1 point crossover.

The creatures go after food that spawns in a random location after pickup and there are also traps to avoid that done move. A food raises the fitness by 1 and the trap makes it lose 1 fitness point. They start at 1 fitness (health) and if they hit to many traps and get to 0 they die and their genes aren't used in the next evolution. But not many die anyway only like 5 to 10/50 per gen. There are 20 of both traps and food and 50 creatures. There are two sensors on the creatures. One on the left side about 30 degrees from the center face and one on the right. The inputs are each sensors dis from the closest food and from the closest trap.The outputs are 2 numbers. I pick which is highest get the abs value and multiply it by a max angle of 15 degrees and the creature rotates by that amount either right or left depending on which output neuron was the highest.

Before I added in the traps the creatures were very good at getting to food quickly and accurately. And they learned how to do it relatively quickly per test (after like 15 gens they were very good). Then I added in traps and just added the inputs that were the distances from the sensors to these traps just like with the food. With both inputs to food and traps they no longer learn. They just kind of make circles or do random stuff. They aren't dying that often (their fitness starts at 1 but if they hit food before they hit a trap they wont die just lose a fitness) but they aren't learning anymore. I tried normalizing (dividing by the env square side length) but didnt change anything. So is the issue with the inputs or something else?


1 Answer 1


If I understand well, your neural net have 4 inputs. But let's take this example :

  • The black circle is your creature
  • Grey circles are your sensors
  • Green circle is food
  • Red circle is a trap

I should learn how to use gimp

Does the left sensor "see" the trap closer than the food ?

If yes, you're doing it wrong

A better way to do it would be to "simulate" real eyes, like this, where each sensor can only see what is in its field of view

Okay, okay, I stop using images !

Your neural net can take 2 inputs per sensor, as you did, with the distance to the closest food/trap it can see.

A second thing to try would be to only take in account the closest item for each sensor.

Another interesting thing to do would be to decrease the fitness over time, avoiding passive bots

  • $\begingroup$ Thank you! This is what I was looking for. Yeah I didn't have cones of vision for each sensor. I will try adding this and will report the results. Also one last thing. Is there a reason why normalizing the just food inputs screwed everything up? Even without the trap problem when I divided the dis of each sensor to the closest food by the env length (so it would be btwn 0 and 1) it messed it up. But I thought normalizing helped or at least didn't hurt. $\endgroup$
    – Liger
    Commented Dec 15, 2015 at 1:57
  • $\begingroup$ I don't see any reason why normalization could hurt your neural network. Have you tried to print the normalized inputs, in order to see if it is not due to the floating point lack of precision ? By the way, normalizing wouldn’t be very useful in this case, because all of your inputs are in the same order of dimension, since they all come from the same sensor type. Normalization usually helps when, for example, one of your input goes from 1 to 10 and the other from 1 to 1000. $\endgroup$
    – 4rzael
    Commented Dec 15, 2015 at 10:11
  • $\begingroup$ There is a loss of precision when the inputs were normalized between 0 and 1. Its not a huge loss but maybe enough to cause problems. One thing i have noticed is when i don't normalize the inputs (they are usually between 100 and 200 in this case) after they go through all of the weight stuff and the tanh activation function of the hidden layer the outputs of the hidden layer are pretty saturated. Usually they are 1 or -1 or very close. By the final output however they aren't usually saturated and are normal floats between -1 and 1. I'm not sure if this matters/helps the net or what, $\endgroup$
    – Liger
    Commented Dec 15, 2015 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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