fuzzy logic and fuzzy control - nju.edu.cn

41
INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 Fuzzy Logic and Fuzzy Control Fuzzy Logic Zadeh defines fuzzy logic (FL) two important concepts Fuzzy Rules fuzzy rules Example of Fuzzification Defuzzification Fuzzy Controllers Why fuzzy control? Example of fuzzy controller

Upload: others

Post on 09-Dec-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy Logic and Fuzzy Control

n  Fuzzy Logic �•  Zadeh defines fuzzy logic (FL) �•  two important concepts "�

n  Fuzzy Rules�•  fuzzy rules�•  Example of Fuzzification �•  Defuzzification�

n  Fuzzy Controllers�l  Why fuzzy control? �l  Example of fuzzy controller

Page 2: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy Logic

•  Zadeh defines fuzzy logic (FL) as a logical system, which is an extension of multivalued logic �

•  FL is not based on a closed world model (we don’t assume� everything is known) �•  FL (& crisp logic) state objective descriptions/measures�•  FL does not require statistical independence of variables�•  In FL, the absence of a fact doesn’t imply anything �•  A FL membership value persists after observation �

Page 3: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Fuzzy Logic

Page 4: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy Logic

Page 5: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

The  more  complex  a  system  is,  the  more  it  involves  intelligent  behavior,  the  more  likely  it  is  that  fuzzy  logic  will  provide  a  good  approach.

Fuzzy Logic

two  important concepts within FL : �

•  linguistic variable �

•  fuzzy if-then rule

Page 6: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

linguistic variable �

Fuzzy Logic

Page 7: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

•  Concentration hedges (e.g. very) �

•  Dilation hedges

Fuzzy Logic

hedges

Page 8: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy Rules �•  Have antecedent part and consequent part�

Page 9: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy Rules

�•  Mamdani-type fuzzy rule: �If X1 is A1 and ... and Xn is An then Y is Bj ��•  TSK-type fuzzy rule: �If X1 is A1 and ... and Xn is An then Y = p0 + p1X1 + ... + pnXn��The default type of rule we use is the Mamdani type. �

Page 10: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Mamdani-type fuzzy rule

Page 11: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

TSK FUZZY RULE

Page 12: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzifica)on    

Fuzzification is the combining of the antecedent sets (the if- side of the rule) ��We use a gas flow regulator for a furnace as an example. �• Input parameters: indoor temp., outdoor temp., 5-min. delta temp.�• Output parameter: change in gas flow �

Page 13: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy  Set  Defini)on    Now  we  must  define  the  fuzzy  sets  over  each  parameter.    We  decide  to  use  triangular  membership  func)ons.    First  decide  how  many  sets  per  parameter,  then  decide  range  for  each:    •  For  the  InTemp  parameter,  we  define  three  fuzzy  sets:  cool,  comfortable,  and  

too_warm.    •  For  OutTemp,  we  have  five  fuzzy  sets  defined:  very_cold,  chilly,  warm,  

very_warm,  and  hot.      •  For  DeltaInTemp,  we  define  five  fuzzy  sets:  large_negaAve,  small_negaAve,  

near_zero,  small_posiAve,  and  large_posAve.    •  For  our  output  parameter  FlowChange,  we  define  five  fuzzy  sets:  

decrease_greatly,  decrease_small,  no_change,  increase_small,  and  increase_greatly.  

 Number  of  membership  func)ons  for  a  parameter  depends  on  the  situa)on.  

Page 14: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Define  the  Rule  Set    Possible rules: ��Rule 1: If InTemp is comfortable and DeltaInTemp is near_zero, then FlowChange is no_change. ��Rule 2: If OutTemp is chilly and DeltaInTemp is small_negative, then FlowChange is increase_small. ��Rule 3: If InTemp is too_warm and DeltaInTemp is large­_positive, then FlowChange is decrease_greatly. ��Rule 4: If InTemp is cool and DeltaInTemp is near_zero, then FlowChange is increase_small. �… �

Page 15: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Define  the  Membership  Func)ons    

(We define only those we need for our example rules.)  For inside temperature (intemp):  

⎭⎬⎫

⎩⎨⎧ ++=

700

601

501cool

⎭⎬⎫

⎩⎨⎧ ++=

800

701

600ecomfortabl

⎭⎬⎫

⎩⎨⎧ ++=

901

801

700_ warmtoo

Page 16: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Define  the  Membership  Func)ons,  Cont’d.    For DeltaInTemp:  

⎭⎬⎫

⎩⎨⎧ ++=

⎭⎬⎫

⎩⎨⎧

+++

−=

⎭⎬⎫

⎩⎨⎧ +

−+

−=

61

41

20_arg

20

01

20_

00

21

40_

positiveel

zeronear

negativesmall

For OutTemp:

⎭⎬⎫

⎩⎨⎧ ++=

700

501

300chilly

(These are all we need for our rules.)

Page 17: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Example of Fuzzification

Assume inside temperature is 67.5 F, change in temperature last five minutes is -1.6 F, and outdoor temperature is 52 F.  

Now find fuzzy values needed for our four example rules:  

For InTemp,

0.0)5.67( and ,75.0)5.67(,25.0)5.67( _ === warmtooecomfortablcool µµµ. For DeltaInTemp,

0.0)6.1( and ,2.0)6.1( ,8.0)6.1( _arg__ =−=−=− positiveelzeronearnegativesmall µµµ

For OutTemp,

9.0)52( =chillyµ.

Page 18: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fire  the  Fuzzy  Rules    Using Zadeh’s AND process:  

Rule 1: changeno _20.020.075.0 µ==∩

Rule 2: smallincrease _8.08.09.0 µ==∩

Rule 3: greatlydecrease _0.00.00.0 µ==∩

so Rule 3 doesn’t produce any output. Rule 3 is said to have fired but not to have been activated. Rule 4: smallincrease _2.02.025.0 µ==∩

Note that two rules result in the activation of increase_small.

for  FlowChange.  

for  FlowChange.  

for  FlowChange.  

for  FlowChange.  

Page 19: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Determine  Output  Fuzzy  Set  Ac)va)ons    

In our example, rules 1, 2, and 4 are activated. ��Two output fuzzy sets are activated: �no_change (by rule 1) �increase_small (by rules 2 and 4) ��Note that a fuzzy set can be activated by several rules

(often at different levels) �We can use various ways to obtain the output when

multiple rules fire; Zadeh’s OR is one common way. This results in an output level of 0.8 for increase_small�

Page 20: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Defuzzifica)on    

•  Combines set of if-then rules into a specific value of a control�(output) variable�•  Defuzzification is the process of getting a scalar out of the fuzzy

system. ��

Note: These rules are for changes in flow. �

Page 21: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Defuzzifica)on,  Con)nued    

Chop off consequent linguistic variable membership functions  at values obtained  Note that membership functions must have been established  with scalar values assigned to consequent variable scale  A common way to defuzzify is with the centroid (clipped center of gravity) method.  

∑=

ii

iii

x

xxOutput

)(

)(

µ

µ

Must specify how to deal with areas of overlap: count them once or twice.

Page 22: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Defuzzifica)on  of  Furnace  Gas  Flow  

DG,  increase  greatly;  DS,  decrease  slightly;  NC,  no  change;    

IS,  increase  slightly;  IG,  increase  greatly  

Page 23: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Other  Defuzzifica)on  Methods  (Each  represents  outputs  as  arrows  pushing  down  on  x-­‐axis.)    Max-­‐membership:  Take  centroid  of  membership  func)on  with  highest  value  (Output  =  1.0  in  example)    Mean-­‐max-­‐membership:  Average  value  on  the  domain  axis  (Output  =  0.5  in  example)    Center-­‐of-­‐maximum:  Each  membership  value  represented  by  one  arrow.    (Like  forces  pushing  on  a  lever.)  (Output  =  0.8  in  example)  

Page 24: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Measures  of  Fuzziness    

• Fuzziness  measures  for  discrete  fuzzy  sets  exist  

• Fuzziness  measures  are  metrics  of  fuzzy  uncertainty  

• These  measures  es)mate  average  ambiguity  in  fuzzy  sets  

• Goal:  to  describe  the  rela)onship  of  elements  to  sets  and  sets  to  one  another  

Page 25: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Fuzzy  Control  

• Largest  applica)on  of  fuzzy  logic  

• First  implemented  by  Mamdani  in  laboratory  in  1975  

• Thousands  of  commercial  and  industrial  applica)ons  today  

Page 26: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Why  Fuzzy  Control?    

*  Efficiently  incorporates  human  expert  informa)on    *  Does  not  require  a  mathema)cal  model  of  system    *  Produces  nonlinear  controllers    *  Easy  and  inexpensive  to  design    *  Easy  to  understand  

Page 27: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

The  Fuzzy  Controller  

System  being  controlled  

Fuzzify  Defuzzify  

Page 28: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

The  Fuzzy  Controller  

*  Provides  set  of  inputs  to  produce  desirable  outputs    *  Controller’s  ac)ons  defined  by  rule  base    *  To  build  rule  base:  

 1.  Iden)fy  and  name  input  variables  and  define  ranges    2.  Iden)fy  and  name  output  variables  and  define  ranges    3.  Define  fuzzy  membership  func)on  for  each  input  variable    4.  Build  rule  base  to  govern  controller    5.  Define  how  control  ac)ons  will  be  combined  to  provide      plant  inputs  

Page 29: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Example  Fuzzy  Controller    

•   Build  system  to  control  speed  of  train  

•   Specifically,  design  system  to  smoothly  slow  and  stop  train  from    any  speed  and  distance  from  sta)on  

Page 30: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Iden)fy  and  name  input  variables  and  define  ranges    

SPEED Linguistic Range

Low High

Fast 26.5 70 Medium Fast 6.5 46.5 Slow 2.5 10.5 Very Slow 1 4 Stopped 0 2

 

DISTANCE Linguistic Range

Low High

Far 1,500 ∞ Medium Far 100 3,000 Near 3 200 Very Near 1 5 At 0 2

Page 31: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Iden)fy  and  name  output  variables  and  define  ranges    

THROTTLE Linguistic Range

Low High

Full 60% 100% Medium 20% 80% Slight 3% 30% Very Slight 1% 5% No 0 2%

BRAKE Linguistic Range

Low High

Full 98% 100% Medium 95% 99% Slight 70% 97% Very Slight 20% 80% No 0 40%

Page 32: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Fuzzy  Membership  Func)ons  for  Speed  

Page 33: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Fuzzy  Membership  Func)ons  for  Brake  

%  

Page 34: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

 Build  Rule  Base  Matrix  

•   Build  matrix  of  input  variable  combina)ons    •   Each  matrix  posi)on  may  have  values  for  output  variables    •   If  one  output  variable  is  specified,  all  must  be    •   Shaded  area  on  next  figure  corresponds  to  rules:  

 As  speed  is  ‘stopped’  and  as  distance  is  ‘at’  then  do  ‘full  brake’    As  speed  is  ‘stopped’  and  as  distance  is  ‘at’  then  do  ‘no  throdle’  

 •   “AND”  together  the  inputs  to  produce  each  output  

Page 35: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Fuzzy  Rule  Base  Matrix  

Shaded  entry:  IF  (speed)  IS  (stopped)  AND  IF  (distance)  IS  (at)  

                                         THEN  (full  brake)  AND  (no  throdle)  

Page 36: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Determine  How  Control  Will  Occur  Usually use centroid defuzzification  Example: speed = 3 km/hr; distance = 1.8 m  Determine which membership functions are activated and

to   what values:    

speed: µVY-SLOW(3)=0.667  

µSLOW(3)=0.125  

µAT(1.8)=0.1  

µVY-NEAR(1.8)=0.4

distance:  

Page 37: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

3  km/hr  Ac)vates  Very  Slow  and  Slow  

Page 38: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

1.8  Meters  Ac)vates  at  and  very  near  

Page 39: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

 Rules  Ac)vated  with  speed  =  3  and  distance  =  1.8  

Page 40: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015 INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2014

Use  Centroid  Defuzzifica)on  to  Obtain  Output  

Page 41: Fuzzy Logic and Fuzzy Control - nju.edu.cn

INTRODUCTION TO COMPUTATIONAL INTELLIGENCE, Nanjing University Spring 2015

Summary  of  Controller  Opera)on    

•  Sample  inputs  

•  Determine  membership  values  ac)vated  by  inputs  

•  Determine  which  rules  fire  

•  Combine  relevant  membership  values  using  AND  operator  

•  Trace  ac)va)on  membership  values  back  through  output  func)ons  

•  Use  centroid  method  to  defuzzify  output  to  a  scalar