AI CS 289 Fuzzy Logic Fuzzy Tutorial 16

  • Slides: 50
Download presentation
AI – CS 289 Fuzzy Logic Fuzzy Tutorial 16 th October 2006 Dr Bogdan

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

AI – CS 289 Fuzzy Logic Contents • • • Recap Example: Air Conditioner

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

AI – CS 289 Fuzzy Logic Recap • Process of developing a fuzzy expert

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 3

AI – CS 289 Fuzzy Logic Recap • Operation of a fuzzy expert system:

AI – CS 289 Fuzzy Logic 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 16 th October 2006 Bogdan L. Vrusias © 2006 4

AI – CS 289 Fuzzy Logic Example: Air Conditioner 1 a. Specify the problem

AI – CS 289 Fuzzy Logic Example: Air Conditioner 1 a. 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. 1 b. Define linguistic variables - Ambient Temperature - Air-conditioner Fan Speed 16 th October 2006 Bogdan L. Vrusias © 2006 5

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Temperature

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Temperature Temp (0 C). 0< (T)<1 (T)=0 16 th October 2006 COLD COOL PLEASANT WARM HOT 0 Y* N N 5 Y Y N N N 10 N Y N N N 12. 5 N Y* N N N 15 N Y N N N 17. 5 N N Y* N N 20 N N N Y N 22. 5 N N N Y* N 25 N N N Y N 27. 5 N N Y 30 N N Y* Bogdan L. Vrusias © 2006 (T)=1 6

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Temperature

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

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Fan

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Fan Speed Rev/sec (RPM) 16 th October 2006 MINIMAL SLOW MEDIUM FAST BLAST 0 Y* N N 10 Y N N 20 Y Y N N N 30 N Y* N N N 40 N Y N N N 50 N N Y* N N 60 N N N Y N 70 N N N Y* N 80 N N N Y Y 90 N N Y 100 N N Y* Bogdan L. Vrusias © 2006 8

AI – CS 289 Fuzzy Logic Example: Air Conditioner 2. Determine Fuzzy Sets: Fan

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

AI – CS 289 Fuzzy Logic Example: Air Conditioner 3. Elicit and construct fuzzy

AI – CS 289 Fuzzy Logic Example: Air Conditioner 3. Elicit and construct fuzzy rules RULE 1: RULE 2: RULE 3: RULE 4: RULE 5: IF IF IF 16 th October 2006 temp is temp is cold cool pleasant warm hot THEN THEN speed is speed is Bogdan L. Vrusias © 2006 minimal slow medium fast blast 10

AI – CS 289 Fuzzy Logic Example: Air Conditioner 4. Encode into an Expert

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

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Fuzzification – Affected fuzzy

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Fuzzification – Affected fuzzy sets: COOL and PLEASANT COOL(T) = – T / 5 + 3. 5 PLSNT(T) = T /2. 5 - 6 = – 16 / 5 + 3. 5 = 0. 3 Temp=16 m. COLD 0 16 th October 2006 = 16 /2. 5 - 6 = 0. 4 m. COOL 0. 3 m. PLEASANT 0. 4 Bogdan L. Vrusias © 2006 m. WARM 0 m. HOT 0 12

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Inference RULE 1: RULE

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Inference RULE 1: RULE 2: RULE 3: RULE 4: RULE 5: IF IF IF 16 th October 2006 temp is temp is cold cool pleasant warm hot THEN THEN speed is speed is Bogdan L. Vrusias © 2006 minimal slow medium fast blast 13

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Inference RULE 2: IF

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Inference RULE 2: IF temp is cool (0. 3) THEN RULE 3: IF temp is pleasant (0. 4) THEN 16 th October 2006 Bogdan L. Vrusias © 2006 speed is slow (0. 3) speed is medium (0. 4) 14

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Composition speed is slow

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Composition speed is slow (0. 3) + 16 th October 2006 speed is medium (0. 4) Bogdan L. Vrusias © 2006 15

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Defuzzification COG = 0.

AI – CS 289 Fuzzy Logic Example: Air Conditioner • Defuzzification 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. 3(11) + 0. 4(5) + 0. 25 = 45. 54 rpm 16 th October 2006 Bogdan L. Vrusias © 2006 16

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem m w g M

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem m w g M 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. 16 th October 2006 Bogdan L. Vrusias © 2006 17

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem nb nm nb ns

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem nb nm nb ns az ps pb nm w 16 th October 2006 pm pb pm ns nm ns ps az nb ns az ps ps ns ps pm nm pb nb nm nb: negative big, nm: negative medium, ps: positive small, pm: positive medium, IF AND THEN ps θ w F is is is pm ns ns: negative small az: approximately zero pb: positive big negative medium approximately zero negative medium Bogdan L. Vrusias © 2006 18

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem The fuzzy sets for

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem The fuzzy sets for θ, and F are based on the linear equation μ(x)=ax + b, and are defined based on the following table: w w m(w)=1 if w= m(w)=0 if w 16 th October 2006 Bogdan L. Vrusias © 2006 19

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Based on the

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 20

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Fuzzification i) Determine

AI – CS 289 Fuzzy Logic 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 16 th October 2006 Bogdan L. Vrusias © 2006 21

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Fuzzification iii) Compute

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Fuzzification iii) Compute membership functions 1 1 m 1/22. 5 = m /17. 5 m θ: pm m = 0. 78 22. 5 45 50 67. 5 45 50 1 θ: pb 67. 5 1/22. 5 = m /5 m m = 0. 22 45 67. 5 1 w: az m -11. 25 16 th October 2006 50 -5 1/11. 25 = m /6. 25 0 10 Bogdan L. Vrusias © 2006 m = 0. 56 22

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Inference 1. IF

AI – CS 289 Fuzzy Logic 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 16 th October 2006 Bogdan L. Vrusias © 2006 23

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Composition ps pb

AI – CS 289 Fuzzy Logic Example: Cart Pole Problem • Composition ps pb • Defuzzification Co. G 16 th October 2006 Bogdan L. Vrusias © 2006 24

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Step 1:

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 25

AI – CS 289 Fuzzy Logic 16 th October 2006 Bogdan L. Vrusias ©

AI – CS 289 Fuzzy Logic 16 th October 2006 Bogdan L. Vrusias © 2006 26

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Step 2:

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 27

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Fuzzy sets

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Fuzzy sets

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Fuzzy sets

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Fuzzy sets

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Step 3:

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 32

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System The square

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System The rule

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Rule Base

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Cube FAM

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Step 4:

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 37

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Step 5:

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 38

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Tune the

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 43

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Modified fuzzy

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Cube FAM

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Three-dimensional plots

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

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System Tuning fuzzy

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 48

AI – CS 289 Fuzzy Logic Case Study: Building a Fuzzy System 4. Review

AI – CS 289 Fuzzy Logic 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. 16 th October 2006 Bogdan L. Vrusias © 2006 49

AI – CS 289 Fuzzy Logic Summary • Process of developing a fuzzy expert

AI – CS 289 Fuzzy Logic 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 16 th October 2006 Bogdan L. Vrusias © 2006 50