Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Project Assignment For Fuzzy Logic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Project 1 Assignment

Developing Fuzzy Inference Systems


September 30, 2012
Contents
Introduction 2
1 Project Objective 3
2 Theoretical Background 4
2.1 Fuzzy Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 Types of Membership Functions . . . . . . . . . . . . . . 5
2.2 Fuzzy Logic Operations . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Fuzzy Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Fuzzy and Linguistic Variables . . . . . . . . . . . . . . . . . . . 9
2.5 Fuzzy Propositions . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.5.1 Inference from Fuzzy Rules . . . . . . . . . . . . . . . . . 11
2.6 Fuzzy Inference Systems . . . . . . . . . . . . . . . . . . . . . . . 14
2.6.1 Stages of Developing Fuzzy Inference Systems . . . . . . . 19
3 Project Report 20
Appendix. Typical Fuzzy Inference Systems 21
1
Introduction
The goal of this project is to develop and verify by testing a Fuzzy Inference
System (FIS) for any purpose, e. g., control, classication, or decision making.
A Fuzzy Inference System is [1] any system whose variables range over states
that are fuzzy sets. For each variable, the fuzzy sets are dened on some relevant
universal set, which in this project is taken as an interval of real numbers. In
this case, the fuzzy sets are fuzzy numbers, and the associated variables are
linguistic variables.
2
Chapter 1
Project Objective
In order to complete this project, each team has to carry out the following steps:
1. Choose any control, classication, or recognition problem to be solved us-
ing fuzzy logic (typical examples are given in Appendix 1). The problem
should be complex enough to be dicult to solve using conventional math-
ematical tools (calculus, probability theory, or dierential equations).
2. Choose input and output linguistic variables (Sect. 2.4). Dene their
fuzzy values by assigning appropriate membership functions (Sect. 2.1).
The suggested number of input variables lies between 3 and 5.
3. Build up a system of fuzzy rules connecting input and output fuzzy values
(Sect. 2.6.1).
4. Develop a fully-functional code for the project (either using MATLAB
Fuzzy Logic Toolbox, or from scratch). There are no specic requirements
as to the I/O interface, however, it should be clear enough to evaluate the
system performance.
5. Prepare a Project Report (Chap. 3) in a form of a presentation and defend
it in front of other teams.
Steps 13 must be discussed with the lecturer and approved before
defending the project.
It is required to analyze system performance depending on its parameters.
Particular ways of modifying system parameters must also be discussed with
the lecturer and approved before defending the project. Possible suggestions
are:
choosing dierent membership functions for the same variable;
reducing/increasing the number of fuzzy rules;
varying the number of fuzzy values of linguistic variables.
3
Chapter 2
Theoretical Background
2.1 Fuzzy Sets
A fuzzy set [2] is a set without a crisp, clearly dened boundary. It can contain
elements with only a partial degree of membership.
Let denote a (universal) set of objects. Then, a fuzzy set A in is
characterized [3] by a membership function f
A
(x) which associates with each
point x a real number f
A
(x) [0, 1] representing the membership grade of
x in A (the grade of possibility that x A). A typical membership function is
shown in Fig. 2.1.
Figure 2.1: The membership function of a fuzzy set
Stated formally, a fuzzy set is a set of ordered pairs:
A = {(x,
A
(x)); x ,
A
(X) [0, 1]} . (2.1)
Often, it is convenient to use list notation to write down members of a fuzzy
set. For a discrete universe , the fuzzy set can be represented as
A =

xi

A
(x
i
)
x
i
.
4
For a continuous universe, this notation changes to
A =
_
x

A
(x)
x
,
where the integral sign is a mere notational mark, and does not denote any
calculus operation.
Example 1.
Consider the continuous universe of discourse = . Then, the membership
function
A
(x) =
1
1+(x5)
10
denes a fuzzy set A which can be interpreted as a
set of numbers close to 5.
2.1.1 Types of Membership Functions
The only condition a membership function must satisfy [2] is that it must vary
between 0 and 1. The function itself can be an arbitrary curve whose shape is
dened to suit the problem from the viewpoint of simplicity, convenience, speed,
and eciency.
The simplest membership functions are formed using straight lines. The
most commonly used among them are triangular and trapezoidal membership
functions (Fig. 2.2):

A
(x; a, b, c) =
_

_
0, x a
xa
ba
, a x b
cx
cb
, b x c
0, c x
, (2.2)

A
(x; a, b, c, d) =
_

_
0, x a
xa
ba
, a x b
1, b x c
dx
dc
, c x d
0, d x
. (2.3)
When it is more convenient to use smooth functions rather than piecewise,
it is a good practice to use Gaussian or generalized bell membership functions
(Fig. 2.3):

A
(x; , c) = e
(xc)
2
2
2
, (2.4)

A
(x; a, b, c) =
1
1 +

xc
a

2b
. (2.5)
Although the Gaussian membership functions and bell membership functions
achieve smoothness, they are unable to specify asymmetric membership func-
tions, which are important in certain applications. The sigmoidal membership
function (Fig. 2.4) can be either open left or right:
5
(a)
(b)
Figure 2.2: The triangular (a) and trapezoidal (b) membership functions
(a)
(b)
Figure 2.3: The Gaussian (a) and generalized bell (b) membership functions

A
(x; a, c) =
1
1 +e
a(xc)
. (2.6)
Asymmetric and closed (i.e. not open to the left or right) membership
6
Figure 2.4: The sigmoid membership function
functions can be synthesized using two sigmoidal functions.
2.2 Fuzzy Logic Operations
It is well known [4] that the complement, union, and intersection of crisp
sets correspond to the logical operations NOT, OR, and AND, respectively, in
the corresponding crisp, bivalent logic. Also, in the crisp, bivalent logic, the
union of a set with the complement of a second set represents an implication
of the rst set by the second set. Set inclusion (subset) is a special case of
implication in which the two sets belong to the same universe.
These operations (connectives) may be extended to fuzzy sets for correspond-
ing use in fuzzy logic and approximate reasoning. For fuzzy sets, the applicable
connectives must be expressed in terms of the membership functions of the sets
which are operated on. However, unlike crisp logic, in general it is possible to
dene an innite number of various kinds of fuzzy complements, unions, in-
tersections, and implications. Further on, we will discuss only standard fuzzy
operations.
The standard fuzzy complement is given by the following formula:

A
(x) = 1
A
(x) . (2.7)
The complement in fuzzy sets corresponds [4] to the negation (NOT) oper-
ation in fuzzy logic.
Example 2. Consider the fuzzy set of hot temperatures. This may be
represented by the membership function from Fig. 2.5 (solid line). The com-
plement of this set is represented by the dotted line in Fig. 2.5, and represents
temperatures that are not hot.
The standard union of two fuzzy sets A and B is given by the formula:

AB
(x) = max[
A
(x),
B
(x)] . (2.8)
The union corresponds [4] to a logical OR operation (A B).
7
Figure 2.5: Fuzzy complement
Example 3. Consider a universe representing the driving speeds, in km/h.
Suppose that the fuzzy set Fast is given by the discrete membership function
F = 0.6/80 + 0.8/90 + 1.0/100 + 1.0/110 + 1.0/120 ,
and the fuzzy set Medium is given by
M = 0.6/50 + 0.8/60 + 1.0/70 + 1.0/80 + 0.8/90 + 0.4/100 .
Then, the fuzzy set Fast OR Medium is given be the membership function
F M = 0.6/50+0.8/60+1.0/70+1.0/80+0.8/90+1.0/100+1.0/110+1.0/120 .
The standard intersection of two fuzzy sets A and B is given by the formula:

AB
(x) = min[
A
(x),
B
(x)] . (2.9)
The intersection corresponds [4] to a logical AND operation (A B).
2.3 Fuzzy Relations
A fuzzy relation is [1] is a fuzzy set dened on the Cartesian product of crisp
sets X
1
, X
2
, . . . , X
n
. A fuzzy relation can be conveniently represented by an
n-dimensional membership function.
Example 4.
Let R be a fuzzy relation between the sets X = {New York City, Paris} and
Y = {Beijing, New York City, London} which represents the relational concept
very far. This relation can be written in list notation as

R
(X, Y ) = 1.0/(NYC, Beijing) + 0.0/(NYC, NYC) + 0.6/(NYC, London)+
0.9/(Paris, Beijing) + 0.7/(Paris, NYC) + 0.3/(Paris, London) .
8
The standard composition of binary fuzzy relations P(X, Y ) and Q(Y, Z)
with a common set Y is dened by
R(x, z) = [P Q](x, z), or

R
(x, z) = max
yY
min[
P
(x, y),
Q
(y, z)] x X, z Z .
(2.10)
2.4 Fuzzy and Linguistic Variables
A variable is characterized [5] by a triple (X, , R(X, u)), where X is the name
of the variable, is a universal set, u is generic name for the elements if , and
R is a subset of which represents a restriction on the values of u imposed by
X.
Example 5. Consider a variable named age. In this case, might be taken
as the set of integers 0, 1, 2, . . ., and R(X, u) might be the subset 0, 1, . . . , 100.
A fuzzy variable is characterized [5] by a triple (X, , R(X, u)), where X is
the name of the variable, is a universal set, u is generic name for the elements
if , and R is a fuzzy subset of which represents a fuzzy restriction on the
values of u imposed by X. The nonfuzzy variable u is called the base variable
for X.
The assignment equation for X has the form
x = u : R(X) ,
and represents an assignment of a value u to x X subject to the restriction
R(X). The degree to which this equation is satised (compatibility of u with
R(X)) is given by
R(X)
(u), the grade of membership of u in R(X).
Example 6. Consider a fuzzy variable named budget, with = [0, ], and
R(budget) =
_
1000
0
1/u +
_

1000
_
1 +
_
u 1000
200
_
2
_
1
/u .
Then in the assignment equation budget = 1100 : R(budget), the compati-
bility of 1100 with R is
R(budget)
(1100) = 0.80.
A linguistic variable is characterized [5] by a quintiple (L, T(L), , G, M),
where L is the name of the variable, T(L) is the term-set of L, or the set of
names of linguistic values being fuzzy variables (denoted by X) ranging over
the universe (associated with the base variable), G is a syntactic rule for
generating the elements of T(L), and M is a semantic rule for association with
each X its meaning, which is a fuzzy subset of . A particular X is called a
term.
The meaning M(X) is dened to be the restriction R(X, u) on the base
variable u imposed by the fuzzy variable named X.
9
Example 7. Consider a linguistic variable named Age (L = Age), with
= [0, 100]. A linguistic value of Age may be named old. Another value may
be very old. The term-set may be expressed as
T(Age) = {old, very old, not old, more or less young, quite young, . . .} .
Each term is the name of a fuzzy variable. For example, the restriction
R(old) constitutes the meaning of old. A possible restriction might be dened
as
M(old) =
_
100
50
_
1 +
_
u 50
5
_
2
_
1
/u .
It is always convenient to use the same symbol to denote both a fuzzy set,
and the name of that set.
Put informally, we can say that a linguistic variable is a variable whose values
are fuzzy sets dened on the same universe of discourse. This is illustrated in
Fig. 2.6.
Figure 2.6: Hierarchical structure of a linguistic variable
2.5 Fuzzy Propositions
The fundamental dierence between classical propositions and fuzzy proposi-
tions is [1] in the range of their truth values. While each classical proposition
is required to be either true or false, the truth or falsity of fuzzy propositions is
a matter of degree.
In this project, it will be sucient to discuss only one type of fuzzy proposi-
tions, namely, unqualied propositions. The canonical form of fuzzy propositions
p of this type is expressed by the sentence
p : V is F , (2.11)
10
where V is a variable that takes values v from some universal set V , and F is
a fuzzy set on V representing a fuzzy predicate (tall, low, cheap, and so
on). Given a particular v, it belongs to F with membership grade
F
(v), which
is also interpreted as the degree of truth T(p) of proposition p.
Example 8.
Let V be the water temperature, and let the membership function (Fig.
2.7) represent the predicate high. Then, the corresponding fuzzy proposition p
is expressed by the sentence
p : temperature (V) is high (F) .
Figure 2.7: Components of the fuzzy proposition p
The degree of truth T(p) depends on the actual value of the temperature.
For example, if v = 85, T(p) = 0.75.
2.5.1 Inference from Fuzzy Rules
Each fuzzy rule can be expressed as a conditional proposition in the canonical
form
p : If X is A, then Y is B , (2.12)
where X and Y are variables whose values are in sets X and Y , respectively,
and A, B are fuzzy sets on X and Y , respectively. These propositions may also
be viewed as propositions of the form
X, Y is R , (2.13)
where R is a fuzzy set on X Y determined by the formula

R
(x, y) = I[
A
(x),
B
(y)] , (2.14)
where I denotes fuzzy implication.
11
There are various kinds of fuzzy implication, but in this project it is recom-
mended to use the implication in the form I(a, b) = min[a, b].
Usually, the if clause of a fuzzy rule is called an antecedent, and the then
clause is called a consequent.
Let us assume that A

and B

are fuzzy sets on X and Y , resprectively.


Then, if
R
and
A
are given, we can obtain
B
by the equation:
B

= A

R (2.15)
called the compositional rule of inference (CRI) (Fig. 2.8).
Figure 2.8: Compositional Rule of Inference
Using relation R obtained from a proposition p by (2.14), and given another
proposition q of the form q : X is A

, we may conclude that Y is B

by the CRI
(2.15). This procedure is called a generalized modus ponens (GMP), and can be
expressed by the following schema:
Rule: If X is A, then Y is B
Fact: X is A

Conclusion: Y is B

Such kind of inference is an example of a so-called approximate reasoning.


Example 9.
Let sets of values of variables X and Y be X = {x
1
, x
2
, x
3
} and Y = {y
1
, y
2
},
respectively. Assume that a proposition if X is A, then Y is B is given, where
A = 0.5/x
1
+ 1.0/x
2
+ 0.6/x
3
, and B = 1.0/y
1
+ 0.4/y
2
. Then, given a fact
expressed by the proposition x is A

, where A

= 0.6/x
1
+ 0.9/x
2
+ 0.7/x
3
,
we can use the GMP to derive a conclusion in the form Y is B

.
12
Using fuzzy implication, we obtain:

R
= 0.5/(x
1
, y
1
) + 0.4/(x
1
, y
2
) + 1.0/(x
2
, y
1
)+
0.4/(x
2
, y
2
) + 0.6/(x
3
, y
1
) + 0.4/(x
3
, y
2
)
by (2.14). Then, by (2.15), we obtain:

B
(y
1
) = sup
xX
min[
A
(x), R(x, y
1
)]
= max[min(0.6, 0.5), min(0.9, 1.0), min(0.7, 0.6)]
= 0.9 ,

B
(y
2
) = sup
xX
min[
A
(x), R(x, y
2
)]
= max[min(0.6, 0.4), min(0.9, 0.4), min(0.7, 0.4)]
= 0.9 .
Thus, we conclude that Y is B

, where B

= 0.9/y
1
+ 0.9/y
2
.
If a fuzzy rule has a complex antecedent:
p : If X
1
is A
1
and X
2
is A
2
and . . . and X
n
is A
n
, then Y is B ,
then it can be reduced to the previous case by introducing a multidimensional
fuzzy set X with a membership function
X
(x
1
, x
2
, . . . , x
n
) = max[
X1
(x
1
),
. . . ,
Xn
(x
n
)]. Of course, if the antecedent contains OR operation instead of
AND, or any combination of both, the multidimesional set can be constructed
using max and min operations in proper order.
When there are several fuzzy rules, we face what is called multiconditional
approximate reasoning of the following form:
Rule 1: If X is A
1
, then Y is B
1
Rule 2: If X is A
2
, then Y is B
2
. . . . . .
Rule n: If X is A
n
, then Y is B
n
Fact: X is A

Conclusion: Y is B

The most common way to determing B

is [1] a method of interpolation. It


consists of the following two steps:
1. Calculate the degree of consistency r
j
(A

) between the given fact and the


antecedent of each rule j:
r
j
(A

) = sup
xX
min[
A
(x),
Aj
(x)] ; (2.16)
2. Calculate the conclusion B

by truncating each set B


j
by the value of
r
j
(A

), and take the union of the truncated sets:

B
(y) = sup
j=1,n
min[r
j
(A

),
Bj
(y)] y Y . (2.17)
The illustration of the method of interpolation is given in Fig. 2.9. In this
project, it is required to build a FIS using this method.
13
Figure 2.9: Illustration of the method if interpolation
2.6 Fuzzy Inference Systems
Fuzzy inference is [2] a process of formulating the mapping from a given input
to an output using fuzzy logic. There are two major types of fuzzy inference
systems, namely, Mamdani-type and Sugeno-type. In this project, it is required
to develop the Mamdani-type FIS initially described by Ebrahim Mamdani in [6]
as an attempt to control a steam engine and boiler combination by synthesizing
a set of linguistic control rules obtained from experienced human operators.
A general scheme of a typical FIS is presented in Fig. 2.10. The fuzzy rule
base consists of fuzzy rules in the form (2.12). Antecedents of the rules in the
base represent input linguistic variables of the FIS, whereas consequents stand
14
for output linguistic variables.
Figure 2.10: A general scheme of a Fuzzy Inference System
A typical fuzzy inference system operates by repeating a cycle of the following
steps [1]:
1. Inputs from the environment are taken in the crisp form.
2. These inputs are fuzzied in the fuzzication module by means of a fuzzi-
cation function f
e
, whose purpose is to interpet measurements of input
variables more realistically. In this project, it is highly recommended to
take f
e
(x) = x, i.e., we will not fuzzify input measurements.
3. The resultant values are used by the inference engine to evaluate each rule
from the rule base by CRI. Fuzzy sets obtained for each rule are aggregated
into one by (2.8).
4. The aggregated fuzzy set is converted into a single crisp value that is in
some sense the best representative of the set. This conversion is called a
defuzzication.
There are several ways of defuzzifying resultant fuzzy sets. One of the most
popular methods is [2] the centroid calculation:
d(C) =
_
c
c
C(z)zdz
_
c
c
C(z)dz
, (2.18)
where C is the fuzzy set to be defuzzied, with the support [c, c]. For a discrete
case, when C is dened on a nite universal set {z
1
, z
2
, . . . , z
n
}, (2.18) changes
to
d(C) =

n
k=1
C(z
k
)z
k

n
k=1
C(z
k
)
. (2.19)
15
Example 10.
Consider the so-called tipping problem: what is the right amount to tip
your waitperson? Let us state this problem in a following manner:
Given a number between 0 and 10 that represents the quality of
service at a restaurant (10 being excellent), and another number
between 0 and 10 that represents the quality of food (10 being deli-
cious), what should the tip be, given that the average tip is usually
15%?
Consider the following Fuzzy Inference System for solving this task. The in-
put variables are Service Quality and Food Quality, and the output variable
is Tip. The values of each variable are dened using the following membership
functions (Fig. 2.11):

poor
(x) = e
x
2
21.5
2
;

good
(x) = e
(x5)
2
21.5
2
;

excellent
(x) = e
(x10)
2
21.5
2
;

rancid
(x) =
_

_
0, x < 0
1, 0 x 1
3x
3
, 1 x 3
0, 3 x
;

delicious
(x) =
_

_
0, x 7
x7
2
, 7 x 9
1, 9 x 10
0, 10 < x
;

cheap
(x) =
_

_
0, x 0
x
5
, 0 x 5
10x
5
, 5 x 10
0, 10 x
;

average
(x) =
_

_
0, x 10
x10
5
, 10 x 15
20x
5
, 15 x 20
0, 20 x
;

generous
(x) =
_

_
0, x 20
x20
5
, 20 x 25
30x
5
, 25 x 30
0, 30 x
.
The fuzzy rule base contains the following fuzzy rules:
1. If Service Quality is poor, or Food Quality is rancid, then Tip
is cheap.
16
(a)
(b)
(c)
Figure 2.11: The membership functions for the tipping problem FIS
2. If Service Quality is good, then Tip is average.
17
3. If Service Quality is excellent, or Food Quality is delicious, then
Tip is generous.
The basic structure of the FIS for the tipping problem is shown in Fig. 2.12.
Figure 2.12: The basic structure of the FIS for the tipping problem
Let the input value for the Service Quality variable be Service
0
= 3, and
for the Food Quality variable be Food
0
= 8. Then, to compute the output tip,
we need to carry out the following steps according to the method of interpolation
explained in Sect. 2.5.1. Keep in mind that, since we decided not to fuzzify our
inputs, the fact in our case is represented by a fuzzy set consisting of only
one element: A

= 1/(3, 8):
1. For each rule, calculate the degree of consistency r
j
(A

):
r
1
(A

) = min[
A
(3, 8),
A1
(3, 8)] =
A1
(3, 8) =
max[
poor
(3),
rancid
(8)] = 0.135 ;
r
2
(A

) = min[
A
(3, 8),
A2
(3, 8)] =
A2
(3, 8) =

good
(3) = 0.411 ;
r
3
(A

) = min[
A
(3, 8),
A3
(3, 8)] =
A3
(3, 8) =
max[
excellent
(3),
delicious
(8)] = 0.500 .
2. For each rule, obtain fuzzy sets by truncating rule consequents by r
j
:

1
(y) = min[r
1
(A

),
B1
(y)] = min[0.135,
cheap
(y)] ;

2
(y) = min[r
2
(A

),
B2
(y)] = min[0.411,
average
(y)] ;

3
(y) = min[r
3
(A

),
B3
(y)] = min[0.500,
generous
(y)] .
3. Unite resulting sets into one:

B
(y) = max[
B

1
(y),
B

2
(y),
B

3
(y)] .
4. Defuzzify the result to obtain crisp output. In our case, applying centroid
method yields 16.7%.
The fuzzy inference diagram for this example is shown in Fig. 2.13.
18
Figure 2.13: The fuzzy inference diagram for the tipping problem
2.6.1 Stages of Developing Fuzzy Inference Systems
To solve a problem with the help of a Fuzzy Inference System, it is necessary to
follow several steps:
1. Identify relevant input and output linguistic variables of the system, and
ranges of their values.
2. Select meaningful fuzzy values for each variable and express them by ap-
propriate fuzzy sets.
3. Formulate fuzzy rules representing the knowledge needed to solve the prob-
lem.
4. Choose appropriate defuzzication method to convert the output fuzzy
set to a crisp value.
19
Chapter 3
Project Report
The Project Report must cover the following topics:
description of the problem to be solved; it is necessary to stress why it
is better (cheaper, faster, more convenient) to use fuzzy logic instead of
conventional tools;
description of the fuzzy inference system, including input and output vari-
ables, membership functions dened for their values, and appropriate fuzzy
rules;
analysis of the results of applying FIS to solving the problem at hand, and
its comparison with results obtained by conventional tools;
analysis of system performance depending on its parameters.
Particular structure of the report, or its esthetical appeal, is irrelevant as
long as the report contains all the parts stated above, and the presentation
satises requirements imposed by the lecturer.
20
Bibliography
[1] Klir, G. J., Yuan, B. Fuzzy Sets and Fuzzy Logic: Theory and Applications.
Prentice Hall, 1995.
[2] Fuzzy Logic Toolbox. For Use with MATLAB. The MathWorkds, Inc., 1999.
[3] Zadeh, L. A. Fuzzy sets, Information and Control, 8, 1965, pp. 338353.
[4] Karray, F. O., de Silva, C. Soft Computing and Intelligent Systems Design.
Theory, Tools and Applications. Pearson Education Limited, 2004.
[5] Zadeh, L. A. The concept of a linguistic variable and its application to
approximate reasoning, Information Sciences, 8, 1975, pp. 199249.
[6] Mamdani, E. H., Assilian, S. An experiment in linguistic synthesis with
a fuzzy logic controller, International Journal of Man-Machine Studies,
Vol. 7, No. 1, 1975, pp. 113.
21
Appendix. Typical Fuzzy
Inference Systems
Fuzzy logic based controller for the climate control system of automobiles.
Fuzzy inference system for classication of dierent species of owers.
Fuzzy logic controller for robot maze traversal.
Fuzzy trac light controller.
Fuzzy controller for a washing machine.
Fuzzy inference system for handwritten digit recognition.
Fuzzy system for controlling the liquid level in a tank.
22

You might also like