Week7 Fuzzy Logic Tutorial

Published on June 2016 | Categories: Types, Instruction manuals | Downloads: 48 | Comments: 0 | Views: 325
of 54
Download PDF   Embed   Report

Week7 Fuzzy Logic Tutorial

Comments

Content


October 2005 0
Fuzzy Expert Systems

CS364 Artificial Intelligence
October 2005 1
Recap
Example: Air Conditioner
Example: Cart Pole Problem
Case Study: Building a Fuzzy Expert System
Summary
Fuzzy Expert Systems

October 2005 2
1. Specify the problem; define linguistic variables.
Recap

2. Determine fuzzy sets.
3. Elicit and construct fuzzy rules.
4. Encode the fuzzy sets, fuzzy rules and procedures
to perform fuzzy inference into the expert system.
5. Evaluate and tune the system.
Process of developing a fuzzy expert system:
October 2005 3
• Fuzzification: definition of fuzzy sets, and
determination of the degree of membership of crisp
inputs in appropriate fuzzy sets.
Recap

• 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
Operation of a fuzzy expert system:
October 2005 4
Recap
Example: Air Conditioner
Example: Cart Pole Problem
Case Study: Building a Fuzzy Expert System
Summary
Fuzzy Expert Systems

October 2005 5
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
October 2005 6
Example: Air Conditioner

2. Determine Fuzzy Sets: Temperature

Temp
(
0
C).
COLD COOL PLEASANT WARM HOT
0 Y* N N 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 N N Y
30 N N N N Y*
Temp
(
0
C).
COLD COOL PLEASANT WARM HOT
0<

(T)<1


(T)=1


(T)=0
October 2005 7
Example: Air Conditioner

2. Determine Fuzzy Sets: Temperature


Temperature Fuzzy Sets
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 5 10 15 20 25 30
Temperature Degrees C
T
r
u
t
h

V
a
l
u
e
Cold
Cool
Pleasent
Warm
Hot
Temperature Fuzzy Sets
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 5 10 15 20 25 30
Temperature Degrees C
T
r
u
t
h

V
a
l
u
e
Cold
Cool
Pleasent
Warm
Hot
October 2005 8
Example: Air Conditioner

2. Determine Fuzzy Sets: Fan Speed

Rev/sec
(RPM)
MINIMAL SLOW MEDIUM FAST BLAST
0 Y* N N N N
10 Y N N 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 N N Y
100 N N N N Y*
October 2005 9
Example: Air Conditioner

2. Determine Fuzzy Sets: Fan Speed

Speed Fuzzy Sets
0
0.2
0.4
0.6
0.8
1
0 10 20 30 40 50 60 70 80 90 100
Speed
T
r
u
t
h

V
a
l
u
e
MINIMAL
SLOW
MEDIUM
FAST
BLAST
October 2005 10
Example: Air Conditioner

3. Elicit and construct fuzzy rules

RULE 1: IF temp is cold THEN speed is minimal
RULE 2: IF temp is cool THEN speed is slow
RULE 3: IF temp is pleasant THEN speed is medium
RULE 4: IF temp is warm THEN speed is fast
RULE 5: IF temp is hot THEN speed is blast


October 2005 11
Example: Air Conditioner

3. Encode into an Expert System


4. 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
October 2005 12
Example: Air Conditioner

• Fuzzification


 Affected fuzzy sets: COOL and PLEASANT

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

0 0.3 0.4 0 0
October 2005 13
Example: Air Conditioner

• Inference


RULE 1: IF temp is cold THEN speed is minimal
RULE 2: IF temp is cool THEN speed is slow
RULE 3: IF temp is pleasant THEN speed is medium
RULE 4: IF temp is warm THEN speed is fast
RULE 5: IF temp is hot THEN speed is blast


October 2005 14
Example: Air Conditioner

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)
• Inference


October 2005 15
Example: Air Conditioner

• Composition


speed is slow (0.3) speed is medium (0.4)

+
October 2005 16
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.25 + 0.3(11) + 0.4(5) + 0.25

= 45.54rpm

October 2005 17
Recap
Example: Air Conditioner
Example: Cart Pole Problem
Case Study: Building a Fuzzy Expert System
Summary
Fuzzy Expert Systems

October 2005 18
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, w of the pole .

M
m
g

w
October 2005 19
n
b
n
m
n
s
a
z
p
s
p
m
p
b
n
b
p
s
p
b
n
m
p
m
n
s
n
m
n
s
p
s
a
z
n
b
n
m
n
s
a
z
p
s
p
m
p
b
p
s
n
s
p
s
p
m
p
m
n
m
p
b
n
b
n
s
Example: Cart Pole Problem

θ

nb: negative big, nm: negative medium, ns: negative small az: approximately zero
ps: positive small, pm: positive medium, pb: positive big
IF is negative medium

and w is approximately zero
THEN F is negative medium
θ

w
October 2005 20
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)=1 if
w=

(w)=1 if
w=

(w)=0 if
w>=
w
October 2005 21
Example: Cart Pole Problem

(b) 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.
(a) Based on the fuzzy sets table draw three graphs showing
the fuzzy sets (nb, nm, ns, az, ps, pm, pb) for each θ, w,
and F individually.
October 2005 22
Example: Cart Pole Problem

Fuzzification

i) Determine where θ and the angular velocity fall in the table
θ: pm, pb
w: az

ii) Formulate possible rules from linguistic values obtained

IF θ is pm

AND w is az THEN F is pm
IF θ is pb

AND w is az THEN F is pb
October 2005 23
Example: Cart Pole Problem
Fuzzification

iii) Compute membership functions
-11.25 -5 0 10
22.5 45 50 67.5

45 50 67.5
1 1

1/22.5 =  /17.5

 = 0.78
θ: pm
θ: pb
67.5 50 45

1
1/22.5 =  /5

 = 0.22

1
w: az
1/11.25 =  /6.25

 = 0.56
October 2005 24
Example: Cart Pole Problem
Inference

The two premises in RULE 1 are conjunctive
 minimum of the two: min{0.78, 0.56}=0.56
1 IF θ is pm

AND w is az THEN F is pm
2 IF θ is pb

AND w 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

October 2005 25
Example: Cart Pole Problem
Composition

ps
pb
Defuzzification

3 0.2 (4 5 6) 0.56 (7 8) 0.22
5.30
0.2 0.56 0.56 0.56 0.22 0.22
SoG
       
= =
    
C
October 2005 26
Recap
Example: Air Conditioner
Example: Cart Pole Problem
Case Study: Building a Fuzzy Expert System
Summary
Fuzzy Expert Systems

October 2005 27
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.
Case Study: Building a Fuzzy
Expert System
Step 1: Specify the problem and define
linguistic variables
There are four main linguistic variables: average waiting time (mean
delay) m, repair utilisation factor of the service centre , number of
servers s, and initial number of spare parts n.
October 2005 28
Linguistic variables and their ranges
Linguistic Variable: Mean Delay, m
Linguistic Value Notation Numerical Range (normalised)
Very Short
Short
Medium
VS
S
M
[0, 0.3]
[0.1, 0.5]
[0.4, 0.7]
Linguistic Variable: Number of Servers, s
Linguistic Value Notation Numerical Range (normalised)
Small
Medium
Large
S
M
L
[0, 0.35]
[0.30, 0.70]
[0.60, 1]
Linguistic Variable: Repair Utilisation Factor, 
Linguistic Value Notation Numerical Range
Low
Medium
High
L
M
H
[0, 0.6]
[0.4, 0.8]
[0.6, 1]
Linguistic Variable: Number of Spares, n
Linguistic Value Notation Numerical Range (normalised)
Very Small
Small
Rather Small
Medium
Rather Large
Large
Very Large
VS
S
RS
M
RL
L
VL
[0, 0.30]
[0, 0.40]
[0.25, 0.45]
[0.30, 0.70]
[0.55, 0.75]
[0.60, 1]
[0.70, 1]
Linguistic Variable: Mean Delay, m
Linguistic Variable: Number of Servers, s
Linguistic Variable: Repair Utilisation Factor, 
Linguistic Variable: Number of Spares, n
October 2005 29
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.
October 2005 30
Fuzzy sets of Mean Delay m
0.1 0
1.0
0.0
0.2
0.4
0.6
0.8
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Mean Delay (normalised)
S VS M
Degree of
Membership
October 2005 31
Fuzzy sets of Number of Servers s
0.1 0
1.0
0.0
0.2
0.4
0.6
0.8
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
M L S
Degree of
Membership
Number of Servers (normalised)
October 2005 32
Fuzzy sets of Repair Utilisation Factor 
0.1 0
1.0
0.0
0.2
0.4
0.6
0.8
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Repair Utilisation Factor
M H L
Degree of
Membership
October 2005 33
Fuzzy sets of Number of Spares n
0.1 0
1.0
0.0
0.2
0.4
0.6
0.8
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
S RS VS M RL L VL
Degree of
Membership
Number of Spares (normalised)
October 2005 34
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.
October 2005 35
The square FAM representation
October 2005 36
The rule table
Rule m s  n Rule m s  n Rule m s  n
1 VS S L VS 10 VS S M S 19 VS S H VL
2 S S L VS 11 S S M VS 20 S S H L
3 M S L VS 12 M S M VS 21 M S H M
4 VS M L VS 13 VS M M RS 22 VS M H M
5 S M L VS 14 S M M S 23 S M H M
6 M M L VS 15 M M M VS 24 M M H S
7 VS L L S 16 VS L M M 25 VS L H RL
8 S L L S 17 S L M RS 26 S L H M
9 M L L VS 18 M L M S 27 M L H RS
October 2005 37
Rule Base 1
1. If (utilisation_factor is L) then (number_of_spares is S)
2. If (utilisation_factor is M) then (number_of_spares is M)
3. If (utilisation_factor is H) then (number_of_spares is L)
4. If (mean_delay is VS) and (number_of_servers is S) then (number_of_spares is VL)
5. If (mean_delay is S) and (number_of_servers is S) then (number_of_spares is L)
6. If (mean_delay is M) and (number_of_servers is S) then (number_of_spares is M)
7. If (mean_delay is VS) and (number_of_servers is M) then (number_of_spares is RL)
8. If (mean_delay is S) and (number_of_servers is M) then (number_of_spares is RS)
9. If (mean_delay is M) and (number_of_servers is M) then (number_of_spares is S)
10.If (mean_delay is VS) and (number_of_servers is L) then (number_of_spares is M)
11.If (mean_delay is S) and (number_of_servers is L) then (number_of_spares is S)
12.If (mean_delay is M) and (number_of_servers is L) then (number_of_spares is VS)
October 2005 38
Cube FAM of Rule Base 2
VS VS VS
VS VS VS
VS VS VS
VL L M
H
S
VS VS VS
VS VS VS
VS VS VS
M
VS VS VS
VS VS VS
S S VS
L
s
L
VS S M
m
M
H
 
VS VS VS
L
VS S M
S
m
VS VS VS M
S S VS L
s
S VS VS
M
VS S M
m
VS S M
m
S
RS S VS M
M RS S L
s
S
M M S M
RL M RS L
s
October 2005 39
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.
October 2005 40
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.
October 2005 41
Three-dimensional plots for Rule Base 1
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.2
0.3
0.4
0.5
0.6
number_of_servers mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
October 2005 42
Three-dimensional plots for Rule Base 1
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.2
0.3
0.4
0.5
0.6
utilisation_factor mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
October 2005 43
Three-dimensional plots for Rule Base 2
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.15
0.2
0.25
0.3
0.35
number_of_servers mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
October 2005 44
Three-dimensional plots for Rule Base 2
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.2
0.3
0.4
utilisation_factor mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
0.5
October 2005 45
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.
Tune the system….
October 2005 46
Modified fuzzy sets of Number of Servers s
0.1 0
1.0
0.0
0.2
0.4
0.6
0.8
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Number of Servers (normalised)
RS M RL L S
Degree of
Membership
October 2005 47
Cube FAM of Rule Base 3
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
VS VS VS
S S VS
S S VS
VL L M
VL RL RS
M M S
RL M RS
L M RS
H
S
M
RL
L
RS
s
L
VS S M
m
M
H
 
VS VS VS
VS VS VS
VS VS VS
S S VS
S S VS
L
VS S M
S
M
RL
L
RS
m
s
S VS VS
S VS VS
RS S VS
M RS S
M RS S
M
VS S M
m
VS S M
m
S
M
RL
L
RS
s
S
M
RL
L
RS
s
October 2005 48
Three-dimensional plots for Rule Base 3
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.15
0.2
0.25
0.3
0.35
number_of_servers mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
October 2005 49
Three-dimensional plots for Rule Base 3
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.2
0.3
0.4
utilisation_factor mean_delay
n
u
m
b
e
r
_
o
f
_
s
p
a
r
e
s
0.5
October 2005 50
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.
October 2005 51
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.
October 2005 52
Recap
Example: Air Conditioner
Example: Cart Pole Problem
Case Study: Building a Fuzzy Expert System
Summary
Fuzzy Expert Systems

October 2005 53
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

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close