Quirky neural network AI

Started by
7 comments, last by Emergent 11 years, 4 months ago
I'm trying to teach a neural network to play pong and so far it's not going very well. I'm using supervised training where I play against myself and every time I move the pad that the AI is going to use I save away some data and when I decide I've gathered enough data I use that for the training.

The data I save away is the balls x,y position as well as ball direction x and y. The y position of the pad. This is what I use for input.
If the pad moves up then I set target outputs for the two output neurons to 1 and 0 and if I move down I set it to 0 and 1.

Its a feed forward network and so far the best results has been that if the ball is moving downwards the AI moves downwards and the ball goes upwards the pad moves upwards. But it wont take in consideration of the balls current position meaning that the pad moves either towards the bottom or the top of the screen.
Advertisement
Feels like there's not enough information here.

How is the network assessing success/failure and how heavily does it adjust its weights? Or is it just using the input you're giving to it as 'good'?

What is the set of behaviors is it selecting from?
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Can your paddle brake properly?
I think the best set of behaviours to choose from is "at time T, paddle will be at position Y with velocity V", abstracting (and delegating to an exact controller) the acceleration and braking of the paddle: three very well behaved continuous parameters making every possible spin shot accessible. Note that the position of the opponent's paddle should be an input of your neural network, while own paddle position is unimportant as long as the movement remains feasible.

Omae Wa Mou Shindeiru

You could try passing in the relative ball position instead.

o3o

Hello smile.png

I'd try this input (edited) :

  • y position of the ball relatively to the pad ( -1 for below , 0 in the y pad area, 1 for above)
  • y component of the velocity vector of the ball (-1 for going down, 0 for horizontal move, 1 for going up)

... assuming the response only depends

  • on the fact that the ball is above, covered by the pad, or below the pad,
  • on the vertical projection of the direction the ball follows.

It can seem over-simplified, but I really think this input encoding can work, and can permit a fast convergence of the network.
If you would have to output an analog velocity of the pad, you would need a more complex input encoding.

In your output you can also add (0,0), meaning 'no move'.

It seems very interesting, good luck !

PS : A key point is to express positions, distances,...., in the actor frame, as stated above. Another point is to make sure you don't feed the network with values such as abs(value)>1. The first thing to do is to make the learning process successful. Then you can complexify the problem.
I'm trying to teach a neural network to play pong and so far it's not going very well. I'm using supervised training where I play against myself and every time I move the pad that the AI is going to use I save away some data and when I decide I've gathered enough data I use that for the training.


So in fact you're not training the network how to play pong, but how you play pong. It could also be interesting to try the following approach: Let two AIs play against each other. Each time one of them loses a point, take some snapshots of it's actions and use them as training samples. This way you could run training on the fly and watch the AIs getting better. Note that this is still supervised learning.


Hello smile.png I'd try this input (edited) :
  • y position of the ball relatively to the pad ( -1 for below , 0 in the y pad area, 1 for above)
  • y component of the velocity vector of the ball (-1 for going down, 0 for horizontal move, 1 for going up)


This wouldn't work. The network could never learn to account for the ball bouncing off the wall. Some relation to the wall is crucial. I'd go for (x,y) position of the ball, (x,y) velocity of the ball and y position of both pads. Maybe even y velocity of the pads. More data is usually better for ANNs, at least if you know there's additional information in it.

A great read on neural network training is Yann LeCuns Efficient Backprop. It's lengthy, but most interesting are the first ~10 pages of chapter 4. Some tips for a successful ANN:

  • Use online training (adapting the weights after each sample), but be careful with the learning rate
  • Track the error on the training and testing data sets. Are both converging?
  • Scale your teacher values so that they don't lie in the saturated area of the sigmoid function. E.g. I'm assuming you are using the logistic function 1/(1+e^(-x)). Teachers of 0 and 1 are evil! 0.2 and 0.8 would be better! For even better results use the scaled tangens hypercolicus as mentioned in the paper I linked.
  • Scale your input values to have a mean of zero and roughly the same covariance.
  • Visualize your network. You'd be surprised how many anomalies you can discover by having a graphic representation of your weight matrices!


PS: Sorry for digging up a slightly outdated thread, but I felt there was a lot of information missing here.

"The network could never learn to account for the ball bouncing off the wall" [/quote]
The network hasn't to account for that .... if the pad can follow the ball, it is quite a big step at first.
You can build the association table quite easily and see it would work .... there are only 9 different input vectors to be associated to 3 responses rolleyes.gif !

0 and 1 as targets to be learned with sigmoid function are evil, I agree, but there is a cleaner solution than using 0.2 and 0.8 : using a decay in the delta rule

The network hasn't to account for that .... if the pad can follow the ball, it is quite a big step at first.


Only if the speed of the ball is less or equal to the speed of the paddle. If the ball is faster, the player/AI has to anticipate the position and needs a way to know where it bounces off.

0 and 1 as targets to be learned with sigmoid function are evil, I agree, but there is a cleaner solution than using 0.2 and 0.8 : using a decay in the delta rule.


Mathematically, it is best to train the network towards target values with the highest first derivative of the sigmoid. This is where the biggest weight changes occur, this is where it can learn fastest. While weight decay does help too, it is actually counter-productive as it doesn't accelerate the learning.

I play against myself and every time I move the pad that the AI is going to use I save away some data [...]

The data I save away is the balls x,y position as well as ball direction x and y. The y position of the pad. This is what I use for input.
If the pad moves up then I set target outputs for the two output neurons to 1 and 0 and if I move down I set it to 0 and 1.


[quote name='dominik81']
So in fact you're not training the network how to play pong, but how you play pong.[/quote]

Interesting.

There is a whole area called Apprenticeship Learning that is very interesting. The name that pops to my head is Andrew Ng; he has a nice paper here (PostScript format. Use Ghostscript to view it, or view online with Google Docs ). The idea here is not to directly learn what the player does in each state, but rather to learn which states the player is trying to get to. Another good paper would be this one.

Moving on...

So you're assuming that the state of the game is the ball's position and velocity, together with the player's paddle position. What about the other player's paddle position? It would seem that you would also need that to encode the whole state.

Anyway, basically what you're doing is using two binary classifiers (which together can produce four output values: 00, 01, 10, and 11) to learn one of three things (UP, DOWN, or STAY_STILL). In your case, you're mapping 10 to UP, 01 to DOWN, and (I guess?) both 00 and 11 to STAY_STILL. Seems reasonable. It wouldn't be a bad idea to try some easier-to-train classifiers (than ANNs) on the problem, like SVMs.

There's also nothing to stop you from doing this in a "lazy learning" way by just searching for the closest data point and doing whatever was done there (or take the k nearest neighbors and use a majority-rules scheme, or something of that sort).

Both approaches will be much faster than multilayer ANNs.

This topic is closed to new replies.

Advertisement