# AI – CS289 Fuzzy Logic Fuzzy Tutorial 16 th October 2006 Dr Bogdan L. Vrusias

## Presentation on theme: "AI – CS289 Fuzzy Logic Fuzzy Tutorial 16 th October 2006 Dr Bogdan L. Vrusias"— Presentation transcript:

AI – CS289 Fuzzy Logic Fuzzy Tutorial 16 th October 2006 Dr Bogdan L. Vrusias b.vrusias@surrey.ac.uk

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20062 Contents Recap Example: Air Conditioner Example: Cart Pole Problem Case Study: Building a Fuzzy Expert System Summary

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20063 Recap Process of developing a fuzzy expert system: –Specify the problem; define linguistic variables. –Determine fuzzy sets. –Elicit and construct fuzzy rules. –Encode the fuzzy sets, fuzzy rules and procedures to perform fuzzy inference into the expert system. –Evaluate and tune the system.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20064 Recap Operation of a fuzzy expert system: –Fuzzification: definition of fuzzy sets, and determination of the degree of membership of crisp inputs in appropriate fuzzy sets. –Inference: evaluation of fuzzy rules to produce an output for each rule. –Composition: aggregation or combination of the outputs of all rules. –Defuzzification: computation of crisp output

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20065 Example: Air Conditioner 1a.Specify the problem Air-conditioning involves the delivery of air, which can be warmed or cooled and have its humidity raised or lowered. An air-conditioner is an apparatus for controlling, especially lowering, the temperature and humidity of an enclosed space. An air-conditioner typically has a fan which blows/cools/circulates fresh air and has a cooler. The cooler is controlled by a thermostat. Generally, the amount of air being compressed is proportional to the ambient temperature. 1b.Define linguistic variables - Ambient Temperature - Air-conditioner Fan Speed

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20066 2. Determine Fuzzy Sets: Temperature Temp ( 0 C).COLDCOOLPLEASANTWARMHOT 0Y*NNNN 5YYNNN 10NYNNN 12.5NY*NNN 15NYNNN 17.5NNY*NN 20NNNYN 22.5NNNY*N 25NNNYN 27.5NNNNY 30NNNNY* Temp ( 0 C).COLDCOOLPLEASANTWARMHOT 0<  (T)<1  (T)=1  (T)=0 Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20067 2. Determine Fuzzy Sets: Temperature Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20068 Rev/sec (RPM) MINIMALSLOWMEDIUMFASTBLAST 0Y*NNNN 10YNNNN 20YYNNN 30NY*NNN 40NYNNN 50NNY*NN 60NNNYN 70NNNY*N 80NNNYY 90NNNNY 100NNNNY* 2. Determine Fuzzy Sets: Fan Speed Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 20069 2. Determine Fuzzy Sets: Fan Speed Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200610 3. Elicit and construct fuzzy rules RULE 1: IFtemp iscoldTHENspeed isminimal RULE 2: IFtemp iscoolTHENspeed isslow RULE 3: IFtemp ispleasantTHENspeed ismedium RULE 4: IFtemp iswarmTHENspeed isfast RULE 5: IFtemp ishotTHENspeed isblast Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200611 4. Encode into an Expert System 5. Evaluate and tune the system Consider a temperature of 16oC, use the system to compute the optimal fan speed. Operation of a Fuzzy Expert System Fuzzification Inference Composition Defuzzification Example: Air Conditioner

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200612  COOL (T) = – T / 5 + 3.5 = – 16 / 5 + 3.5 = 0.3  PLSNT (T) = T /2.5 - 6 = 16 /2.5 - 6 = 0.4 Temp=16  COLD  COOL  PLEASANT  WARM  HOT 00.30.400 Example: Air Conditioner Fuzzification –Affected fuzzy sets: COOL and PLEASANT

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200613 Example: Air Conditioner Inference RULE 1: IFtemp iscoldTHENspeed isminimal RULE 2: IFtemp iscoolTHENspeed isslow RULE 3: IFtemp ispleasantTHENspeed ismedium RULE 4: IFtemp iswarmTHENspeed isfast RULE 5: IFtemp ishotTHENspeed isblast

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200614 RULE 2: IF temp is cool (0.3) THEN speed is slow (0.3) RULE 3: IF temp is pleasant (0.4) THEN speed is medium (0.4) Example: Air Conditioner Inference

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200615 speed is slow (0.3)speed is medium (0.4) + Example: Air Conditioner Composition

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200616 COG = 0.125(12.5) + 0.25(15) + 0.3(17.5+20+…+40+42.5) + 0.4(45+47.5+…+52.5+55) + 0.25(57.5) 0.125 + 0.25 + 0.3(11) + 0.4(5) + 0.25 = 45.54rpm Example: Air Conditioner Defuzzification

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200617 Example: Cart Pole Problem The problem is to balance an upright pole, with a mass m at its head and mass M at its base. A weightless shaft connects these two masses. The base can be moved on a horizontal axis. The task is to determine the force (F) necessary to balance the pole. The calculation of the force F involves the measurement of the angle θ and the angular velocity ω of the pole. M m g  

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200618  nbnb nmnm nsns azaz psps pmpm pbpb nbnb psps pbpb nmnm pmpm nsns nmnm nsns psps azaz nbnb nmnm nsns azaz psps pmpm pbpb psps nsns psps pmpm pmpm nmnm pbpb nbnb nsns nb: negative big,nm: negative medium,ns: negative small az: approximately zero ps: positive small,pm: positive medium,pb: positive big IFθisnegative medium AND  isapproximately zero THENFisnegative medium  Example: Cart Pole Problem

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200619 The fuzzy sets for θ, and F are based on the linear equation μ(x)=ax + b, and are defined based on the following table:   Example: Cart Pole Problem  if   if   if 

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200620 Example: Cart Pole Problem Based on the fuzzy sets table draw three graphs showing the fuzzy sets (nb, nm, ns, az, ps, pm, pb) for each θ, ω, and F individually. Consider the case when the input variables are: θ = 50, ω = -5. Use the rule base, execute each of the four tasks to compute the force F necessary to balance the pole using the Centre of Gravity in the Defuzzification task.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200621 Example: Cart Pole Problem Fuzzification i)Determine where θ and the angular velocity fall in the table θ: pm, pb ω: az ii)Formulate possible rules from linguistic values obtained IF θ is pm AND ω is az THEN F is pm IF θ is pb AND ω is az THEN F is pb

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200622 -11.25 -5010 22.5 45 5067.5  45 5067.5 11  1/22.5 =  /17.5  0.78 θ: pm θ: pb 67.55045  1 1/22.5 =  /5  0.22  1  : az 1/11.25 =  /6.25  0.56 Example: Cart Pole Problem Fuzzification iii)Compute membership functions

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200623 Example: Cart Pole Problem Inference 1.IF θ is pm AND ω is az THEN F is pm The two premises in rule are conjunctive  minimum of the two: min{0.78, 0.56} = 0.56 2.IF θ is pb AND ω is az THEN F is pb The two premises in RULE 2 are conjunctive  minimum of the two: min{0.22, 0.56} = 0.22

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200624 ps CoG pb Example: Cart Pole Problem Composition Defuzzification

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200625 Case Study: Building a Fuzzy System Step 1: Specify the problem and define linguistic variables A service centre keeps spare parts and repairs failed ones. A customer brings a failed item and receives a spare of the same type. Failed parts are repaired, placed on the shelf, and thus become spares. The objective is to advise a manager of the service centre on certain decision policies to keep the customers satisfied. There are four main linguistic variables: average waiting time (mean delay) m, repair utilisation factor of the service centre p, number of servers s, and initial number of spare parts n.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200626

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200627 Case Study: Building a Fuzzy System Step 2: Determine fuzzy sets Fuzzy sets can have a variety of shapes. However, a triangle or a trapezoid can often provide an adequate representation of the expert knowledge, and at the same time, significantly simplifies the process of computation.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200628 Case Study: Building a Fuzzy System Fuzzy sets of Mean Delay m

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200629 Case Study: Building a Fuzzy System Fuzzy sets of Number of Servers s

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200630 Case Study: Building a Fuzzy System Fuzzy sets of Repair Utilisation Factor p

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200631 Case Study: Building a Fuzzy System Fuzzy sets of Number of Spares n

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200632 Case Study: Building a Fuzzy System Step 3: Elicit and construct fuzzy rules To accomplish this task, we might ask the expert to describe how the problem can be solved using the fuzzy linguistic variables defined previously. Required knowledge also can be collected from other sources such as books, computer databases, flow diagrams and observed human behaviour.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200633 Case Study: Building a Fuzzy System The square FAM representation

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200634 Case Study: Building a Fuzzy System The rule table

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200635 Case Study: Building a Fuzzy System Rule Base 1

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200636 Case Study: Building a Fuzzy System Cube FAM of Rule Base 2

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200637 Case Study: Building a Fuzzy System Step 4: Encode the fuzzy sets, fuzzy rules and procedures to perform fuzzy inference into the expert system To accomplish this task, we may choose one of two options: to build our system using a programming language such as C/C++ or Pascal, or to apply a fuzzy logic development tool such as MATLAB Fuzzy Logic Toolbox or Fuzzy Knowledge Builder.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200638 Case Study: Building a Fuzzy System Step 5: Evaluate and tune the system The last, and the most laborious, task is to evaluate and tune the system. We want to see whether our fuzzy system meets the requirements specified at the beginning. Several test situations depend on the mean delay, number of servers and repair utilisation factor. The Fuzzy Logic Toolbox can generate surface to help us analyse the system’s performance.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200639 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 1

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200640 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 1

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200641 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 2

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200642 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 2

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200643 Case Study: Building a Fuzzy System Tune the system… However, even now, the expert might not be satisfied with the system performance. To improve the system performance, we may use additional sets Rather Small and Rather Large on the universe of discourse Number of Servers, and then extend the rule base.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200644 Case Study: Building a Fuzzy System Modified fuzzy sets of Number of Servers s

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200645 Case Study: Building a Fuzzy System Cube FAM of Rule Base 3

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200646 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 3

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200647 Case Study: Building a Fuzzy System Three-dimensional plots for Rule Base 3

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200648 Case Study: Building a Fuzzy System Tuning fuzzy systems 1.Review model input and output variables, and if required redefine their ranges. 2.Review the fuzzy sets, and if required define additional sets on the universe of discourse. The use of wide fuzzy sets may cause the fuzzy system to perform roughly. 3.Provide sufficient overlap between neighbouring sets. It is suggested that triangle-to-triangle and trapezoid-to-triangle fuzzy sets should overlap between 25% to 50% of their bases.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200649 Case Study: Building a Fuzzy System 4.Review the existing rules, and if required add new rules to the rule base. 5.Examine the rule base for opportunities to write hedge rules to capture the pathological behaviour of the system. 6.Adjust the rule execution weights. Most fuzzy logic tools allow control of the importance of rules by changing a weight multiplier. 7.Revise shapes of the fuzzy sets. In most cases, fuzzy systems are highly tolerant of a shape approximation.

AI – CS289 Fuzzy Logic 16 th October 2006Bogdan L. Vrusias © 200650 Summary Process of developing a fuzzy expert system Operation of a fuzzy expert system Examples: Air Conditioner; Cart Pole Problem Case Study: Building a Fuzzy Expert System

Download ppt "AI – CS289 Fuzzy Logic Fuzzy Tutorial 16 th October 2006 Dr Bogdan L. Vrusias"

Similar presentations