Sign in to follow this  
MichaelWeber

good introdution book on Fuzzy Logic

Recommended Posts

Hi. I am looking for a good book about Fuzzy logic in games. I have looked at "A Course In Fuzzy Systems And Control" by Li-Xin Wang, which seems okay but may be a bit generel. I have also looked at "Programming Game Ai By Example" by Matt Buckland but I am not sure it contains enough material om fuzzy logic. Could anyone recommend a good book on Fuzzy Logic in games or books on fuzzy logic and game ai (with fuzzy logic) ? Thanks :) Michael Weber

Share this post


Link to post
Share on other sites
if a > b

is actually fuzzy logic. The best way of using, and learning, fuzzy logic is to do it with brain.

The most of such requests are, if answered, just a road to the... and ... shortly too much math and graphs that says in very obscure ways that 2 + a > 2 for a > 0


Or they could say something like : if we have 1KV, std A, in wire "a" the wheel would turn itself by 2/10 of circle, if we will change voltage by 299 volts, it will change its position by ... from norm.

Share this post


Link to post
Share on other sites
Fuzzy logic in a few easy steps....

a and b = min(a, b)
a or b = max(a, b)
a and not b = min(a, !b)
not b = 1-b

So, for x = a and b or a and not b
= max(min(a, b), min(a, not(b)))

So, for moveforeward = foodinfront and not attackfront
...

You get the drift.

Basically, everything is from 0 to 1, and it is fuzzy, not descrete.

From,
nice coder

Share this post


Link to post
Share on other sites
What games related information do you think you are missing?

I have never come across a game that uses FL in a more "advanced" way than that shown in my book. It is possible to tweak the sets and rules using learning algorithms but that's another topic altogether...

Edit: I forgot to mention that if you want to delve further into FL then Earl Cox's book comes highly recommended.

http://www.amazon.com/exec/obidos/tg/detail/-/0121942708/ref=pd_sim_b_2/002-6279316-6781624?%5Fencoding=UTF8&v=glance


[Edited by - fup on July 1, 2005 1:48:50 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Raghar
if a > b

is actually fuzzy logic. The best way of using, and learning, fuzzy logic is to do it with brain.



Not exactly the best example. With no context it looks like classical boolean logic. 'a' is either greater than 'b' (result = true) or not (result = false). Unlike boolean logic, fuzzy logic presents degrees of truth (not to be confused with probability). In this respect it contains values between and including 0 and 1. But that's beside the point, the OP seems more interested in how to apply FL to games not what FL is.

Share this post


Link to post
Share on other sites

A few little examples from game developing:

Some use of FL is just to avoid using: if (a == C.ALIENS) do something.

with FL it's:
a = b+c+ d/2 + e/4;
if(a > CurrentThereshold) dosomething (they are likely aliens)

The above equation work best for larger range than 0 to 1. (normalization and error cancelation could bite you severally)

for example

a = 10;
CurrentThereshold = 2035;

Naw it's not an alien.


Then you could plug it to some other equation, if you are interested in how much it isn't an alien.

For example:
NotAlien = log(2035) - log(a);
or
NotAlien = Math.sqrt(2035) - Math.sqrt(a);

Of course it's a Fuzzy logic. The possibility that such thing isn't an alien is difference between 10 and 2035, but it could be an alien anyway. You never know. And this is the reason why FL is used in games, to simulate friendly fire, and such mistakes.


(One of important things to note is a neccessity to make program hardened against unexpected situations, for example if some friendly unit would be identified by a mistake as an alien, and contacted in friendly maner by aliens. If game/world engine would crash after that event, it wasn't hardened well.)

Share this post


Link to post
Share on other sites
Fuzzy logic is pretty simple, when you break it down into chunks. A fuzzy system is, in the end, taking crisp (non-fuzzy) inputs and outputting crisp values... otherwise, it's like... not practical and stuff :-).

So, here are the steps to solving some problem using applied fuzzy logic (roughly, as it's been a while since I've played with it):


1) Fuzzify your input data

As you may know, a fuzzy set is pretty much a function with range 0..1, applied to a domain. For example, your domain might be "temperature"... And on this domain, you may have fuzzy sets like: "friggin cold", "cold", "comfy", "warm", "friggin warm"... EVERYONE pretty much would consider "-45C" as friggin cold, so the membership of -45C into the "friggin cold" set is 1. But -20C is more common, and is less likely to be considered "friggin cold", so it would only be say 0.6 (or 60%) a member of the "friggin cold" set... and so on and so forth. so:


for each input value I
for each fuzzy set F
keep track of Membership(I, F)


2) Apply your rule base

It's MUCH easier (more natural) to think in terms of fuzzy rules than crisp ones. We do it all the time in our everyday lives. We say "if it's cold, wear a jacket"... "if it's warm, wear a t-shirt"... "if it's kinda mild, wear a sweater"... but NOBODY looks at a thermometer and says "I will wear a jacket at 4C, but just a sweater at 4.1C... so you see what the idea is. You have a number of fuzzy rules that would look something like this:

This assumes there's two inputs (temperature and 'what the sky looks like'), and one output (what to wear when you go outside):


IF temp = "friggin cold" AND sky = "sunny" THEN "wear a winter jacket"
IF temp = "pretty warm" AND sky = "very cloudy" THEN "wear a raincoat"
...


Now, to apply your rules, you use a basic minimax approach in most cases (the AND/OR rules discussed earlier):

suppose

MEMBERSHIP(temp, "friggin cold") = 0.3
MEMBERSHIP(temp, "pretty warm") = 0.7
MEMBERSHIP(sky, "sunny") = 0.1
MEMBERSHIP(sky, "very cloudy") = 0.9

...you perform the AND's in each rule.

So first rule: 0.3 AND 0.1 = 0.1
Second rule: 0.7 AND 0.9 = 0.7

So now we have some candidate membership functions for the outputs:

Membership(coat, winter coat) = 0.1
Membership(coat, raincoat) = 0.7

In reality, you would have a LOT of rules, and let's say there are two of them that conclude "wear a raincoat", and the other one (not in the example) says "Membership(coat, raincoat) = 0.5", you OR them together: 0.7 OR 0.5 = 0.7... Hence the MINIMAX approach!

So now, we've determined the memberships of the proper output variable (what to wear), for each fuzzy set over our domain:

Membership(coat, winter coat) = 0.1
Membership(coat, raincoat) = 0.7

3) Defuzzify your output (get crisp output)

Like I said, the fuzzy version of the output is absolutely useless in most cases. A REAL example with real output would have output over a much more continuous domain, and the crisp output is calculated using all kinds of weighted averages and such. The complicatedness of it really depends on what you're going for, and how symmetrical your output fuzzy set member functions are.

Now that you have your real output value, apply it, and continue reading the input from the system and re-adjusting. It actually works really well for more serious examples, like if you want to control the force you apply to a card that's supposed to balance an inverted pendulum or what have you.

Hope this wasn't too confusing. The point is, the mathematics are really simple, and it only looks complicated as a whole. The steps are clear-cut and separately, they're very simple.

Share this post


Link to post
Share on other sites
Quote:
Original post by MichaelWeber
I am looking for a good book about Fuzzy logic in games.
Few games use fuzzy logic, so there's little to go by. Those that do, hardly stray from the "standard" fuzzy logic, so you might as well go with a standard fuzzy logic book, IMO. I'm not an expert on what fuzzy logic books are out there, but one book I have and like is:

Reznik, Leonid. Fuzzy Controllers

It's not a traditional (and stuffy) textbook, so it's quite readable. As the title suggests, the focus is on controllers, i.e. control units of embedded systems, so while it doesn't cover games as such, the fact that it talks about controllers makes is particularly relevant to games-like applications. It does lack the worked examples that you'd find in a textbook, but it's not a big flaw.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this