Limegarden.net Personal site of Wouter Lindenhof

6Mar/090

Fuzzy Logic

A while ago I was contacted with a question if someone I didn’t know (feel free to mail me, you could be the second person I haven’t met) could use my SSAO shader because he was in a desperate need for fuzzy logic. First of all the SSAO shader is free and second I don’t see where fuzzy logic is in my shader, but I wrote the code a long time ago so maybe I put it in without thinking too much of it.

However the term fuzzy logic is how do I put it… fuzzy for me as well. I have heard the term before and I can describe it, but what it exactly is? As I’m writing this post I already know what it is but just for fun I will describe my original explanation.

Old explanation:
Fuzzy logic is making a logical decision based on an inexact (or fuzzy) value. With an fuzzy value we refer to a value in a certain range.

The above is not correct, but not completely off. And how can a number something that we can measure (1, 2, 3, etc) be inexact? Anyway the second explanation is better and after you have read how I came to that explanation it will make sense.

New explanation:
Fuzzy logic is making a logical choice based on the range in which the value currently resides.

It’s a bit hard to explain with an example, but you will know after this most simple example. If you ask someone “how fast is your car?” he can answer with a number, if someone asked me that question I could answer that it max speed is 180 KM/H. However that is a quantity which is an exact number. However I could say that it is pretty fast and that is a fuzzy answer.

In code we could make it look like something:

[cc_cpp]
enum FUZZY_SPEED
{
FUZZY_SLOW = 0,
FUZZY_DECENT = 1,
FUZZY_FAST = 2,
FUZZY_LIGHTSPEED = 3,
};

FUZZY_SPEED GetSpeedOfCar(int Kmh)
{
if(Kmh <= 75) return FUZZY_SLOW;
if(Kmh <= 150) return FUZZY_DECENT;
if(Kmh <= 200) return FUZZY_FAST;
if(Kmh > 200) return FUZZY_LIGHTSPEED;
}[/cc_cpp]

However lets say this is the next version of GTA in which everybody is crazy about his car, including the character to which you told "My car is pretty fast, do you want to race?".

[cc_cpp]
bool ReactOnRaceChallange(FUZZY_SPEED playercar, FUZZY_SPEED aicar)
{
int FuzzyValue = aicar - playercar;
if(FuzzyValue < -1) return false; // Do not accept, noway the AI can beat the player
if(FuzzyValue <= 2) return false; // Do not accept, the player is not worthy to race with the AI
return true;
}[/cc_cpp]
The above is an example of fuzzy reasoning.
If you think about the answer you can find a lot of cases in which you can apply fuzzy logic.

  • Freezing, cold, warm, hot
  • Light, twilight, dark
  • Young, grown up, old, ancient

Now one last example: Let's say we have a story teller which based on your character attributes tells something about it.

Intellect: 8
Charisma:  7
Luck:      8

"He was a good looking (based on charisma) student (smart people often study) who had girls waiting in line (based on charisma and luck)."

If you still have trouble understanding try to change the character attributes and change the sentence. Like what would happen if we would drop his luck to zero? Would it become "Who was so good looking that all the girl fainted and had therefor never had a date in his life" or would that only happen if we increase his charisma to 9 and drop luck to zero?
References:

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.