Fuzzy Logic Notes
Fuzzy Logic Notes
1 Introduction 2
1.1 Computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Example: Motion Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Fuzzy Systems 6
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Definitions on Fuzzy Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Operations on Fuzzy Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Membership Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.5 Fuzzy Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.6 Rules and Patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Knowledge Representation 10
4.1 Knowledge-Based Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Linguistic Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Defuzzification Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Fuzzy Control 17
5.1 Conventional Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Fuzzy Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1
Chapter 1
Introduction
1.1 Computers
Computers aid us with many areas of life from astronomy to banking to rocket science. However,
they have their drawbacks. Computer systems cannot satisfactorily manage information flowing
across a hospital, for example. The introduction of computer systems for public administration has
invariably generated chaos. Computer systems have been found responsible for disasters like flood
damage, fire control and so on.
1.2 Problems
So why can’t the computers do what we want them to?
• Problems in engineering software: specification, design, and testing.
• Algorithms (the basis of computer programs) cannot deal with partial information, with un-
certainty.
• Much of human information processing relies significantly on approximate reasoning.
Perception Emotion
If the intruder is far away there is no fear
If the intruder is near there is no surprise
If the intruder is stationary there is no fear
If the intruder is moving fast there is no anger
2
Stationary Fast
Near Very angry, not surprised, no fear Not angry, not surprised, very fearful
Far Very angry, not surprised, no fear Not angry, very surprised, no fear
However, near and far are quite relative terms, as is fast. We’ll consider a more accurate set of
emotions:
where V means very, N means not, A means angry, S means surprised and F means fearful. We can
make the terms of speed and distance more specific still, and this will give us different combinations
of emotions.
1.4 Solution
The solution to the above problem of computers is soft computing:
Soft computing differs from conventional (hard) computing in that, unlike hard
computing, it is tolerant of imprecision, uncertainty, partial truth, and approximation.
In effect, the role model for soft computing is the human mind. The guiding principle
of soft computing is: Exploit the tolerance for imprecision, uncertainty, partial truth,
and approximation to achieve tractability, robustness and low solution cost.
Soft computing is used as an umbrella term for sub-disciplines of computing, including fuzzy logic
and fuzzy control, neural networks based computing and machine learning, and genetic algorithms,
together with chaos theory in mathematics.
3
Chapter 2
• As a professional subject dedicated to the building of systems of high utility - for example
fuzzy control.
• As a theoretical subject - fuzzy logic is “symbolic logic with a comparative notion of truth
developed fully in the spirit of classical logic. It is a branch of many-valued logic based on
the paradigm of inference under vagueness.”
If µA (x) = 1, we say that x is Fully Included in (A, µA ), and if µA (x) = 0, we say that x
is Not Included in (A, µA ). If there exists some x ∈ A such that µA (x) = 1, we say that (A, µA )
is Normal. Otherwise, we say that (A, µA ) is Subnormal.
As in fuzzy set theory the set membership values can range (inclusively) between 0 and 1, in
fuzzy logic the degree of truth of a statement can range between 0 and 1 and is not constrained to
the two truth values true/false as in classic predicate logic.
4
2.2.1 Examples of Fuzzy Logic
In a Fuzzy Logic washing machine, Fuzzy Logic detects the type and amount of laundry in the
drum and allows only as much water to enter the machine as is really needed for the loaded amount.
So, less water will heat up quicker - which means less energy consumption. Additional properties:
• Imbalance compensation: In the event of imbalance calculate the maximum possible speed,
sets this speed and starts spinning.
• Water level adjustment: Fuzzy automatic water level adjustment adapts water and en-
ergy consumption to the individual requirements of each wash programme, depending on the
amount of laundry and type of fabric.
• Food cookers
• Cars
5
Chapter 3
Fuzzy Systems
3.1 Introduction
A Fuzzy System can be contrasted with a conventional (crisp) system in three main ways:
• Fuzzy Conditional Statements are expressions of the form “If A THEN B”, where A
and B have fuzzy meaning, e.g. “If x is small THEN y is large”, where small and large are
viewed as labels of fuzzy sets.
• A Fuzzy Algorithm is an ordered sequence of instructions which may contain fuzzy assign-
ment and conditional statements, e.g., “x = very small, IF x is small THEN y is large”. The
execution of such instructions is governed by the compositional rule of inference and the rule
of the preponderant alternative.
A ⊆ {x1 , x2 , . . . , xn } = X
3.1.2 Example
Consider X = {1, 2, . . . , 10}. Suppose a child is asked which of the numbers in X are “large”
relative to the others. The child might come up with the following:
6
Number Comment Degree
10 Definitely 1
9 Definitely 1
8 Quite possible 0.8
7 Maybe 0.5
6 Not usually 0.2
5, 4, 3, 2, 1 Definitely Not 0
From this, we can define some new terms using different membership functions:
Small µB = 1 − µA
Very Large µC = (µA )2
√
Large-ish µD = µA
7
• Exponentiation: C = Aα where µC = (µA )α for α > 0
Note that A ∩ ¬A is not necessarily the empty set, as would be the case with classical set theory.
Also, if A is crisp, then Aα = A for all α. We will define the Cartesian product A × B to be the
same as A ∩ B.
1
• Generalised Bell: gbell(x; a, b) =
x − b 2a
1+
a
An air-conditioner is an apparatus for controlling, especially lowering, the temperature and hu-
midity of an enclosed space. An air-conditioner typically has a fan which blows/cools/circulates
fresh air and has cooler and the cooler is under thermostatic control. Generally, the amount of air
being compressed is proportional to the ambient temperature.
Consider an air-conditioner which has five control switches: cold, cool, pleasant, warm and hot.
The corresponding speeds of the motor controlling the fan on the air-conditioner has the gradua-
tions: minimal, slow, medium, fast, blast. The rules governing the air-conditioner are as follows:
8
Rule Temperature Speed
1 Cold Minimal
2 Cool Slow
3 IF Pleasant THEN Medium
4 Warm Fast
5 Hot Blast
Hence, we can regard our rules as the cross product of temperature and speed.
In a fuzzy controller, a rule in the rule set of the controller can be visualized as a “device” for
generating the product of the input/output fuzzy sets.
Geometrically a patch is an area that represents the causal association between the cause (the
inputs) and the effect (the outputs). The size of the patch indicates the vagueness implicit in the
rule as expressed through the membership functions of the inputs and outputs.
The total area occupied by a patch is an indication of the vagueness of a given rule that can
be used to generate the patch.
Consider a one-input-one output rule: if the input is crisp and the output is fuzzy then the patch
becomes a line. And, if both are crisp sets then the patch is vanishingly small - a point.
9
Chapter 4
Knowledge Representation
Once we have found that the knowledge of a specialism can be expressed through linguistic variables
and rules of thumb, that involve imprecise antecedents and consequents, then we have a basis of
a knowledge-base. In this knowledge-base “facts” are represented through linguistic variables and
the rules follow fuzzy logic. In traditional expert systems facts are stated crisply and rules follow
classical propositional logic.
Fuzzification
The problem is that in the “real” world some of our knowledge of facts is derived from the use of
sensors: quantity of heat measured in degrees Centigrade, length measured in meters, weight (the
quantity of matter) measured in grams, etc. This quantitative, and rather precise factual informa-
tion has to be mapped onto the term-set of a linguistic variable - the process of Fuzzification.
Inference
Once mapped, the rules within a knowledge base are invoked systematically to see which of the
rules is fired and to what degree - the process of Inference. In traditional expert systems, only
those rules fire whose antecedents are true. In fuzzy expert systems rules may fire to a certain
degree: all rules may fire to a degree between zero and unity. Min and Product are two inference
methods.
1. In Min inferencing the output membership function is clipped off at a height corresponding
to the computed degree of truth of a rule’s premise. This corresponds to the traditional
interpretation of the fuzzy logic’s AND operation.
2. In Product inferencing the output membership function is scaled by the premise’s computed
degree of truth.
Composition
But, of course, we have to see what influence each rule has given the fuzzy input values. An
“averaging” procedure is adopted to compute the effective contribution of each of the rules. This
is the process of Composition. Max and Sum are two composition rules:
10
1. In MAX composition, the combined fuzzy subset is constructed by taking the pointwise
maximum over all the fuzzy subsets assigned to the output variable by the inference rule.
2. The SUM composition, the combined output fuzzy subset is constructed by taking the point-
wise sum over all the fuzzy subsets assigned to output variable by their inference rule. (Note
that this can result in truth values greater than 1).
Defuzzification
And, finally, we have to convert the fuzzy values outputted by the inference procedure onto a crisp
number that can be used in the “real” world. This process is called Defuzzification.
• Inference: Check the rules which contain the above linguistic variables.
• Composition: Create new membership function of the alpha levelled functions for Cool and
Pleasant.
• Defuzzification: Examine the fuzzy sets of Slow and Medium and obtain a speed value.
11
2. How to find an inference mechanism that is founded on well-defined semantics and that
permits approximate reasoning by means of a conjunctive general system of vague rules and
case-specific vague facts?
The fuzzy rules are also called Linguistic Rules comprising an Antecedent/Premise (the IF
part) and a Consequent/Conclusion (the THEN part). The antecedent/premise describes an
object or event or state in the form of a fuzzy specification of a measured value. The conse-
quent/conclusion specifies an appropriate fuzzy value.
T (age) = young + old + very young + not young + very old + very very young + . . .
where each of the terms in T (age) is a label of a fuzzy subset of a universe of discourse, say
U = [0, 100]. A linguistic variable is associated with two rules:
Example 4.2.1 (Age). The primary terms in the equation above are young and old, whose
meaning might be defined by their respective compatibility functions µY and µO . From these,
then, the meaning - or, equivalently, the compatibility functions - of the non-primary terms in
T age) above may be computed by the application of a semantic rule.
Example 4.2.2 (Air Conditioner). Consider again the problem of controlling an air-conditioner.
The rules that are used to control the air conditioner can be expressed as a cross product:
12
Term Membership Function
1−V
Minimal µMinimal (V ) = min ,1
30
V − 10 50 − V
Slow µSlow (V ) = max min , ,0
20 20
−40 60 − V
Medium µMedium (V ) = max min V 10 , ,0
10
V − 50 90 − V
Fast µFast (V ) = max min , ,0
20 20
V − 70
Blast µBlast (V ) = min ,1
30
Now, for our fuzzification, we consider that the temperature is 16◦ C and we want our knowledge
base to compute the speed. The fuzzification of the the crisp temperature gives the following mem-
bership for the Temperature fuzzy set:
Inference: Consider that the temperature is 16◦ and we want our knowledge base to compute the
speed. Rules 2 and 3 are firing and are essentially the fuzzy patches made out of the cross products
of
Cool × Slow
Pleasant × Medium
Composition: The Cool and Pleasant sets have an output of 0.3 and 0.4 respectively. The fuzzy
sets for Slow and Medium have to be given an α-level cut for these output values respectively.
13
Table 4.1: α-levelled Fuzzy Sets for Speed
The fuzzy output from rules 2 and 3 can be given by Defuzzification: Now we have to find a
way to obtain one single number from the curve below - one number corresponding to the speed of
the air-conditioner’s motor.
4.3.1 Centroid
We can compute the ’Centre of Gravity (COG) or ’Centre of Area’ (COA) of the output of the
rules: The COG involves the computation of the weighted sum of the Speed and the corresponding
membership function of the output fuzzy set and the weighted sum of the membership function.
Z
1
η=Z yµx1 ,...,xn (y) dy
µx1 ,...,xn (y) dy Y
Y
The centre of gravity approach attempts to take the rules into consideration according to their
degree of applicability. If a rule dominates during a certain interval then its dominance is discounted
in other intervals. There are problems with the notion of COG and COA. The crisp value η can be
obtained by approximating the integral with a sum
1 X
η= X yµx1 ,...,xn (y)
µx1 ,...,xn (y) y∈Y
y∈Y
14
Table 4.2: Rules
The centre of gravity approach attempts to take the rules into consideration according to their
degree of applicability. If a rule dominates during a certain interval then its dominance is discounted
in other intervals.
4.3.2 Maximum
Here again the weighted sum and weighted membership are worked out, except that the membership
function is given another alpha level cut corresponding to the maximum value of the output fuzzy
set. The crisp value for MOM method is given as:
η =∗∗∗
Note
Both of these methods give different results:
15
Table 4.3: CoG method versus MoM method
16
Chapter 5
Fuzzy Control
The term control is generally defined as a mechanism used to guide or regulate the operation of
a machine, apparatus or constellations of machines and apparatus. Often the notion of control
is inextricably linked with feedback: a process of returning to the input of a device a fraction of
the output signal. Feedback can be negative, whereby feedback opposes and therefore reduces the
input, and feedback can be positive whereby feedback reinforces the input signal.
’Feedback control’ is thus a mechanism for guiding or regulating the operation of a system or
subsystems by returning to the input of the (sub)system a fraction of the output. The machinery
or apparatus etc., to be guided or regulated is denoted by S, the input by W and the output by
y, and the feedback controller by C. The input to the controller is the so-called error signal e and
the purpose of the controller is to guarantee a desired response of the output y.
• Proportional to both the magnitude of the error and the duration of the error
17
Value determines reaction to the
Proportional (KP ) current error
Integral (KI ) sum of recent errors
Derivative (KD ) rate at which the error has been changing
The weighted sum of these three actions is used to adjust the process via a control element such
as the position of a control valve or the power supply of a heating element. Conventional control
theory uses a mathematical model of a process to be controlled and specifications of the desired
closed-loop behaviour to design a controller. This approach may fall short if the model of the
process:
• is difficult to obtain, or
• is (partly) unknown, or
• is highly non-linear.
A knowledge-based system for closed-loop control is a control system which enhances the perfor-
mance, reliability, and robustness of control by incorporating knowledge which cannot be accom-
modated in the analytic model upon which the design of a control algorithm is based, and that is
usually taken care of manual modes of operation, or by other safety and ancillary logic mechanisms.
The controller can be used with the process in two modes: Feedback mode when the fuzzy controller
will act as a control device, and Feed Forward mode where the controller can be used as a prediction
device. All inputs to, and outputs from, the controller are in the form of linguistic variables. In
many ways, a fuzzy controller maps the input variables into a set of output linguistic variables.
Usually, a plant, process, vehicle, or any other object to be controlled is called a system S. The
feedback controller is expected to ‘guarantee a desired response’, or output y.
Regulation is a process described in the control theory literature as a process for ‘keeping the
output y close to the setpoint (reference input) w, despite the presence of disturbances, fluctu-
ations of the system parameters, and noise measurements’. (Error e = w − y). A controller is
implemented using the control algorithm.
18