Вы находитесь на странице: 1из 10

5.

Fuzzy Logic Fuzzy Logic


• Introduced by Lotfi Zadeh, UC Berkeley • Empirical model
• Process data allowed partial set membership instead • Simple rule-based approach: IF x THEN y
of “crisp membership” Here no numbers but fuzzy set memberships, e.g.:
IF (temp is too_cool) AND (time is progressed) THEN (cool fast)
• Deals with noisy, imprecise,vague, ambiguous data
• Imprecise, but descriptive
• Higher reliability
• Mimic human control logic
• “People also do not require precise numerical input”
• Robust, requires little tuning
• These slides are based on “Fuzzy Logic Tutorial” by
Encoder Newsletter of the Seattle Robotics Society • Can model non-linear systems that are mathematically
very difficult (or impossible) to model
Bräunl 2003 1 Bräunl 2003 2

5.1 Fuzzy Logic Guide Fuzzy Logic Example


• Consider inputs, outputs, system control, failure modes
• Determine input/output relationships Fuzzy logic temperature control of a physical process
• Use minimum number of input variables, e.g.
– error (control difference) Heater
– change-of-error (error derivative) Target Fuzzy Physical
temp. Logic Process
• Set up system as a number of IF-THEN rules Cooler
• Create membership functions, giving meaning to
input/output terms
• Create pre-/post-processing terms Feedback temperature

• Test system, evaluate, tune, and test again


Bräunl 2003 3 Bräunl 2003 source: Encoder, Seattle Robotics Soc. 4
Fuzzy Logic Example Linguistic Variables
Heater
Fuzzy Physical
Logic
Cooler
Process Introduction of linguistic variables:
• Input 1: “error”: positive (P), zero (Z), negative (N)
• Input 2: “error-dot”: positive (P), zero (Z), negative (N)
• Output: heat (H), do_nothing (–), cool (C)
• Target input: temperature
• Error feedback: negative, zero, positive Error = target – feedback
• Error-dot feedback: negative, zero, positive (P = too cold, Z = just right, N = too hot)
• Fuzzy logic output: heat, cool, or “do nothing” ErrorDot = d Error / dt
(P = getting colder, Z = no change, N = getting hotter)
Output H = activate heater, “–” = do nothing, C = activate cooler
Bräunl 2003 5 Bräunl 2003 6

5.2 Linguistic Rules Linguistic Rules


Set up linguistic rules: 1. IF too_hot AND getting_colder THEN ??
IF-THEN (antecedent and consequent blocks) 2. IF just_right AND getting_colder THEN ??
3. IF too_cold AND getting_colder THEN ??
Example: 4. IF too_hot AND no_change THEN ??
IF too_hot AND getting_hotter THEN cool 5. IF just_right AND no_change THEN ??
6. IF too_cold AND no_change THEN ??
7. IF too_hot AND getting_hotter THEN ??
target-feedback=N d(target-feedback)/dt=N output = C
8. IF just_right AND getting_hotter THEN ??
9. IF too_ cold AND getting_hotter THEN ??
Bräunl 2003 7 Bräunl 2003 8
Linguistic Rules Rule Matrix
1. IF too_hot AND getting_colder THEN cool Build rule matrix from linguistic rules
2. IF just_right AND getting_colder THEN heat
too cold just right too hot
3. IF too_cold AND getting_colder THEN heat
4. IF too_hot AND no_change THEN cool getting cool heat heat
colder
5. IF just_right AND no_change THEN do_nothing
no change cool do nothing heat
6. IF too_cold AND no_change THEN heat
getting cool cool heat
7. IF too_hot AND getting_hotter THEN cool hotter
8. IF just_right AND getting_hotter THEN cool
9. IF too_ cold AND getting_hotter THEN heat
Bräunl 2003 9 Bräunl 2003 source: Encoder, Seattle Robotics Soc. 10

5.3 Membership Functions Membership Functions


• Membership function is a graphical representation of • Shape of membership function is usually triangle
“magnitude of participation” of each input (but could also be trapezoidal or other)
• Associates weighting with each input • Height usually normalized to 1 (so in total: [0..1])
• Defines overlaps between inputs • Width of the base of function depends on number of functions
• Determines output response • Shouldering is used to lock height in an outer function
(leftmost and rightmost functions evaluate to 1 to the outsides)
• Fuzzification: Translating input values to fuzzy set
• Center points of functions evaluate to 1
memberships
• Overlap is usually 50% at base of function
• Defuzzification: Translating fuzzy output back to crisp
system output (e.g. a number)

Bräunl 2003 11 Bräunl 2003 12


Membership Functions Membership Functions
• Add shoulders

too hot too cold (shoulder)


(shoulder)

height too hot just right too cold too hot just right too cold

h&r r&c

width
Bräunl 2003 13 Bräunl 2003 14

Membership Functions Membership Functions


• Add values, here: for error (temperature difference in deg. Celsius) • Add values, here for error_dot (temperature change in deg. Celsius / minute)

1.0 1.0
Degree of Membership

Degree of Membership
too hot too cold (shoulder) getting hotter getting colder
(shoulder) (shoulder) (shoulder)

0.5 too hot just right too cold 0.5 getting no change getting
hotter colder

h&r r&c gh & nc nc & gc


0.0 0.0
-4 -2 0 +2 +4 -10 -5 0 +5 +10
Error in degrees Celsius Error_dot in degrees Celsius / minute
Bräunl 2003 15 Bräunl 2003 16
Membership Functions Membership Functions
Degree of Membership

Degree of Membership
1.0 1.0

0.5 too hot just right too cold 0.5 too hot just right too cold

h&r r&c h&r r&c


0.0 0.0
-4 -2 0 +2 +4 -4 -2 0 +2 +4
Error in degrees Celsius Error in degrees Celsius

Example Example
• Error = –1 • Error = +5
⇒ Membership(too_hot) = 0.5 ⇒ Membership(too_hot) = 0.0
⇒ Membership(just_right) = 0.5 ⇒ Membership(just_right) = 0.0
⇒ Membership(too_cold) = 0.0 ⇒ Membership(too_cold) = 1.0
Bräunl 2003 17 Bräunl 2003 18

Membership Functions 5.4 Inferences


Note • Deviation from Boolean logic (true, false or 1, 0)
• Sum of all membership values for a certain input value • Now we have continuous membership values [0..1]
is always 1.0 • Build logical sums using membership values in
• Different value range for different input variables combination with rule matrix
(e.g. error and error_dot) • Use minimum of all antecedent values (AND-part)
• Membership values (antecedents) are evaluated for the for output
produced conclusion (consequent)

Bräunl 2003 19 Bräunl 2003 20


Inferences Inferences
• too_hot = 0.5, just_right = 0.5, too_cold = 0.0
• getting_hotter = 0.5, no_change = 0.5, getting_colder = 0.0
Example:
error = –1 1. IF too_hot AND getting_colder THEN cool
2. IF just_right AND getting_ colder THEN heat
error_dot = –2.5
3. IF too_cold AND getting_ colder THEN heat
4. IF too_hot AND no_change THEN cool
Membership error:
5. IF just_right AND no_change THEN do_nothing
too_hot = 0.5, just_right = 0.5, too_cold = 0.0 6. IF too_cold AND no_change THEN heat
Membership error_dot 7. IF too_hot AND getting_hotter THEN cool
getting_hotter = 0.5, no_change = 0.5, getting_colder = 0.0 8. IF just_right AND getting_hotter THEN cool
9. IF too_ cold AND getting_hotter THEN heat
Bräunl 2003 21 Bräunl 2003 22

Inferences Inferences
use use
• too_hot = 0.5, just_right = 0.5, too_cold = 0.0 • too_hot = 0.5, just_right = 0.5, too_cold = 0.0
• getting_hotter = 0.5, no_change = 0.5, getting_colder = 0.0 minimum • getting_hotter = 0.0, no_change = 0.5, getting_colder = 0.5 minimum
1. IF too_hot AND getting_colder THEN cool 0.5 & 0.0 = 0.0 1. IF too_hot AND getting_colder THEN cool
2. IF just_right AND getting_ colder THEN heat 0.5 & 0.0 = 0.0 2. IF just_right AND getting_ colder THEN heat
3. IF too_cold AND getting_ colder THEN heat 0.0 & 0.0 = 0.0 3. IF too_cold AND getting_ colder THEN heat
4. IF too_hot AND no_change THEN cool 0.5 & 0.5 = 0.5 4. IF too_hot AND no_change THEN cool 0.5 & 0.5 = 0.5
5. IF just_right AND no_change THEN do_nothing 0.5 & 0.5 = 0.5 5. IF just_right AND no_change THEN do_nothing 0.5 & 0.5 = 0.5
6. IF too_cold AND no_change THEN heat 0.0 & 0.5 = 0.0 6. IF too_cold AND no_change THEN heat
7. IF too_hot AND getting_hotter THEN cool 0.5 & 0.5 = 0.5 7. IF too_hot AND getting_hotter THEN cool 0.5 & 0.5 = 0.5
8. IF just_right AND getting_hotter THEN cool 0.5 & 0.5 = 0.5 8. IF just_right AND getting_hotter THEN cool 0.5 & 0.5 = 0.5
9. IF too_ cold AND getting_hotter THEN heat 0.0 & 0.5 = 0.0 9. IF too_ cold AND getting_hotter THEN heat
Bräunl 2003 23 Bräunl 2003 24
5.5 Output Combination Output Combination
• Find out “firing strength” of each rule MAX-MIN
• Test magnitude of all rules – select highest one
• Combine logical outputs for each rule must be Use horizontal coordinate of “fuzzy centroid” as output
combined before defuzzification Note: This method does not combine individual results!
• Combining rule outputs MAX-DOT
– MAX-MIN • Scale each member function to fit under its peak value,
take the horizontal coordinate of the fuzzy centroid of the
– MAX-DOT (MAX-PRODUCT) composite area as output.
– AVERAGING This shrinks all member functions to their peaks equal the
– ROOT-SUM-SQUARE magnitude of the respective function.
Note: This method prodruces a smooth, continuous output
combining all active rules
Bräunl 2003 25 Bräunl 2003 26

Output Combination Output Combination


1. IF too_hot AND getting_colder THEN cool 0
2. IF just_right AND getting_ colder THEN heat 0
AVERAGING 3. IF too_cold AND getting_ colder THEN heat 0
• Each function is clipped at the average value and the fuzzy centroid 4. IF too_hot AND no_change THEN cool 0.5
5. IF just_right AND no_change THEN do_nothing 0.5
of the composite area is computer 6. IF too_cold AND no_change THEN heat 0
Note: This method does not give increased weight if multiple rules 7. IF too_hot AND getting_hotter THEN cool 0,5
8. IF just_right AND getting_hotter THEN cool 0.5
generate the same output member! 9. IF too_ cold AND getting_hotter THEN heat 0
ROOT-SUM-SQUARE
• Combination of several approaches: Output membership functions:
Scale functions to respective magnitudes with root of sum of squares, “cool” = √(rule12 + rule42 + rule72 + rule82 )
compute fuzzy centroid of composite area. = √(0 + 0.52 +0.52 + 0.52)
Note: This method gives a good weighted influence to all firing rules. = √0.75
= 0.866
Bräunl 2003 27 Bräunl 2003 28
Output Combination Output Combination
1. IF too_hot AND getting_colder THEN cool 0 1. IF too_hot AND getting_colder THEN cool 0
2. IF just_right AND getting_ colder THEN heat 0 2. IF just_right AND getting_ colder THEN heat 0
3. IF too_cold AND getting_ colder THEN heat 0 3. IF too_cold AND getting_ colder THEN heat 0
4. IF too_hot AND no_change THEN cool 0.5 4. IF too_hot AND no_change THEN cool 0.5
5. IF just_right AND no_change THEN do_nothing 0.5 5. IF just_right AND no_change THEN do_nothing 0.5
6. IF too_cold AND no_change THEN heat 0 6. IF too_cold AND no_change THEN heat 0
7. IF too_hot AND getting_hotter THEN cool 0,5 7. IF too_hot AND getting_hotter THEN cool 0,5
8. IF just_right AND getting_hotter THEN cool 0.5 8. IF just_right AND getting_hotter THEN cool 0.5
9. IF too_ cold AND getting_hotter THEN heat 0 9. IF too_ cold AND getting_hotter THEN heat 0

Output membership functions: Output membership functions:


“do_nothing” = √(rule52) “heat” = √(rule22 + rule32 + rule62 + rule92)
= √(0.52) = √(0 + 0 + 0 + 0)
= 0.5 = 0.0

Bräunl 2003 29 Bräunl 2003 30

5.6 Defuzzification Defuzzification


• Output Membership Function (action to be taken)
• Defuzzification of combined results of inference process
• Result will be a crisp (numeric) output cool do_nothing heat
1.0

Degree of Membership
• Calculation of “fuzzy centroid”:

1. Multiply the weighted strength of each output member function


by the respective member function center points 0.5
2. Add these values
3. Divide area by the sum of the weighted member function c&n n&h
strength
0.0
-100 -50 0 +50 +100
Percent output (-100..-1 cooling, +1..+100 heating)
Bräunl 2003 31 Bräunl 2003 32
Defuzzification Defuzzification
• Output Membership Function (action to be taken) • Output Membership Function (action to be taken)

cool do_nothing heat cool do_nothing heat


1.0 1.0
Degree of Membership

Degree of Membership
0.87 0.87
Combined rule results Combined rule results
cool = 0.866 cool = 0.866
do_nothing = 0.5 do_nothing = 0.5
0.5 0.5
heat = 0.0 heat = 0.0

Calculate fuzzy centroid


0.0 0.0
-100 -50 0 +50 +100 -100 -50 0 +50 +100
Percent output (-100..-1 cooling, +1..+100 heating) -63.4 Percent output (-100..-1 cooling, +1..+100 heating)
Bräunl 2003 33 Bräunl 2003 34

Defuzzification Defuzzification
• Input: • How to calculate centroid
– error = –1 – graphically: intuitively
– error_dot = –2.5 – numerically: see formula below

N
• Output: ∑ (center ⋅ strength )
i i “Moment”
– activate cooling at 63.4% Output = i =1
N N is number of output members
∑ strengthi
i =1
(here: 3)

Bräunl 2003 35 Bräunl 2003 36


1.0
0.87
1.0

Defuzzification 0.87
Defuzzification 0.5

0.5

0.0
1.0 -100 -50 0 +50 +100
0.87
0.0
-100 -50 0 +50 +100
centercool ⋅ strengthcool + centernothing ⋅ strengthnothing + centerheat ⋅ strengthheat
0.5
with shoulders: adjust formula Output =
strengthcool + strengthnothing + strengthheat
by moving centers
1.0
− 100 ⋅ 0.866 + 0 ⋅ 0.5 + 100 ⋅ 0
0.0 0.87
-100 -50 0 +50 +100 Output = = −63.4
without shoulders: simple formula 0.866 + 0.5 + 0.0
0.5
N

∑ (center ⋅ strength )
i i
Result: Activate cooling at 63.4%
Output = i =1
N

∑ strength
i =1
i
0.0
-100 -50 0 +50 +100
Bräunl 2003 37 Bräunl 2003 38

5.7 Tuning 5.8 Applications


Tuning of a fuzzy system can be accomplished by: Fuzzy control can be applied to a number of control problems
• Changing rule antecedents for example:
• Changing rule conclusions • Motor control
• Changing centers of the input/output membership functions • Driving
• Balancing
• Adding additional membership functions
e.g. negative, low_neg, zero, low_pos, positive • Walking
→ additional rules • …

Bräunl 2003 39 Bräunl 2003 40

Вам также может понравиться