Advertisement

Fuzzy Logic problem

Started by July 19, 2009 03:24 AM
25 comments, last by IADaveMark 15 years, 4 months ago
Quote: Original post by InnocuousFox
I think where you are getting confused is with the concept of "defuzzification". That is where you subdivide a single continuous value into segments that can then be described. For example, you could say that:

0.0 to 0.1 -> "very short"
0.1 to 0.3 -> "rather short"
...


Actually, "defuzzification" is the process of extracting a singleton (a single, real-valued number) from a fuzzy distribution (for instance, by a weighted centroid calculation).

The process you have described (above) is "binning" (with labels), which accepts as input a single numeric value and outputs 1 of a small number of symbols. Defuzzification, in contrast, accepts a numeric distribution representing a fuzzy set as input, and returns a single real number from the domain of that fuzzy set.


-Will Dwinnell
Data Mining in MATLAB
Ok. listen.
You said
"By using responses curve that ramps upwards as the values approach one end or the other, you can increase the magnitude of the importance. For example, by using an exponential curve applied to the threat distance, you can create a similar effect as what you arrived at in the above equation. The point of the formula was that as the threat level progressed from the lower ranges into the higher ones, you deployed more units at a rapidly increasing rate (not just linearly). If you were to use something along the lines of:

nDeploy = (threat)^exponent"

Yea, i figured that works for his example. But how do i do it with mine?
How do i calculate the value of my strategicness? You've said multiple times, that i shouldn't use four vars, but you didn't say how i should do it. I don't know how to use this exponent function in this case, since the strategicness in this case is not something that clear. It's not something like distance*strangth^2, or whatever. because as i said, being close to the player is good if it's strong, and bad if it's weak. so it's not so linear.
Advertisement
Quote: Original post by Predictor
Actually, "defuzzification" is the process of extracting a singleton (a single, real-valued number) from a fuzzy distribution (for instance, by a weighted centroid calculation).

The process you have described (above) is "binning" (with labels)...

True enough. That's what I get for posting on and off while working on a lecture, watching a baseball game, and generally being a bum on a Sunday. *sigh*

Regardless of the labeling, however...

As for the solution to the OP's problem, I haven't tried to explain it completely because we still have yet to see all the information that goes into a decision in a concise way. I'm not up for piecing together bits and parts scattered throughout 3 different posts to try to see what all the relevant information is and the decisions that need to be made with it. You haven't been terribly clear in that sense.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

ok. sorry.
after calculating the values of mweak to mverystrong and mclose to mfar, i have this, to calulate whats actually strategic:
var mNotStrategic:Number = OR(AND(mWeak,mClose), AND(mWeak,mNearby), AND(mVeryFar, OR(mWeak,mStable,notVery(mStrong))) );
//above means that a place is not strategic if it is either weak and close or weak and nearby or very far and (weak,stable or kind of strong). So these are distinct ways of being not very strategic

var mStrategic:Number = OR(AND(mStable,mNearby), AND(mWeak,mFar), AND(mStrong,mFar), AND(very(mVeryStrong),mVeryFar) );
//meaning the place is strategic if it's either stable and nearby, or weak and far or strong and far or verystrong and very far
var mVeryStrategic:Number = OR(AND(mStrong, OR(notVery(mClose), mNearby)), AND(mVeryStrong, OR(notVery(mNearby),vFar) );
//meaning it's a very strategic point, if its either strong and close/nearby or very strong and kind of nearby/far
var mUnbeatable:Number = OR(AND(mVeryStrong,OR(mClose,very(mNearby))), AND(very(mVeryStrong), mNearby) );
//meaning its an unbeatably point, if its either very strong and close/very nearby, or if its very very strong and nearby.

this is basically what calculates the strategicness of the point.
Strength is measured in amount of shields a place has, and calculating that is pretty linnear. and distance is the distance to the player. which is also pretty linnear.

Now after having calculated these four vars, i want to have the truth value of var mStrategicValue (between 0 and one, where 0 is not strategic at all, and 1 is unbeatable).
Quote: Original post by omniscient
var mNotStrategic:Number = ...
var mStrategic:Number = ...
var mVeryStrategic:Number = ...
var mUnbeatable:Number = ...
My understand of fuzzy logic is that once you have these values, you simply do something like:
if (very(mNotStrategic)) {  // do "not strategic" action}if (very(mStrategic)) {  // do "strategic" action}if (very(mVeryStrategic)) {  // do "very strategic" action}if (very(mUnbeatable)) {  // do "unbeatable" action}
(note that it's not if ... else if ... else because it can be both "NotStrategic" and "Strategic" at the same time)
Hi omniscient,

Why don't you try to get it working with a completely different solution, like the one Dave suggested for example? Just invent a non-linear function that fits with the kind of results you want.

You're trying to think of this as a fuzzy logic problem is constraining your thinking. The result in the end may not turn out differently, but right now you're in a dead end it seems.


Try something different, use three values for each cover point then use a simple equation to turn that into a cover desirability value. For reference, see this paper:

Procedural Combat Tactics in Killzone
Remco Straatman, Arjen Beij, William van der Sterren

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!

Advertisement
"Just invent a non-linear function that fits with the kind of results you want."

How do i do this? I said what the ai is supposed to do, but i have no idea how to turn that into a function.
This is what i want:
When the point is close to the player, AND ahs lots of shields, then it is desirable. if it is close but has few shields, then it is undesirable. So closeness isn't always good or always bad. I don't know how to make a function out of that.

and to come back to my origninal question. i may have found a solution (keeping the four vars):
public static function fuzzyTotalTruth(... values):Number
{//the input is, odd arguments are the fuzzysets. even arguments are the values of those fuzzySets.
var truth:Number = 0;
for (var i:int = 0,num:int = values.length;i<num;i+=2)
{
truth += Number(values)*Number(values[i+1]);
}
return truth;//is a number between 0.0 and 1.0.
}//end of function
i then fill in:

var strategic:Number = fuzzyTotalTruth(
mNotStrategic, 0.1 ,mStrategic, 0.5 ,mVeryStrategic, 0.7
,mUnbeatable, 1.0
);
so the second value is the weight the first value has on the eventual strategicness.
does this make sense?
Keep it simple, get it working.

Write two separate functions, one for high shields and the other for low shields first. Get a feel for the problem. If you're stuck then you've started thinking too complex.

You can also use a lookup table to create a function and interpolate between values, that's one way to implement a response curve.

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!

Quote: Original post by omniscient
I am using fuzzy logic to calculate the desirability of certain strategic spots in a game.
I have 4 vars:

//in Actionscript 3.0
var mNotStrategic:Number
var mStrategic:Number
var mVeryStrategic:Numbe
var mUnbeatable:Number

//in C++:
double mNotStrategic
double mStrategic
double mVeryStrategic
double mUnbeatable

all these vars are ofcourse from 0 to 1.
and I want to calculate the desirability:
var mDesirable:Number

I want to use mDesirable in other fuzzy logic expressions.
So i don't want to defuzzify it. it has to be a number between 0 and 1.


The above makes me suspect a serious misunderstanding of fuzzy logic. Although fuzzy truth values are measured as numbers ranging from 0.0 to 1.0, fuzzy inference is typically performed on fuzzy sets (distributions of fuzzy truth values over some domain). The only way to "defuzzify" a single fuzzy truth value is to force that value to 0.0 or 1.0, but this term is normally used in reference to the conversion of a fuzzy set to a singleton (a single real number value- not necessarily in the 0.0 to 1.0 range).

I suggest reviewing any of the following:

Fuzzy Math, Part 1, The Theory, by Luka Crnkovic-Dodig

Fuzzy Logic Overview (HTML)

comp.ai.fuzzy FAQ: Fuzzy Logic and Fuzzy Expert Systems

Fuzzy Logic for "Just Plain Folks" (HTML), by Thomas Sowell


-Will Dwinnell
Data Mining in MATLAB




Quote: Original post by omniscient
define what i mean by strategic:
the points that are the most strategic, will be mroe desirable for the AI to go to. The strategic value of the point, combined with the distance of that ai unit to that point is the eventual value of the point. the unit will then choose the best point to go to. so the most strategic point, but that is not too far away.
I hope that answers the question.

so i am measuring 3 aspects of the point. 2 aspects determine the strategic value of the point, namely distance from the player, and the amount of cover there is.
the mWeak till mVeryStrong represent the cover value. (nrShields is the amount of cover the place has).

this function only calculates the strategic value.



To me, the above suggests the following fuzzy logic solution:

StrategicValue is a scale, measured from, say 0.0 ("not strategically valuable at all" to 1.0 ("maximally strategically valuable"). StrategicValue needs to be covered by fuzzy sets: graded, overlapping regions, such as "LowStrategicValue", "MediumStrategicValue" and "HighStrategicValue".

The two inputs to the fuzzy model are DistanceFromPlayer and AmountOfCover. The domains of these two variables would be covered with fuzzy sets ("DistanceNear", "DistanceMedium", "DistanceFar" and "NoCover", "SomeCover", "MuchCover", for instance).

The model itself is a collection of rules which combine the input fuzzy sets and imply output fuzzy sets:

IF Distance IS DistanceFar AND Cover IS NoCover THEN StrategicValue IS
LowStrategicValue

IF Distance IS DistanceNear AND Cover IS MuchCover THEN StrategicValue IS
HighStrategicValue

In any given case, different fuzzy rules fire to different degrees (depending on the fuzzy truth of their conditions), and the output fuzzy sets are composed into a single output fuzzy set. Typically, this is defuzzified to reveal the final output.


-Will Dwinnell
Data Mining in MATLAB

This topic is closed to new replies.

Advertisement