Genetic neural network plays FlappyBird

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
MateConBigote
Prole
Posts: 3
Joined: Tue Aug 08, 2017 3:34 am
Contact:

Genetic neural network plays FlappyBird

Post by MateConBigote »

I started learning about neural networks, so I decided to create a neural network in Love2d capable of learning to play Flappy Bird.
After programming a lot this is what I got, I hope you like it.

Git hub link
Attachments
AutoFlappyBird.love
(21.07 KiB) Downloaded 368 times
Last edited by MateConBigote on Tue Oct 31, 2017 2:38 pm, edited 1 time in total.
English is not my first language and I never took an English class, feel free to correct any error or misspelling.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Genetic neural network plays FlappyBird

Post by zorg »

Seems like an interesting project, though the overall file structure is weird, mainly because you're not including everything in the .love as you normally should.

If it was dofile that failed you there (and it seems likely), then you should use require (or love.filesystem.load, though that doesn't execute the chunk it loads), since the require paths of löve do search inside the .love archive, whereas standard lua io functions don't.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
MateConBigote
Prole
Posts: 3
Joined: Tue Aug 08, 2017 3:34 am
Contact:

Re: Genetic neural network plays FlappyBird

Post by MateConBigote »

Actually the structure of the code was conceived in this way, but now that I think about it, it was not a very good idea since it leaves the program organized in a very confusing and difficult way to explain.
Now I'm working on changing the structure in a more standard way.
English is not my first language and I never took an English class, feel free to correct any error or misspelling.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Genetic neural network plays FlappyBird

Post by vrld »

Fun project that leaves room for so much experimentation. Here are a few suggestions:

For the neural net:
  • Use different activation function, for example ReLU, leaky ReLU, sinc, etc. (here is a list). How do the different activation functions affect how fast the computer learns to play the game?
  • Use different activation functions for each layer. Or even for each individual neuron.
  • Use a different number of hidden neurons. How many neurons do you need at minimum?
  • Use a different number of hidden layers. It can be shown that you need only one hidden layer, but do more layers help or hurt training?
For the genetic algorithm:
  • Use tournament selection instead of random selection of parents for recombination. How does that affect the learning speed?
  • Use a different recombination strategy, for example, choose individual weights (not whole layers) randomly from either parent.
  • Select more weights from the fitter parent.
  • Use a different mutation strategy: instead of randomly replacing a whole layer, randomly replace individual weights.
  • … or randomly change the activation function.
  • Add a small random offset to a random weight, instead of replacing the weight entirely.
  • Use elitism instead of randomly killing half of the birds: always keep the best of all birds.
And lastly, it might be fun to look inside the head of a bird. Here is a function that draws the output of a net for a range of possible inputs (aka the decision surface of the net):

Code: Select all

function paint(bird)
local img = love.image.newImageData(300,300)
  img:mapPixel(function(x,y)
  -- input x is always positive, input y may also be negative
  local input = mx{{x, y-150}}
    local result = mx.replace(mx.mul(input, bird.hiden), sigmoid)
    result = mx.replace(mx.mul(result, bird.output), sigmoid)
    result = mx.getelement(result, 1, 1) * 255
    return result,result,result,255 -- maybe add a color palette here?
  end)
  return img
end
You can use this function to plot the brain of the best and worst birds in your population. Comparing the images, does that tell you anything about good solutions?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests