Fuzzy Systems Mamdani-Assilian Controller Prof. Dr. Rudolf Kruse Christian Moewes {kruse,cmoewes}@iws.cs.uni-magdeburg.de Otto-von-Guericke University of Magdeburg Faculty of Computer Science Department of Knowledge Processing and Language Engineering R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 1 / 27 Outline 1. Motivation Architecture of a Fuzzy Controller Cartpole Problem Table-based Control Function Combination of Rules Defuzzification 2. Example: Engine Idle Speed Control 3. Example: Automatic Gear Box Architecture of a Fuzzy Controller knowledge base fuzzification interface not fuzzy R. Kruse, C. Moewes fuzzy measured values decision logic controlled system FS – Mamdani-Assilian Controller fuzzy defuzzification interface controller output not fuzzy Lecture 7 2 / 27 Example: Cartpole Problem (cont.) X1 is partitioned into 7 fuzzy sets. Support of fuzzy sets: intervals with length 1 4 of whole range X1 . Similar fuzzy partitions for X2 and Y . Next step: specify rules if ξ1 is A(1) and . . . and ξn is A(n) then η is B, A(1) , . . . , A(n) and B represent linguistic terms corresponding to µ(1) , . . . , µ(n) and µ according to X1 , . . . , Xn and Y . Let the rule base consist of k rules. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 3 / 27 Example: Cartpole Problem (cont.) nb θ̇ nb nm ns az ps pm pb nm nb nm nm ns ps ns ns θ az pb pm ps az ns nm nb ps pm pb ps ps pm pb pm ns 19 rules for cartpole problem, e.g. If θ is approximately zero and θ̇ is negative medium then F is positive medium. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 4 / 27 Definition of Table-based Control Function Measurement (x1 , . . . , xn ) ∈ X1 × . . . × Xn is forwarded to decision logic. Consider rule if ξ1 is A(1) and . . . and ξn is A(n) then η is B. Decision logic computes degree to ξ1 , . . . , ξn fulfills premise of rule. For 1 ≤ ν ≤ n, the value µ(ν) (xν ) is calculated. n o Combine values conjunctively by α = min µ(1) , . . . , µ(n) . For each rule Rr with 1 ≤ r ≤ k, compute n (1) (n) o αr = min µi1,r (x1 ), . . . , µin,r (xn ) . R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 5 / 27 Definition of Table-based Control Function II Output of Rr = fuzzy set of output values. Thus “cutting off” fuzzy set µir associated with conclusion of Rr at αr . So for input (x1 , . . . , xn ), Rr implies fuzzy set r) µxoutput(R : Y → [0, 1], 1 ,...,xn n (1) (n) o y 7→ min µi1,r (x1 ), . . . , µin,r (xn ), µir (y ) . (1) output(Rr ) (n) If µi1,r (x1 ) = . . . = µin,r (xn ) = 1, then µx1 ,...,xn (ν) = µir . output(Rr ) If for all ν ∈ {1, . . . , n}, µi1,r (xν ) = 0, then µx1 ,...,xn R. Kruse, C. Moewes FS – Mamdani-Assilian Controller = 0. Lecture 7 6 / 27 Combination of Rules The decision logic combines the fuzzy sets from all rules. The maximum leads to the output fuzzy set µoutput x1 ,...,xn : Y → [0, 1], y 7→ max 1≤r ≤k n n (1) (n) oo min µi1,r (x1 ), . . . , µin,r (xn ), µir (y ) . Then µoutput x1 ,...,xn is passed to defuzzification interface. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 7 / 27 Rule Evaluation 1 positive small 1 approx. zero θ 0 1 15 25 30 45 positive medium 0.6 positive small min 0.5 0.3 1 F θ̇ −8 −4 0 1 8 approx. zero 0 min 1 3 6 9 positive medium 0.5 θ 0 15 25 30 45 F θ̇ −8 −4 0 0 8 Rule evaluation for Mamdani-Assilian controller. 1 3 6 max Input tuple (25, −4) leads to fuzzy output. Crisp output is determined by defuzzification. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller 9 F 0 1 4 4.5 7.5 9 Lecture 7 8 / 27 Defuzzification So far: mapping between each (n1 , . . . , nn ) and µoutput x1 ,...,xn . Output = description of output value as fuzzy set. Defuzzification interface derives crisp value from µoutput x1 ,...,xn . This step is called defuzzification. Most common methods: • max criterion, • mean of maxima, • center of gravity. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 9 / 27 The Max Criterion Method Choose an arbitrary y ∈ Y for which µoutput x1 ,...,xn reaches the maximum membership value. Advantages: • Applicable for arbitrary fuzzy sets. • Applicable for arbitrary domain Y (even for Y 6= IR). Disadvantages: • • • • Rather class of defuzzification strategies than single method. Which value of maximum membership? Random values and thus non-deterministic controller. Leads to discontinuous control actions. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 10 / 27 The Mean of Maxima (MOM) Method Preconditions: (i) Y is interval output ′ (ii) YMax = {y ∈ Y | ∀y ′ ∈ Y : µoutput x1 ,...,xn (y ) ≤ µx1 ,...,xn (y )} is non-empty and measurable (iii) YMax is set of all y ∈ Y such that µoutput x1 ,...,xn is maximal Crisp output value = mean value of YMax . if YMax is infinite: if YMax is finite: η= 1 X |YMax | y ∈Y i Max yi R y ∈Y η = R Max y dy y ∈YMax dy MOM can lead to discontinuous control actions. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 11 / 27 Center of Gravity (COG) Method Same preconditions as MOM method. η = center of gravity/area of µoutput x1 ,...,xn If Y is finite, then η= P η= R yi ∈Y yi P · µoutput x1 ,...,xn (yi ) output yi ∈Y µx1 ,...,xn (yi ) . If Y is infinite, then R. Kruse, C. Moewes y ∈Y y R · µoutput x1 ,...,xn (y ) dy output y ∈Y µx1 ,...,xn (y ) dy FS – Mamdani-Assilian Controller . Lecture 7 12 / 27 Center of Gravity (COG) Method Advantages: • Nearly always smooth behavior, • If certain rule dominates once, not necessarily dominating again. Disadvantage: • No semantic justification, • Long computation, • Counterintuitive results possible. Also called center of area (COA) method: take value that splits µoutput x1 ,...,xn into 2 equal parts. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 13 / 27 Example Task: compute ηCOG and ηMOM of fuzzy set shown below. Based on finite set Y = 0, 1, . . . , 10 and infinite set Y = [0, 10]. µoutput x1 ,...,xn (y ) 1.0 ηCOG ηMOM 0.8 0.6 0.4 0.2 y 0 0 R. Kruse, C. Moewes 1 2 3 4 5 6 7 FS – Mamdani-Assilian Controller 8 9 10 Lecture 7 14 / 27 Example for COG Continuous and Discrete Output Space ηCOG = R 10 0 0 = ≈ ηCOG = = y · µoutput x1 ,...,xn (y ) dy R 10 R5 0 µoutput x1 ,...,xn (y ) dy 0.4y dy + 57 (0.2y − 0.6)y dy + 710 0.8y dy 5 · 0.4 + 2 · 0.8+0.4 + 3 · 0.8 2 R R 38.7333 ≈ 6.917 5.6 0.4 · (0 + 1 + 2 + 3 + 4 + 5) + 0.6 · 6 + 0.8 · (7 + 8 + 9 + 10) 0.4 · 6 + 0.6 · 1 + 0.8 · 4 36.8 ≈ 5.935 6.2 R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 15 / 27 Example for MOM Continuous and Discrete Output Space R 10 y dy ηMOM = R7 10 7 dy = 25.5 50 − 24.5 = 10 − 7 3 = 8.5 7 + 8 + 9 + 10 4 34 = 4 ηMOM = = 8.5 R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 16 / 27 Problem Case for MOM and COG 1 µoutput x1 ,...,xn 0 −2 −1 0 1 2 What would be the output of MOM or COG? Is this desirable or not? R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 17 / 27 Outline 1. Motivation 2. Example: Engine Idle Speed Control 3. Example: Automatic Gear Box Example: Engine Idle Speed Control VW 2000cc 116hp Motor (Golf GTI) R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 18 / 27 Structure of the Fuzzy Controller R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 19 / 27 Deviation of the Number of Revolutions dREV 1.00 0.75 0.50 nb nm ns −50 −30 zr ps pm 30 50 pb 0.25 0 −70 R. Kruse, C. Moewes −10 10 FS – Mamdani-Assilian Controller 70 Lecture 7 20 / 27 Gradient of the Number of Revolutions gREV 1.00 0.75 0.50 nb nm ns zr ps pm pb 0.25 0 -400 R. Kruse, C. Moewes -70 -40 -30 -20 20 30 FS – Mamdani-Assilian Controller 40 70 -400 Lecture 7 21 / 27 Change of Current for Auxiliary Air Regulator dAARCUR 1.00 0.75 nm ns zr ps pm pb 0 −25 −20 −15 −10 −5 0 5 10 15 0.50 nh nb ph 0.25 R. Kruse, C. Moewes FS – Mamdani-Assilian Controller 20 Lecture 7 25 22 / 27 Rule Base If the deviation from the desired number of revolutions is negative small and the gradient is negative medium, then the change of the current for the auxiliary air regulation should be positive medium. dREV R. Kruse, C. Moewes nb nm ns az ps pm pb nb ph ph pb ps az az ns nm pb pb pm ps az ns ns ns pb pm ps az az ns nm gREV az pm pm ps az ns ns nb FS – Mamdani-Assilian Controller ps pm ps az az ns nb nb pm ps ps az nm nm nb nb pb ps az az ns nb nh nh Lecture 7 23 / 27 Performance Characteristics R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 24 / 27 Outline 1. Motivation 2. Example: Engine Idle Speed Control 3. Example: Automatic Gear Box Example: Automatic Gear Box I VW gear box with 2 modes (eco, sport) in series line until 1994. Research issue since 1991: individual adaption of set points and no additional sensors. Idea: car “watches” driver and classifies him/her into calm, normal, sportive (assign sport factor [0, 1]), or nervous (calm down driver). Test car: different drivers, classification by expert (passenger). Simultaneous measurement of 14 attributes, e.g. , speed, position of accelerator pedal, speed of accelerator pedal, kick down, steering wheel angle. R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 25 / 27 Example: Automatic Gear Box II Continuously Adapting Gear Shift Schedule in VW New Beetle R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 26 / 27 Example: Automatic Gear Box III Technical Details Optimized program on Digimat: 24 byte RAM 702 byte ROM Runtime: 80 ms 12 times per second new sport factor is assigned. Research topics: When fuzzy control? How to find fuzzy rules? R. Kruse, C. Moewes FS – Mamdani-Assilian Controller Lecture 7 27 / 27