Advertisement

AI Ideas for Air-Hockey Simulator

Started by June 10, 2002 10:32 AM
39 comments, last by AJFleming 22 years, 5 months ago
quote: Original post by InnocuousFox
Hey Steve... you think we can start a PayPal account where we can take up a collection to send Ol'' Timkin to the GDC next year? I know you were lamenting his absence while we were there. Let''s do something about it! I want his ass in a roundtable!


I may be there yet Dave! I can''t say much at the moment... but I''ll keep you posted!

Cheers,

Timkin
Hi Guys,

everything seems to make sense - although I''m getting confused as to what the function of the Kalman filter is going to be. By simply adding noise to the observations we have already added uncertainty to the system haven''t we? By passing these noisy observations through the perfect prediction system, we should get noisy predictions - or have I missed something along the way?

cheers,

Adam...
Advertisement
quote: Original post by Ferretman

Completely off topic, of course, but this quote is from one of my very favorite movies of all time. "The ''Burbs" is right up there with "Neighbors" IMO.



I love that movie

"There go the God Damn brownies."

"I''ve never seen that. I''ve never seen anybody drive their garbage down to the side of the street and bang the hell out of it with a stick. I''ve never seen that."
oh hai
quote: Original post by AJFleming
By passing these noisy observations through the perfect prediction system, we should get noisy predictions - or have I missed something along the way?


Yes, exactly. Of course, I haven't gotten onto a noisy process model yet, which reflects the fact that the AI agent doesn't have a perfect model of puck motion in it's mind. This creates more uncertainty in it's predictions and it's state estimation.

quote: Original post by AJFleming
everything seems to make sense - although I'm getting confused as to what the function of the Kalman filter is going to be.


The Kalman filter is just the mathematical tool for solving the system of equations you get for the Linear Dynamical System. Hopefully this will be made clear by my next installment.Because you've added noise you don't have a deterministic system any more, you've got a stochastic system. While the puck might be in a single state the AI agent will hold a set of beliefs (a probability distribution) as to which states the puck could be in and with what probabilities.

After prediction, what will happen is that the AI agent will have a range of possible states that it believes the puck will be in and a probability for each (or this can be viewed as an estimate of the most likely state and an uncertainty measure for that estimate). Using these beliefs and its desires (to score goals, trick the opponent, defend its goal, etc) the AI will choose an action. How it chooses the action is a whole other story! For the moment we can just focus on embuing the AI agent with beliefs that contain uncertainty.

Cheers,

Timkin

[edited by - Timkin on June 13, 2002 9:16:47 PM]
So, where were we...

The basics of a Kalman filter (part 2)...

In part 1 we created a simple linear dynamical system for the hockey puck that incorporated only observation noise. It was given by the following equations:
s  (t+dt) = Fs  (t)y(t) = H(s  (t)) + n  (t)    |1  dt|F = |     |   H = |1  0|   n = |n1|    |0   1|  


There was an error above which I need to go back and fix... and that was that we actually want H to be a 1x2 matrix, not 2x2 since we only observe 1 of the 2 variables. Thus n will be a scalar noise variable, not a 2x1 matrix. Sorry for any confusion.

Now, I want to complicate things just a little more. Let''s assume that are hockey playing agent doesn''t have a perfect model of the physics of the world. Pucks generally go in straight lines (except when they bounce), but spin can make them swerve a little. this doesn''t have to be the case in the actual physics model of the game, only in what the hockey agent THINKS the physics model is.

To accomplish this, we add noise to the process model (the first of the equations above). So,
s  (t+dt) = Fs  (t) + Gw  (t) 


But, do we add this process noise to the position of the puck or to its velocity? We could do both, but we actually only need to add it to the velocity, since the belief in the position depends on the belief in the velocity. Uncertainty in the velocity will flow through to the position.

So, we set

    | w1  |w = |    |    | w2 | 


and we define G so that only noise is added to the velocity. So

G = |0  1| 


Now, we need to return to the idea that this noise is Gaussian. A Gaussian (Normal) probability distribution is characterised by two cumulants : the mean and the variance (covariance for multidimensional distributions). Now, for additive noise, it needs to have a zero mean. The covariance though is up to us to choose. Since s has dimension two (1 dimension for position and 1 for speed) then the covariance for the process noise will be a 2x2 matrix looking like

    |q11    0|Q = |    |    |0    q22| 


and the covariance for the observation noise will be

R = r1 


since n is a scalar.

We also need to know the initial value of the cumulants for the probability distribution over the state at t=0. These are a free choice, so set s (0) to whatever you want to be the starting position of the puck and set P (0) ( the initial covariance of the state probability distribution) to say

    |1  0|P = |    |    |0  1| 


So, now that we have all of this, what do we do with it??? Well, we apply the Kalman filter equations!

For the forward pass filter we have two steps:

1) Prediction: Compute what we think the cumulants of the state probability distribution are going to be just before the observation is made (using our last known state and our process model); and,

2) Estiamtion: Bias this prediction by the actual noisy observation we make.

Let''s assume that our first observation occurs at t=1. So, we need to predict the cumulants at t=1.

This is done using
s  pred = Fs  (t-1)Ppred = F*P(t-1)*F'' + G*Q*G'' 


where the '' denotes the transpose of the matrix.

Now, the estimation step is only slightly more complex.

We need to compute a few intermediary quantities... don''t worry what they mean.

e = y - H*s pred
M = H*Ppred*H'' + R
Minv = M-1
K = Vpred*H''*Minv

and finally

s (t) = s pred + K*e
P(t) = (I - K*H)*Ppred


That''s enough for now. You can have some time to digest this and ask questions if anyone is still interested!??? Over the weekend I''ll add in the backwards pass filter, which you need to complete the system. I''ll also talk about how you can handle the bouncing behaviour the walls create!

Cheers for now,

Timkin
Hi Timkin,

just a quick post, since I haven''t had time to digest things properly - but definitely still interested. Thanks for taking the time to lend a hand - I really appreciate it.

cheers,

Adam...
Advertisement
Timkin,

Thanks for taking the time to post all this info on the Kalman filter (maybe someone should gather up everything at the end and make an article out of it, wink wink, nudge nudge ). I''ve taken higher level prob/stat courses, and one of the hardest things to do is actually apply the equations to real world situations. This is making me want to do an air hockey game :D

"I''ve never seen that. I''ve never seen anybody drive their garbage down to the side of the street and bang the hell out of it with a stick. I''ve never seen that."
oh hai
quote: Original post by Zul
Thanks for taking the time to post all this info on the Kalman filter (maybe someone should gather up everything at the end and make an article out of it, wink wink, nudge nudge ).


I''ll probably turn it into an article once I''ve finished.... and expand on it to give a probabilistic explanaiton of the problem first. I''ll also cover a really nice non-linear Kalman filter algorithm that I came across during my research. It''s about all you''ll ever need for approximate inference in games... it''s easy to understand and fairly easy to implement to.

quote: Original post by Zul
I''ve taken higher level prob/stat courses, and one of the hardest things to do is actually apply the equations to real world situations. This is making me want to do an air hockey game :D


Hehe... there are PLENTY of scenarios in which you could apply probabilistic inference in games... but whether you could convince the gods to give you enough clock cycles to include it (rather than just fudging it) is another question all together.

Personally, I think the way that the industry will try new things is if independent developers make games that incorporate new techniques and that work. So go for it... make an air hockey game... or even a soccer game (with non-linear physics for ball motion)!

Cheers,

Timkin
Hi Guys,

just a quick bump. I haven''t forgotten about this - I''ve just been away from a terminal for the last couple of days so I haven''t had chance to digest the latest installment

Back in the office on Monday, so I should be able to devote some time to this then.

cheers,

Adam...
...and my apologies for not having found the time to finish the ''story''. The last few weeks have been rather hectic for me... hopefully this week I''ll find some time.

Plenty of time for you to take in all of the above!

Cheers,

Timkin

This topic is closed to new replies.

Advertisement