Advertisement

Using Fuzzy Data for AI

Started by July 14, 2015 11:13 PM
7 comments, last by Tutorial Doctor 9 years, 2 months ago

I am playing around with a way to structure fuzzy data using python. I am really wondering about some applications of such data.

It looks like I would have to do Type 2 fuzzy logic in order to get real fuzziness, because if a value isn't in the set that I have created (which is crisp) then am I to think that the value still doesn't belong to the set?

Here is the code:


#Only Integers right now
# Need backwards fuzziness (hi to low)
# Need to handle float ranges

cold = [1,213]
hot = [90,100]
funny = [8,10]
close = [0,5]

joes_distance = 1
joes_funniness = 9

def membership(x,List):
    return (float(x)-List[0])/(List[-1]-List[0])
def Is(x,List):
    print membership(x,List)
    return x in range(List[0],List[-1]+1)


print Is(joes_distance,close)
print Is(93,hot)


if Is(joes_funniness,funny):
    print "Joe is %s funny"%membership(joes_funniness,funny)
else:
    print "Joe is not funny at all"

def get_fuzzy_values(List,Label):
    for i in range(List[0],List[-1]+1):
        print str(i) + " is " + str((float(i)-List[0])/(List[-1]-List[0])) + " " + Label
    
get_fuzzy_values(cold,"Cold")

So for an object to be considered close, it has to be in the range of 0-5. But is an object that is 5.1 units away not close? Well, it is still close, but to another degree. So, using any sort of boolean logic seems futile when trying to keep everything fuzzy. Perhaps I should consider the extremes to be only the values in consideration?

Anything that has any temperature is both hot and cold, but to various degrees of hot and cold (how do you work with this type of logic).

At any rate, I am still wondering about some possible applications of the current structure I have in an AI system. Or perhaps in a game at all.

I know my code is probably unnecessarily elaborate, but I am just toying with ideas right now.

They call me the Tutorial Doctor.

Made it a little better:


#close and hot are not comstants, because they can be interpreted
close = (0,10)
hot = (90,100)

def membership(x,List):
	top =(float(x)-List[0])
	bottom =(List[-1]-List[0])
	M = top/bottom
	return M

def Is(x,List):
	if x >= List[0]:
		if x <= List[-1]:
			print membership(x,List)
			return True
	return False

joseph = 9.3
San_Antonio = 0
Georgia = 99.35

print Is(1.3,close)
print Is(joseph,close)

def Get(List,x,i=1):
	steps=0
	while x<=List[1]:
		print (x,membership(x,List))
		x=x+i
		print 'steps: {}'.format(steps)
		steps=steps+1

print 
Get(close,joseph,.1)
print
Get(hot,San_Antonio,10)
print 
print Is(Georgia,hot)

They call me the Tutorial Doctor.

Advertisement
There is an entire field of AI modeling that uses "fuzzy" values in a loose, informal sense of the word - utility theory.

In a non-normalized utility model, scores can be any floating point value; the significance of a score is determined by applying certain types of reasoning to the score:
  • Thresholds - does the value exceed a certain limit? Is it less than some maximum? etc.
  • Ranges - does the value fall within a given range?
  • Distance - how far from some expected norm is the value?
  • Relative measures - how does the value compare to a different score from the system?
  • Combinatorial measures - when combining multiple scores via addition, multiplication, division, etc., how does the result look?
Note that these techniques are converting numeric imprecision into Boolean predicates. Hence why I say that they are not "fuzzy" in the formal, "fuzzy logic" sense. However, they still allow for very fluid and seamless modeling of decision logic, state awareness, prioritization, and other fundamental AI notions.

To make the system a bit less unwieldy and free-ranging, you can instead apply a normalized model, where scores land between controlled endpoints, such as 0 and 1, or -100 and 100. This is typically done by range adjustment, division, and clamping.

Suppose you have a temperature in Fahrenheit that you want to gauge. You could model it as a [0,1] interval by deciding that anything below 32 is "cold" and anything above 212 is "hot." Take the temperature raw value, subtract 32 (to anchor the bottom end of the range), and divide by (212-32 = 180) to yield a normalized number. Celsius is simpler, obviously.

Now you can compare normalized values using the same bag of tricks I listed above.


Utility modeling is a very powerful subject and I highly recommend materials like the Game AI Pro series (esp. work by Kevin Dill and Dave Mark), Behavioral Mathematics for Game AI (also by Dave Mark), and lectures including this one by myself and Dave at GDC 2015.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Great info Apoch! Thanks a lot. I perhaps will try to simulate type 2 fuzzy logic (they say it is complex) one day.

Exactly the type of response I needed. Thanks again.

They call me the Tutorial Doctor.

What that dude up there said.

Book link in the sig below.

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!"

Okay. Thanks Dave and Apoch. Will check them out definitely.

They call me the Tutorial Doctor.

Advertisement

Its useful when you take the raw data and can 'fuzzy' process them into different degrees/gradualtion in a systematic way.

Use would be where you have different contingencies depending on the degree of 'whatness' -- very close do X, sorta close doY nearby do Z, far away do W, very far Ignore.

by changing parameterization of the fuzzy functions you can have different object types have custom adjusted ranges for these different responses.

One thing that often is ignored is Temporal aspects, where the values change and the judgements shift - when the behavior originally selected for action is no longer indicated and replaced with a different one. If the raw values start oscillating and the logic likewise oscillates its results the behavior can look eratic/be wasteful. So some derivative dampening factor (like fuzzy averaging across time) can help stabilize situations like that.

--------------------------------------------[size="1"]Ratings are Opinion, not Fact

The architecture that Apoch and I presented in the video he linked to does all of that and then some.

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!"

Finally have something up that I can expand upon.

Here is an AI chatbot (easily customizable) made with python.

It has other features also.

Any critique is welcome.

https://gist.github.com/TutorialDoctor/506baac02e908cfed802

They call me the Tutorial Doctor.

This topic is closed to new replies.

Advertisement