Fuzzy Systems Overview: Literature: Why Fuzzy Fuzzy Logic and Sets Fuzzy Reasoning chapter 4 DKS - Module 7 1 Why fuzzy thinking? Experts rely on common sense to solve problems Representation of vague, ambiguous terms If short means 300m or less, is 301m long? Fuzzy logic Not logic that is fuzzy But logic that describes fuzzyness = vagueness 2 13/10/09 DKS - Module 7 1
Vague concepts - at least 1.80 m? - could Frank be 1.78 m and be still tall? - if Frank is a basketball player is 1.80m still tall? - if Frank is a kid of 10 years and 1.80 m isn t Frank very tall? 3 13/10/09 DKS - Module 7 Numerical vs. Logic uncertainty reasoning Numerical systems: degree of belief Logical systems: degree of membership 4 13/10/09 DKS - Module 7 2
Fuzzy Logic - I Approach to formal treatment of uncertainty Relies on quantifying and reasoning through natural language uses linguistic variables to describe concepts with vague values tall, large, small, heavy,... Based on the idea that all things admit of degrees Really hot, very tall, kind of small, light blue, 5 13/10/09 DKS - Module 7 Fuzzy Logic - II Boolean logic uses sharp distinctions Fuzzy logic reflects how people think Fuzzy logic is a set of mathematical principles for knowledge representation and reasoning based on degrees of membership 6 13/10/09 DKS - Module 7 3
Fuzzy set Crisp set (tall men): Is a function f: domain [0,1] Fuzzy set (tall men): 7 13/10/09 DKS - Module 7 Fuzzy sets (men s height): Representing a domain 8 13/10/09 DKS - Module 7 4
Membership function Categorization of element x into a set A described through a membership function µ A (x) Formally, given a fuzzy set A of universe X µ A (x): X [0,1], where µ A (x) = 1 if x is totally in A µ A (x) = 0 if x is totally not in A 0 < µ A (x) <1 if x is partially in A (Discrete) Fuzzy set A is represented as: A = {µ A (x 1 )/x 1, µ A (x 2 )/x 2,, µ A (x n )/x n } µ Tall (200) = 1 µ Tall (160) = 0 0 < µ Tall (180) <1 Tall = {0/160, 0.2/170, 0.8/180, 1/190} 9 13/10/09 DKS - Module 7 Operations on Fuzzy Sets Union: µ A B (x) = max(µ A (x), µ B (x)) Intersection: µ A B (x) = min(µ A (x), µ B (x)) Complement: µ A (x) = 1 - µ A (x) 10 13/10/09 DKS - Module 7 5
Fuzzy logic Based on fuzzy set properties Logic OR ( ) is set union A B = µ A B (x) = max(µ A (x), µ B (x)) Logical AND ( ) is set intersection A B = µ A B (x) = min(µ A (x), µ B (x)) Logical NOT ( ) is set complement A = µ A (x) = 1 - µ A (x) 11 13/10/09 DKS - Module 7 Properties of fuzzy sets The same as for crisp sets Commutativity Associativity Distributivity Idempotency Identity De Morgan s Laws 12 13/10/09 DKS - Module 7 6
Linguistic variables A linguistic variable is a fuzzy variable The linguistic variable speed ranges between 0 and 300km/h and includes the fuzzy sets slow, very slow, fast, Fuzzy sets define the linguistic values Hedges are qualifiers of a linguistic variable All purpose: very, quite, extremely Probability: likely, unlikely Quantifiers: most, several, few Possibilities: almost impossible, quite possible 13 13/10/09 DKS - Module 7 Fuzzy set with hedge very 14 13/10/09 DKS - Module 7 7
Interpretation of hedges Hedges modify the shape of a fuzzy set 15 13/10/09 DKS - Module 7 Fuzzy rules A fuzzy rule is defined as a conditional statement of the form IF x is A THEN y is B Where x and y are linguistic variables and A and B are linguistic values determined by fuzzy sets on the universes of discourse X and Y. 16 13/10/09 DKS - Module 7 8
Fuzzy rule example IF height is tall THEN weight is heavy. Where the fuzzy classes height and weight have a given range (i.e. the universe of discourse). range(height) = [140, 220] range(weight) = [50, 250] 17 13/10/09 DKS - Module 7 Reasoning with fuzzy rules In classical systems, rules with true antecedents fire. In fuzzy systems, truth (i.e. membership in some class) is relative so all rules fire (to some extent). 18 13/10/09 DKS - Module 7 9
Applying fuzzy rules If the antecedent is true to some degree, the consequent is true to the same degree. IF length is tall THEN weight is heavy Tall men Heavy men µ Tall (x) = 0.7 µ Heavy (y) = 0.7 19 13/10/09 DKS - Module 7 Multiple antecedents IF x is A AND y is B THEN z is C IF x is A OR y is B THEN z is C Use unification (OR) or intersection (AND) operations to calculate a membership value for the whole antecedent. AND: µ C (z) = min(µ A (x), µ B (y)) OR: µ C (z) = max(µ A (x), µ B (y)) E.g. If rain is heavy AND wind is strong THEN weather is bad ((µ heavy (rain) = 0.7) (µ strong (wind) = 0.4)) (µ bad (weather) = 0.4) 20 13/10/09 DKS - Module 7 10
Multiple consequents IF x is A THEN y is B AND z is C Each consequent is affected equally by the membership in the antecedent class(es). E.g. IF x is tall THEN y is heavy AND z has large feet µ Tall (x) = 0.7 µ Heavy (y) = 0.7 µ LargeFeet (z) = 0.7 21 13/10/09 DKS - Module 7 Fuzzy Events Fuzzy probabilities: What is the probability of meeting a tall man? P(x is A) = Where µ A (x) is the membership function of elements in A P(x) is the probability of x (Empirical evidence) 22 13/10/09 DKS - Module 7 11
Fuzzy probability What is the probability that temperature on July 16 th is around 25 C Based of average temperatures for July 16 th : C 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 P.002.005.005.01.04.11.15.21.16.14.11.04.01.005.002 1 0 20 24 26 30 Around 25 C P(temp is around 25 C) = = Σ µ about25 (x)*p(x) = µ (20)*P(20) + µ(21)*p(21) + + µ(30)*p(30) = 0*0.005 + 0.25*0.01 + 0.5*0.04 + + 0*0.01 = 0.8125 0,8 23 13/10/09 DKS - Module 7 Using hedges The probability that temperature on July 16 th is around 25 C is likely P(temp is about 25 C) = 0.8 Likely with probability 0.95 Very likely with prob. 0.32 0.8 24 13/10/09 DKS - Module 7 12
Fuzzy Inference How to reason using Fuzzy Logic? 1. Fuzzify input variables 2. Evaluate rules 3. Aggregate rule outputs 4. Defuzzify the output 25 13/10/09 DKS - Module 7 Rule 1 w 1 X is A 1 y is B 1 Rule 2 defuzzifier X X is A 2 y is B 2 w 2 Rule r Fuzzy aggregator y X is A r w r y is B r 26 13/10/09 DKS - Module 7 13
Step 1: Fuzzification Use crisp inputs from the user Determine membership values for all the relevant classes (i.e. in right Universe of Discourse). 27 13/10/09 DKS - Module 7 Step 2: Rule evaluation Apply fuzzified inputs to all relevant rules Use union, intersection and complement operations to handle composite antecedents Min-max method for composite antecedents produces clipped functions 28 13/10/09 DKS - Module 7 14
Step 3: Result Aggregation Build membership function for each output (rule consequents) by aggregating all the relevant classes Unification of outputs of all rules 29 13/10/09 DKS - Module 7 Step 4: Defuzzification (Mamdani) Definition: It refers to the way a crisp value is extracted from a fuzzy set as a representative value There are five methods of defuzzifying a fuzzy set A of a universe of discourse Z Centroid of area z COA Bisector of area z BOA Mean of maximum z MOM Smallest of maximum z SOM Largest of maximum z LOM 30 13/10/09 DKS - Module 7 15
Step 4: Defuzzification (Mamdani) Use centre of area formula (centroid technique) to calculate crisp output value Summation as approximation to integral value 31 13/10/09 DKS - Module 7 Step 4: Defuzzification 32 13/10/09 DKS - Module 7 16
Sugeno Fuzzy Models If x is A & y is B then z = f(x, y) Where A & B are fuzzy sets in the antecedent, while z = f(x, y) is a crisp function in the consequent If f(.,.) is a constant then it is a zero-order Sugeno fuzzy model (special case of Mamdani model) Often: Weighted average of singletons in each fuzzy set 33 13/10/09 DKS - Module 7 Exercise Suppose 3 fuzzy rules that determine heart attack risk, based on: Three universes of discourse (UoD): Diet (1000-4000 cal/day): with fuzzy classes poor, good Exercise (1000-4000 cal/day): with fuzzy classes high, low Risk (0-100 likelihood): with fuzzy classes high, low, medium Represent membership functions graphically Show fuzzy inference for following sample data What is the risk of heart disease of Mary who has a diet of 2500 cal/day and spends 1000 cal/day on exercise 34 13/10/09 DKS - Module 7 17
Rules Rule1: Rule2: Rule3: IF diet is poor AND exercise is low THEN risk is high IF diet is good AND exercise is high THEN risk is low IF diet is good OR exercise is high THEN risk is medium 35 13/10/09 DKS - Module 7 Membership function: Diet Mary? 36 13/10/09 DKS - Module 7 18
Membership function: Exercise Mary? 37 13/10/09 DKS - Module 7 Membership function: Risk Mary? 38 13/10/09 DKS - Module 7 19
Mamdani inference 1. Fuzzify input variables Determine membership values 2. Evaluate rules Based on membership values of (composite) antecedents 3. Aggregate rule outputs Unify all membership values for output from all rules 4. Defuzzify the output COG: Center of gravity (approx. by summation) 39 13/10/09 DKS - Module 7 Step 1: fuzzification Fuzzify values for Mary: has a diet of 2500 cal/day and spends 1000 cal/day on exercise µ poordiet (2500) = 0,6 µ gooddiet (2500) = 0,8 µ highexer (1000) = 0 µ lowexer (1000) = 1 40 13/10/09 DKS - Module 7 20
Step 2: rule evaluation Rule1: IF diet is poor (0,6) AND exercise is low (1) THEN risk is high µ A B (x) = min(µ A (x), µ B (x)) = 0,6 Consequent is true to the same degree as the composition of antecedent µ riskhigh (Mary) = 0,6 41 13/10/09 DKS - Module 7 Membership: Risk High 42 13/10/09 DKS - Module 7 21
Step 2 (continuation) RULE1: IF diet is poor (0,6) AND exercise is low (1) THEN risk is high (0,6) RULE2: IF diet is good (0,8) AND exercise is high (0) THEN risk is low (0) RULE3: IF diet is good (0,8) OR exercise is high (0) THEN risk is medium (0,8) 43 13/10/09 DKS - Module 7 Step 3: Aggregation Note that low has been clipped down to zero, and average hasn t been clipped, because the derived µ was higher than the original membership function. The aggregate is simply the union of the three functions. 44 13/10/09 DKS - Module 7 22
Step 4: Defuzzification Centroid technique Example: sample every 12,5 units More points are better, integral is even better COG = 70 45 13/10/09 DKS - Module 7 Result The likelihood of heart disease for Mary is 70% 46 13/10/09 DKS - Module 7 23
Advantages of Fuzzy Logic general theory of uncertainty wide applicability, many practical applications natural use of vague and imprecise concepts helpful for commonsense reasoning, explanation 47 13/10/09 DKS - Module 7 Problems of Fuzzy Logic membership functions can be difficult to find multiple ways for combining evidence problems with long inference chains 48 13/10/09 DKS - Module 7 24
Coming up 20 October 2009: Knowledge Engineering (Evaluation) 27 October 2009: Intelligent Interfaces (Agents and KS) 49 13/10/09 DKS - Module 7 25