0% found this document useful (0 votes)
72 views

Topic 3 Dealing With Uncertainty Slides

- Dealing with uncertainty is important in artificial intelligence as information is often incomplete, inconsistent, or uncertain. This makes exact reasoning difficult. - Probability and fuzzy logic allow reasoning under uncertainty by assigning numerical values to represent degrees of belief rather than making binary true/false assumptions. - Bayes' rule provides a way to calculate conditional probabilities and update beliefs as new evidence is obtained. This Bayesian reasoning approach is useful for artificial intelligence applications involving hypothesis and evidence.

Uploaded by

Alyssa Ann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Topic 3 Dealing With Uncertainty Slides

- Dealing with uncertainty is important in artificial intelligence as information is often incomplete, inconsistent, or uncertain. This makes exact reasoning difficult. - Probability and fuzzy logic allow reasoning under uncertainty by assigning numerical values to represent degrees of belief rather than making binary true/false assumptions. - Bayes' rule provides a way to calculate conditional probabilities and update beliefs as new evidence is obtained. This Bayesian reasoning approach is useful for artificial intelligence applications involving hypothesis and evidence.

Uploaded by

Alyssa Ann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 204

Dealing with

Uncertainty

Ir. Dr. Chuah Yea Dat


Course Learning Outcomes
• Explain the fundamental concepts of AI
systems.
• Analyse problems using appropriate
techniques.
• Analyse AI systems for various selection,
recognition and decision-making problems.
• Identify AI applications in various fields.
Dealing with Uncertainty
Topics
• Probability-based reasoning
• Certainty Factors
• Fuzzy Reasoning
• Rules As Knowledge
• Fuzzy Expert Systems
• Example Applications
Uncertainty
Uncertainty is the lack of the exact
knowledge that would enable us to
reach a perfectly reliable conclusion.
Information
Due to incomplete, inconsistent or
uncertainty of information, it is often
not suitable for solving a problem.
Exact Reasoning
• Classical logic permits only exact reasoning.
• It assumes that perfect knowledge always
exists and the law of the excluded middle can
always be applied.

IF A is true , then A is not false


IF A is false, then A is not true
Types of uncertain knowledge
Weak implications
• Domain experts and knowledge engineers
have the painful task of establishing concrete
correlations between IF (condition) and THEN
(action) parts of the rules.
• Therefore, expert systems need to have the
ability to handle vague associations, for
example by accepting the degree of
correlations as numerical certainty factors.
Types of uncertain knowledge

Imprecise language
• Our natural language is ambiguous and
imprecise.
• We describe facts with such terms as often and
sometimes, frequently and hardly ever.
• As a result, it can be difficult to express
knowledge in the precise IF-THEN form of
production rules.
Types of uncertain knowledge
Imprecise language
• However, if the meaning of the facts is
quantified, it can be used in expert systems.
• In 1944, Ray Simpson asked 355 high school and
college students to place 20 terms like often on
a scale between 1 and 100.
• In 1968, Milton Hakel repeated this experiment.
Quantification of ambiguous and imprecise
terms on a time-frequency scale
Ray Simpson (1944) Milton Hakel (1968)
Term Mean value Term Mean value
Always 99 Always 100
Very often 88 Very often 87
Usually 85 Usually 79
Often 78 Often 74
Generally 78 Rather often 74
Frequently 73 Frequently 72
Rather often 65 Generally 72
About as often as not 50 About as often as not 50
Now and then 20 Now and then 34
Sometimes 20 Sometimes 29
Occasionally 20 Occasionally 28
Once in a while 15 Once in a while 22
Not often 13 Not often 16
Usually not 10 Usually not 16
Seldom 10 Seldom 9
Hardly ever 7 Hardly ever 8
Very seldom 6 Very seldom 7
Rarely 5 Rarely 5
Almost never 3 Almost never 2
Never 0 Never 0
Unknown data

When the data is incomplete or missing, the


only solution is to accept the value “unknown”
and proceed to an approximate reasoning with
this value.
Expert System
Expert system is a piece of software which uses
databases of expert knowledge to offer advice
or make decisions
Combining the views of different
experts
• Large expert systems usually combine the
knowledge and expertise of a number of experts.
• Unfortunately, experts often have contradictory
opinions and produce conflicting rules.
• To resolve the conflict, the knowledge engineer
has to attach a weight to each expert and then
calculate the composite conclusion.
• But no systematic method exists to obtain these
weights.
Probability
• The concept of probability has a long history
that goes back thousands of years when
words like “probably”, “likely”, “maybe”,
“perhaps” and “possibly” were introduced
into spoken languages.
• However, the mathematical theory of
probability was formulated only in the 17th
century.
Probability
• The probability of an event is the proportion
of cases in which the event occurs.
• Probability can also be defined as a scientific
measure of chance.
Probability
• Probability can be expressed mathematically
as a numerical index with a range between
zero (an absolute impossibility) to unity (an
absolute certainty).
• Most events have a probability index strictly
between 0 and 1, which means that each
event has at least two possible outcomes:
- favourable outcome or success,
- and unfavourable outcome or failure.
Mathematical expression of
Probability
Probability

the number of successes


P(success) =
the number of possible outcomes

the number of failures


P( failure) =
the number of possible outcomes
Mathematical expression of
Probability
If s is the number of times success can occur,
and f is the number of times failure can
occur,
then P success = p = s
s+ f
f
P failure = q =
s+ f
and p+ q=1
Probability of throwing a coin
• If we throw a coin, the probability of getting a
head will be equal to the probability of getting
a tail.
• In a single throw, s = f =1, and therefore the
probability of successfully getting a head is
0.5. s
P success = p =
s+ f
f
P failure = q =
s+ f
p+ q=1
Conditional probability
• Let A be an event in the world and B be
another event.
• Suppose that events A and B are not mutually
exclusive, but occur conditionally on the
occurrence of the other.
The probability that event A will occur if
event B occurs is called the conditional
probability.
Mathematical expression of conditional
probability

p(A|B)
Note:
1. The probability that event A will occur if
event B occurs is called the conditional
probability.
2. Vertical bar represents GIVEN,
3. Probability expression is interpreted as
“Conditional probability of event A occurring
given that event B has occurred”.
Mathematical
expression of
conditional
probability

the number of times A and B can occur


p AB =
the number of times B can occur

Event A occurring given


that event B has
occurred.
Bayes’
rule
Bayes’ rule
In probability theory and statistics, Bayes's rule
(alternatively Bayes's law or Bayes's theorem),
named after Reverend Thomas Bayes
Joint probability of A and B

p(A∩B)
The number of times A and B can occur, or the
probability that both A and B will occur, is called
the joint probability of A and B.
Joint probability of A and B
• The number of ways B can occur is the
probability of B, p(B), and thus Intersection
represents
Vertical bar AND
represents
GIVEN

• Similarly, the conditional probability of event


B occurring given that event A has occurred
equals
Joint Probability Distributions
• A joint probability distribution represents the
combined probabilities of two or more variables.
A ⌐A
B 0.11 0.09
⌐B 0.63 0.17

• This table shows, for example, that


P (A ∩ B) = 0.11
P (¬A ∩ B) = 0.09
• Using this, we can calculate P(A):
P(A) = P(A ∩ B) + P(A ∩ ¬B)
= 0.11 + 0.63
= 0.74
Bayes’ rule
Hence,
or

Substituting the last equation into the


equation

pBA p A
p AB =
pB
Bayes’ rule

pBA p A
p AB =
pB

where:
• p(A|B) is the conditional probability that event A
occurs given that event B has occurred;
• p(B|A) is the conditional probability of event B
occurring given that event A has occurred;
• p(A) is the probability of event A occurring;
• p(B) is the probability of event B occurring.
The joint probability
• If the occurrence of event A depends on only
two mutually exclusive events, B and NOT B , we
obtain:

• Similarly,

• Substituting this equation into the Bayesian rule


yields:
Bayesian reasoning
• Suppose all rules in the knowledge base are
represented in the following form:
IF A is true
THEN B is true {with probability p}

• This rule implies that if event A occurs, then


the probability that event B will occur is p.
• In expert systems, B usually represents a
hypothesis and A denotes evidence to
support this hypothesis.
The Bayes’ rule expressed in terms of hypotheses
and evidence looks like this:
p EH p H
pHE =
p E H  p H + p E H  p H
where:
• p(H) is the prior probability of hypothesis H being true;
• p(E|H) is the probability that hypothesis H being true
will result in evidence E;
• p(¬H) is the prior probability of hypothesis H being
false;
• p(E|¬H ) is the probability of finding evidence E even
when hypothesis H is false.
Bayesian reasoning

• In expert systems, the probabilities required to


solve a problem are provided by experts.

An expert determines :
❖ the prior probabilities for possible hypotheses
p(H) and p(¬H), and
❖ the conditional probabilities for observing
evidence E :
✓ if hypothesis H is true, p(E|H), and
✓ if hypothesis H is false, p(E|¬H).
Bayesian reasoning

• Users provide information about the evidence


observed and the expert system computes p(H|E)
for hypothesis H in light of the user-supplied
evidence E.
• Probability p(H|E) is called the posterior probability
of hypothesis H upon observing evidence E.
➢ We can take into account both multiple hypotheses
H1, H2,..., Hm and multiple evidences E1, E2 ,..., En.
The hypotheses as well as the evidences must be
mutually exclusive and exhaustive.
➢ Single evidence E and multiple hypotheses follow:
p EH p H
p E H i  p Hi pHE =
p E H  p H + p E H  p H
p Hi E = m
 p E Hk  p Hk
k =1
➢ Multiple evidences and multiple hypotheses follow:
p E1 E2 . . . En H i  p H i
p H i E1 E2 . . . En =
m
 p E1 E2 . . . En H k  p Hk
k =1
❖ This requires to obtain the conditional probabilities
of all possible combinations of evidences for all
hypotheses, and thus places an enormous burden
on the expert.
❖ Therefore, in expert systems, conditional
independence among different evidences assumed.
Thus, instead of the unworkable equation, we
attain:
p E1 H i  p E 2 H i  . . .  p En H i  p H i
p H i E1 E2 . . . En =
m
 p E1 H k  p E 2 H k  . . .  p En H k  p H k
k =1
Example

• Suppose an expert, given three conditionally


independent evidences E1, E2 and E3, creates three
mutually exclusive and exhaustive hypotheses H1,
H2 and H3, and provides prior probabilities for these
hypotheses – p(H1), p(H2) and p(H3), respectively.
• The expert also determines the conditional
probabilities of observing each evidence for all
possible hypotheses.
The prior and conditional probabilities
• Assume that we first observe evidence E3.
• The expert system computes the posterior
probabilities for all hypotheses as
H y p o t h esi s
Probability
i =1 i =2 i =3
p Hi 0.40 0.35 0.25

p E1 H i 0.3 0.8 0.5

p E2 H i 0.9 0.0 0.7

p E3 Hi 0.6 0.7 0.9


H y p o t h esi s

p E3 H i  p H i
Probability
i =1 i =2 i =3

p H i E3 = , i = 1, 2, 3 p Hi 0.40 0.35 0.25

3 p E1 H i 0.3 0.8 0.5

 p E3 H k  p Hk p E2 H i 0.9 0.0 0.7

k =1 p E3 Hi 0.6 0.7 0.9

Thus, 0.6  0.40


p H1 E3 = = 0.34
0.6  0.40 + 0.7  0.35 + 0.9  0.25
0.7  0.35
p H 2 E3 = = 0.34
0.6  0.40 + 0.7  0.35 + 0.9  0.25
0.9  0.25
p H3 E3 = = 0.32
0.6  0.40 + 0.7  0.35 + 0.9  0.25
• After evidence E3 is observed, belief in hypothesis H1
decreases and becomes equal to belief in hypothesis
H2 .
• Belief in hypothesis H3 increases and even nearly
reaches beliefs in hypotheses H1 and H2.
H y p o t h esi s
Probability
i =1 i =2 i =3

Suppose now that we observe evidence E1. p Hi 0.40 0.35 0.25

p E1 H i 0.3 0.8 0.5


The posterior probabilities are calculated as p E2 H i 0.9 0.0 0.7

p E3 Hi 0.6 0.7 0.9

p E1 Hi  p E3 H i  p H i
p Hi E1E3 = , i = 1, 2, 3
3
 p E1 H k  p E3 H k  p H k
k =1
Hence,
0.3 0.6 0.40
p H1 E1E3 = = 0.19
0.3 0.6 0.40 + 0.8 0.7  0.35 + 0.5  0.25
0.8 0.7  0.35
p H 2 E1E3 = = 0.52
0.3 0.6 0.40 + 0.8 0.7  0.35 + 0.5  0.25
0.5 0.9  0.25
p H3 E1E3 = = 0.29
0.3 0.6 0.40+ 0.8 0.7  0.35 + 0.5  0.25
Hypothesis H2 has now become the most likely one.
H y p o t h esi s
Probability
i =1 i =2 i =3

After observing evidence E2, the final posterior p Hi 0.40 0.35 0.25

p E1 H i 0.3 0.8 0.5


probabilities for all hypotheses are calculated: p E2 H i 0.9 0.0 0.7

p E3 Hi 0.6 0.7 0.9


p E1 H i  p E2 H i  p E3 H i  p H i
p H i E1E2E3 = , i = 1, 2, 3
3
 p E1 H k  p E2 H k  p E3 H k  p H k
k =1
0.3 0.9 0.6 0.40
p H1 E1E2E3 = = 0.45
0.3 0.9 0.6 0.40+ 0.8 0.0 0.7  0.35 + 0.5 0.7 0.9  0.25
0.8  0.0  0.7  0.35
p H 2 E1E2E3 = =0
0.3 0.9  0.6  0.40 + 0.8  0.0  0.7  0.35+ 0.5 0.7  0.9 0.25
0.5 0.7 0.9  0.25
p H 3 E1E2E3 = = 0.55
0.3 0.9 0.6 0.40+ 0.8 0.0 0.7  0.35 + 0.5 0.7  0.9  0.25

Although the initial ranking was H1, H2 and H3, only


hypotheses H1 and H3 remain under consideration
after all evidences (E1, E2 and E3) were observed.
Bias of the Bayesian method
• The framework for Bayesian reasoning requires
probability values as primary inputs.
• The assessment of these values usually involves
human judgement.
• However, psychological research shows that humans
cannot elicit probability values consistent with the
Bayesian rules.
• This suggests that the conditional probabilities may
be inconsistent with the prior probabilities given by
the expert.
Example
▪ A car that does not start and makes odd noises
when you press the starter.
▪ The conditional probability of the starter being
faulty if the car makes odd noises may be
expressed as:
IF the symptom is “odd noises”
THEN the starter is bad {with probability 0.7}
▪ The conditional probability of the starter is good if
the car makes odd noises may be expressed as:
P(starter is not bad|odd noises) =
= p(starter is good|odd noises) = 1-0.7 = 0.3
• Therefore, we can obtain a companion rule that
states
IF the symptom is “odd noises”
THEN the starter is good {with probability 0.3}
• Domain experts do not deal with conditional
probabilities and often deny the very existence of
the hidden implicit probability (0.3 in our
example).
• We would also use available statistical information
and empirical studies to derive the following rules:
IF the starter is bad
THEN the symptom is “odd noises” {probability 0.85}
IF the starter is bad
THEN the symptom is not “odd noises” {probability 0.15}
• To use the Bayes’ rule, we still need the prior
probability, the probability that the starter is bad if
the car does not start. Suppose, the expert supplies
us the value of 5 per cent. Now we can apply the
Bayesian rule to obtain:
0.85  0.05
p starter is bad odd noises = = 0.23
0.85  0.05 + 0.15  0.95
• The number obtained is significantly lower
than the expert’s estimate of 0.7 given at the
beginning of this section.
• The reason for the inconsistency is that the expert
made different assumptions when assessing the
conditional and prior probabilities.
Application in medical diagnosis (E.g. 1)
Data
– 80% of the time you have a cold, you also
have a high temperature. P(HT|C) = 0.8
– At any one time, 1 in every 10,000 people
has a cold. P(C) = 1/10000 = 0.0001
– 1 in every 1000 people has a high
temperature. P(HT) = 1/1000 = 0.001
• Suppose you have a high temperature. What
Is the likelihood that you have a cold? P(C|HT)
P(C|HT) = {P(HT|C)*P(C)}/P(HT) = ? 48

pBA p A
p AB =
pB
Application in medical diagnosis (E.g. 2)
Data
– 99% of the time you have a plague, you also
have a high temperature. P(HT|P) = 0.99
– At any one time, 1 in every 1000,000,000
people has a plague. P(P) = 1/1000000000 =
0.000000001
– 1 in every 1000 people has a high
temperature. P(HT) = 1/1000 = 0.001
• What is the relative likelihood of cold and
plague? {P(C|HT)/P(P|HT)} = ? 49
Application in medical diagnosis
(E.g. 2 - continue)
• Medical diagnosis
– P(HT|C) = 0.8
– Probability of cold, P(C) = 0.0001
– Probability of plague, P(P) is 0.000000001
– 99% of the time you have a plague, you also
have a high temperature. P(HT|P) = 0.99
• Relative likelihood of cold and plague
𝑃(𝐻𝑇|𝐶) ∗ 𝑃(𝐶) 𝑃(𝐻𝑇|𝑃) ∗ 𝑃(𝑃)
𝑃(𝐶|𝐻𝑇) = 𝑃(𝑃|𝐻𝑇) =
𝑃(𝐻𝑇) 𝑃(𝐻𝑇)
𝑃(𝐶|𝐻𝑇) 𝑃(𝐻𝑇|𝐶) ∗ 𝑃(𝐶)
=
𝑃(𝑃|𝐻𝑇) 𝑃(𝐻𝑇|𝑃) ∗ 𝑃(𝑃)
Term Certainty Factor
Definitely not _ 1.0

Certainty factors theory and Almost certainly not


Probably not
Maybe not
_ 0.8
_
_ 0.6
_ 0.4
Unknown 0.2 to +0.2

evidential reasoning Maybe


Probably
Almost certainly
+0.4
+0.6
+0.8
Definitely +1.0

• Certainty factors theory is a popular alternative


to Bayesian reasoning.
• A certainty factor (cf ), a number to measure the
expert’s belief.
• The maximum value of the certainty factor is,
say, +1.0 (definitely true) and the minimum -1.0
(definitely false).
• For example, if the expert states that some
evidence is almost certainly true, a cf value of 0.8
would be assigned to this evidence.
Example: MYCIN
MYCIN was an early backward chaining expert
system that used artificial intelligence to identify
bacteria causing severe infections, such as
bacteremia and meningitis, and to recommend
antibiotics, with the dosage adjusted for
patient's body weight — the name derived from
the antibiotics themselves, as many antibiotics
...
Uncertain terms and their
interpretation in MYCIN
Term Certainty Factor
Definitely not _ 1.0
Almost certainly not _
_ 0.8
Probably not _ 0.6
Maybe not _ 0.4
Unknown 0.2 to +0.2
Maybe +0.4
Probably +0.6
Almost certainly +0.8
Definitely +1.0
Expert systems with certainty factors
In expert systems with certainty factors, the
knowledge base consists of a set of rules that
have the following syntax:

IF <evidence> cf = belief in
THEN <hypothesis> {cf} hypothesis H
given that
evidence E has
occurred.
Certainty factors theory
Certainty Measure of Belief
factors theory Measure of Disbelief

The certainty factors theory is based on two


functions: Hypothesis Evidence

I. Measure of Belief : MB(H,E) – the measure


of increased belief in H due to E, and
II. Measure of Disbelief : MD(H,E)- the
measure of increased disbelief in H due to
E.
Certainty
factors theory
 1 if p(H ) = 1
 Hypothesis Evidence

MB (H, E) =  max  p(H E), p(H )  − p(H )


Measure of Belief   otherwise
 max 1, 0 − p(H )
 1 if p(H ) = 0
Measure of Disbelief

MD (H, E) =  min  p(H E), p(H )  − p(H )
 otherwise
 min 1, 0 − p(H )

• p(H) is the prior probability of hypothesis H being true;


• p(H|E) is the probability that hypothesis H is true given
evidence E.
 1 if p(H) = 1

Certainty factors MB (H, E) =  max  p(H E), p(H)  − p(H)
 otherwise
 max 1, 0 − p(H)
theory 

1 if p(H) = 0
MD (H, E) =  min  p(H E), p(H)  − p(H)
 otherwise
 min 1, 0 − p(H)

Measure of Belief Measure of Disbelief

• The values of MB(H, E) and MD(H, E) range


between 0 and 1.
• The strength of belief or disbelief in hypothesis
H depends on the kind of evidence E observed.
• Some facts may increase the strength of belief,
but some increase the strength of disbelief.
Certainty factors theory

The total strength of belief or disbelief


in a hypothesis:
Measure of Belief Measure of Disbelief Hypothesis Evidence

MB H, E − MD H,E
cf =
1- min MB H,E , MD H, E
Certainty factors theory - Example
• Consider a simple rule:
IF A is X
THEN B is Y
• An expert may not be absolutely certain that this
rule holds.
• Also suppose it has been observed that in some
cases, even when the IF part of the rule is
satisfied and object A takes on value X, object B
can acquire some different value Z.
IF A is X
THEN B is Y {cf 0.7};
B is Z {cf 0.2}
Certainty factor
• The certainty factor assigned by a rule is
propagated through the reasoning chain.
• This involves establishing the net certainty of
the rule consequent when the evidence in the
rule antecedent is uncertain:
cf (H,e) = cf (E,e) x cf (H,E)
Hypothesis Evidence
Notes:
• cf (H, e): certainty factor hypothesis H was influenced by evidence e
• cf (E, e): certainty factor evidence E influenced by evidence e
• cf (H, E): certainty factor hypotheses H assuming the evidence
uncertain, i.e. when the cf (E, e) = 1
Certainty factor - Example
IF sky is clear
THEN the forecast is sunny {cf 0.8}
and the current certainty factor of sky is 0.5, then
cf (H,E) = 0.5 × 0.8 = 0.4
This result can be interpreted as “It may be
sunny”.
For conjunctive rules such as
IF <evidence E1>
………
AND <evidence En>
THEN <hypothesis H > {cf)

the certainty of hypothesis H, is established as follows:


cf (H,E1∩ E2∩…∩ En ) = min [cf (E1,e), cf (E2,e),...,cf (En ,e)] ´ cf

Example,
IF sky is clear
certainty factor
AND the forecast is sunny
THEN the action is ‘wear sunglasses’ {cf 0.8}
and the certainty of sky is clear is 0.9 and the certainty of the
forecast of sunny is 0.7,
then cf (H,E1∩E2) = min [0.9, 0.7] × 0.8 = 0.7 × 0.8 = 0.56
For disjunctive rules such as
IF <evidence E1>
………
OR <evidence En>
THEN <hypothesis H > {cf)

the certainty of hypothesis H , is established as follows:


cf (H,E1ᴜE2ᴜ…ᴜEn ) = min [cf (E1,e), cf (E2,e),...,cf (En ,e)] ´ cf

For example,
IF sky is overcast
certainty factor
OR the forecast is rain
THEN the action is ‘take an umbrella’ {cf 0.9}
and the certainty of sky is overcast is 0.6 and the certainty of the
forecast of rain is 0.8,
then cf (H,E1ᴜE2 ) = max [0.6, 0.8] × 0.9 = 0.8 × 0.9 = 0.72
Combine Certainty factor
• When the same consequent is obtained as a
result of the execution of two or more rules,
the individual certainty factors of these rules
must be merged to give a combined certainty
factor for a hypothesis.
• Suppose the knowledge base consists of the
following rules:
Rule 1 IF A is X
THEN C is Z {cf 0.8}

IF B is Y
Rule 2 THEN C is Z {cf 0.6}
Combine Certainty factor
• If we have two pieces of evidence (A is X
and B is Y) from different sources (Rule 1
and Rule 2) supporting the same
hypothesis (C is Z),
• then the confidence in this hypothesis
should increase and become stronger
than if only one piece of evidence had
been obtained.
Equation to calculate a combined certainty factor

 cf1 + cf2  (1 − cf1) if cf 0 andcf 0



 cf1 + cf2
cf (cf1, cf2) =  if cf 0 or cf 0
 1 − min cf1, cf2

 cf1 + cf2  (1 + cf1) if cf  0 andcf  0

where:
cf1 is the confidence in hypothesis H established by
Rule 1;
cf2 is the confidence in hypothesis H established by
Rule 2;
|cf1| and |cf2| are absolute magnitudes of cf1 and cf2,
respectively. Absolute value symbol
Certainty factors theory
• The certainty factors theory provides a
practical alternative to Bayesian reasoning.
• The heuristic manner of combining certainty
factors is different from the manner in which
they would be combined if they were
probabilities.
• The certainty theory is not “mathematically
pure” but does mimic the thinking process of
a human expert.
Comparison of Bayesian reasoning and
certainty factors
• Probability theory is the oldest and best-
established technique to deal with inexact
knowledge and random data.
• It works well in such areas as forecasting and
planning, where statistical data is usually
available and accurate probability statements
can be made.
Comparison of Bayesian reasoning and
certainty factors (continue)

• However, in many areas of possible


applications of expert systems, reliable
statistical information is not available or we
cannot assume the conditional independence
of evidence.
• As a result, many researchers have found the
Bayesian method unsuitable for their work.
Comparison of Bayesian reasoning and
certainty factors (continue)

• This dissatisfaction motivated the


development of the certainty factors theory.
• Although the certainty factors approach lacks
the mathematical correctness of the
probability theory, it outperforms subjective
Bayesian reasoning in such areas as
diagnostics.
Comparison of Bayesian reasoning and
certainty factors (continue)
• The Bayesian method is likely to be the most
appropriate if reliable statistical data exists,
the knowledge engineer is able to lead, and
the expert is available for serious decision-
analytical conversations.
• In the absence of any of the specified
conditions, the Bayesian approach might be
too arbitrary and even biased to produce
meaningful results.
Comparison of Bayesian reasoning and
certainty factors (continue)

• The Bayesian belief propagation is of


exponential complexity, and thus is
impractical for large knowledge bases.
• Certainty factors are used in cases where the
probabilities are not known or are too difficult
or expensive to obtain.
Comparison of Bayesian reasoning and
certainty factors (continue)
• The evidential reasoning mechanism can
manage incrementally acquired evidence, the
conjunction and disjunction of hypotheses, as
well as evidences with different degrees of
belief.
• The certainty factors approach also provides
better explanations of the control flow
through a rule-based expert system.
Fuzzy Reasoning
Difference between fuzzy logic and
probability
• Probability is ADDITIVE, means all its values
must add up to one.
• This is main difference between fuzzy logic
and probability.
• Although both probability and fuzzy logic
contain values between the range of 1 and 0,
fuzzy logic tells the extent of a specific
member function, whereas probability gives
the frequency, hence all values of its set must
add up to one.
Crisp Set theory
vs fuzzy logic
• Traditional set theory is also known as Crisp Set
theory.
• Traditional set theory set membership is fixed or
exact either the member is in the set or not.
• There is only two crisp values true or false.
• In case of fuzzy logic there are many values.
• With weight say x the member is in the set.
• The truth values of traditional set theory is either
0 or 1 and that of fuzzy set is between 0 and 1.
Fuzzy If-Then Rules
General format:
If x is A then y is B
Examples:
i. If pressure is high, then volume is small.
ii. If the road is slippery, then driving is dangerous.
iii. If a tomato is red, then it is ripe.
iv. If the speed is high, then apply the brake a little.
Fuzzy Reasoning
(Single rule with single antecedent)
Single rule with single antecedent (a thing that existed before)
i. Rule: if x is A then y is B
Graphic Representation:
A’ A B
w

X Y
i. Fact: x is A’
ii. Conclusion: y is B’
A’
B’

X Y
x is A’ y is B’
Fuzzy Reasoning
(Single rule with multiple antecedent)
Single rule with multiple antecedent
i. Rule: if x is A and y is B then z is C
Graphic Representation:
A’ A B’ B T-norm C
w

Z
X Y
i. Fact: x is A’ and y is B’
ii. Conclusion: z is C’
A’ B’
C’
Z
x is A’ X y is B’ Y z is C’
Fuzzy Reasoning
• Multiple rules with multiple antecedent
i. Rule 1: if x is A1 and y is B1 then z is C1
ii. Rule 2: if x is A2 and y is B2 then z is C2
iii. Fact: x is A’ and y is B’
iv. Conclusion: z is C’
• Graphic Representation: (next slide)
Multiple rules with multiple antecedent
Graphics representation:

A’ A1 B’ B1 C1
Rule
1 w1
Z
X Y
A’ A2 B’ B2 C2
Rule w2
2
Z
X Y
T-norm
A’ B’
C’
Z
x is A’ X y is B’ Y z is C’
Membership Functions
• The simplest membership functions are formed using
straight lines.
• The simplest is the triangular membership function,
and it has the function name trimf.
• The trapezoidal membership function, trapmf, has a
flat top and really is just a truncated triangle curve.
• These straight line membership functions have the
advantage of simplicity.

Triangular membership function


Membership Functions (triangular)
• Fuzzy Linguistic Variables are used to represent qualities
spanning a particular spectrum
• Temp: {Freezing, Cool, Warm, Hot}
• Question: What is the temperature?
• Answer: It is warm.
• Question: How warm is it?
Freezing Cool Warm Hot
1

0
10 30 50 70 90 110

Membership Functions Temp. (F°)


Membership Functions (triangular)
How cool is 36 F° (30°F − 32) × 5/9 = -1.111°C ) ?
It is 30% Cool and 70% Freezing

Freezing Cool Warm Hot


1

0.7

0.3

0
10 30 50 70 90 110
Temp. (F°)
Membership Functions (Gaussian distribution curve)
• Two membership functions are built on the Gaussian
distribution curve:
• a simple Gaussian curve and a two-sided composite of
two different Gaussian curves.
• The two functions are gaussmf and gauss2mf.
• The generalized bell membership has the function name
gbellmf.
• Because of their smoothness and concise notation,
Gaussian and bell membership functions are popular
methods for specifying fuzzy sets. Both of these curves
have the advantage of being smooth and nonzero at all
points.
Membership Functions (Sigmoidal membership function)
• Gaussian membership functions and bell membership functions
are unable to specify asymmetric membership functions, which are
important in certain applications.
• Sigmoidal membership function is defined, which is either open
left or right.
• Asymmetric and closed (i.e. not open to the left or right)
membership functions can be synthesized using two sigmoidal
functions, so in addition to the basic sigmf, you also have the
difference between two sigmoidal functions, dsigmf, and the
product of two sigmoidal functions psigmf.
Membership Functions (Polynomial based curves )
• Polynomial based curves account for several of the
membership functions in the toolbox.
• Three related membership functions are the Z, S, and Pi
curves, all named because of their shape.
• The function zmf is the asymmetrical polynomial curve
open to the left, smf is the mirror-image function that
opens to the right, and pimf is zero on both extremes
with a rise in the middle.
Rules As Knowledge
Rule-based reasoning
• One can often represent the expertise that
someone uses to do an expert task as rules.
• A rule means a structure which has an if
component and a then component.
The Edwin Smith papyrus
ABCDEECDBBACDACDBCDECDADCADBADE

The Edwin Smith ECDBBACDACDBCDECDADCADBADCDBBACDA


BCDEECDBBACDACDBCDECDAD
papyrus is a 3700-
BBACDACDBCDECDADCADBADEDCDBBA
year-old ancient
DCDBBADCDBBABCDECDADCADBADEACDA
Egyptian text.
BACDACDBCDECDADBACDACDBCDECDAD

• It contains medical descriptions of 48 different


types of head wound.
• There is a fixed format for each problem
description: Title - symptoms - diagnosis -
prognosis - treatment.
Rule-based reasoning: rules
Examples:
if - the leaves are dry, brittle and discoloured
then - the plant has been attacked by red spider
mite
if - the customer closes the account
then - delete the customer from the database
Rule-based reasoning: rules
• The statement, or set of
statements, after the word if
represents some pattern which
you may observe.
• The statement, or set of
statements, after the word
then represents some
conclusion that you can draw,
or some action that you should
take.
Rule-based
reasoning:
rules
A rule-based system:
–identifies a pattern and draws conclusions about
what it means,
or
–identifies a pattern and advises what should be done
about it,
or
–identifies a pattern and takes appropriate action.
Rule-based reasoning: rules
• The essence of a rule-based reasoning system is
that it goes through a series of cycles.
• In each cycle, it attempts to pick an appropriate
rule from its collection of rules, depending on the
present circumstances, and to use it.
Rule-based reasoning: rules
• Because using a rule produces new information,
it's possible for each new cycle to take the
reasoning process further than the cycle before.
• This is rather like a human following a chain of
ideas in order to come to a conclusion.
Terminology
• A rule as described in previous slide is often
referred to as a production rule.
• A set of production rules, together with
software that can reason with them, is known
as a production system.
Terminology
There are several different terms for the statements
that come after the word if, and those that come after
the word then.
• The statements after if may be called the
conditions, those after then may be called the
conclusions.
• The statements after if may be called the
premises, those after then may be called the
actions.
• The statements after if may be called the
antecedents, those after then may be called the
consequents.
Conditional branching
Is a production rule the same as a conditional
branching statement?

A production rule looks similar to the


if (statement to be evaluated) then (action)
pattern which is a familiar feature of all
conventional programming languages.
Conditional branching vs.
production rules
There is a radical difference between a
production system and a piece of conventional
software.
Conventional program
• if...then... structure is an integral part of the
code,
• represents a point where the execution can
branch in one of two (or more) directions.
Reasoning with production rules
• The statements forming the conditions, or the
conclusions, in such rules, may be structures,
following some syntactic convention (such as
three items enclosed in brackets).
• Very often, these structures will include
variables - such variables can, of course, be
given a particular value, and variables with the
same name in the same rule will share the
same value.
Example
(Reasoning with production rules)
• For example (assuming words beginning with
capital letters are variables, and other words are
constants): Unemployment
if [Person, age, Number] &
[Person, employment, none] &
[Number, greater_than, 18] &
[Number, less_than, 65]
then [Person, can_claim,
} 18<x<65

_benefit]
Reasoning with production rules

Architecture of a typical production system

observed data

working memory
select modify

rule
Inference
memory fire output
engine
Working
memory
and
rule memory

❖Holds items of data. Their presence, or their


absence, causes the inference engine to trigger
certain rules.
❖ e.g. working memory contains [john, age, 29]
& [john, employment, none]
❖ The system decides: does this match any rules
in the rule base? If so, choose the rule.
Inference
engine

Behaviour of the inference engine :


• the system is started by putting a suitable data
item into working memory.
• recognise-act cycle: when data in the working
memory matches the conditions of one of the
rules in the system, the rule fires (i.e.is brought
into action).
Advantage and disadvantage of
production systems
• The principle advantage of production rules :
➢ Notational convenience
(easy to express suitable pieces of knowledge in this
way)

• The principle disadvantage of production rules:


➢ Restricted power of expression
(many useful pieces of knowledge don’t fit this
pattern)
Advantages of production systems
• No need to bother about when or how or in
which sequence the rules are used; the
production system can deal with that.
• When one wishes to expand the knowledge, one
just adds more rules at the end of the rule base.
• The rules themselves are very easy to understand
and improve.
Fuzzy Expert System
Fuzzy
expert
system
Fuzzification interface
➢The fuzzy expert system receive linguistic terms, this
module has to have an ability to handle such fuzzy
information.
➢Each rule can have its certainty factor. This certainty
factor is used in the aggregation of the results from
each rule.
Fuzzy
expert
system
Inference engine
• The fuzzy expert systems can use the inference
methods of the fuzzy logic controller.
• It is difficult to have a fuzzy set with monotonic
membership function in the consequent part of a rule.
(Therefore especially, Mamdani method and Larsen
method are often used.)
Fuzzy
expert
system

Linguistic approximation
➢Instead of the defuzzification module, a linguistic
approximation module is needed to :
✓Finds a linguistic term which is closest to the
obtained fuzzy set.
✓Use a measuring technique of distance between
fuzzy sets.
Fuzzy
expert
system

Scheduler
➢Controls all the processes in the fuzzy expert system.
➢Determines the rules to be executed and sequence of
their executions.
➢Provides an explanation function for the result.
Fuzzy expert
system

Knowledge base
➢Principal design parameters for an fuzzy logic
controller
➢Contains a knowledge of the application
domain and the control goals.
Fuzzy expert systems
Knowledge
base

User
input Fuzzification Linguistic Output
interface Scheduler approximation

Inference
engine
Fuzzy logic controller
Fuzzy logic controller

Four main components


I. The fuzzification interface : transforms input
crisp values into fuzzy values
II. The knowledge base : contains a knowledge of
the application domain and the control goals.
III. The decision-making logic : performs inference
for fuzzy control actions
IV. The defuzzification interface : Defuzzification
means the fuzzy to crisp conversion
Choice of state
variables and
control variables
• State variables
– input variables of the fuzzy control system
– state, state error, state error deviation, and state error
integral are often used
• Control variables
– output variables of the fuzzy control system
• Selection of the variables
– depends on expert knowledge on the process
Fuzzification

• Fuzzification is the process of changing a real


scalar value into a fuzzy value.
• This is achieved with the different types of
fuzzifiers (membership functions).
Knowledge base
component (Data base)

Principal design parameters for an fuzzy logic


controller
i. discretization and normalization of
universe of discourse
ii. fuzzy partition of input and output spaces
iii. membership function of primary fuzzy set
Data base (Discretization of a universe
of discourse)
1. Quantization
i. The quantization discretizes a universe into
a certain number of segments.
ii. Each segment is labeled as a generic
element and forms a discrete universe.
iii. A fuzzy set is then defined on the discrete
universe of discourse.
iv. The number of quantization levels affects
an important influence on the control
performance.
Data base (Discretization of a universe
of discourse)
2. Discretization
Range Level No.
A scale mapping serves to x  −2.4 −6
transform measured variables −2.4  x  −2.0 −5
−1.6  x  −0.8 −4
into values in the discretized −0.8  x  −0.4 −3
universe. −0.4  x  −0.2 −2
−0.2  x  −0.1 −1
The mapping can be uniform −0.1  x  +0.1 0
(linear), non-uniform +0.1  x  +0.2 1
(nonlinear), or both. +0.2  x  +0.4 2
+0.4  x  +0.8 3
Example: A universe of
+0.8  x  +1.1 4
discourse is discretized into 13 +1.1  x  +1.4 5
levels (-6,…, 6). +1.4  x 6
Normalization of universe of discourse
• A discretization into a normalized universe.
• The normalized universe consists of finite number of
segments.
• The scale mapping can be uniform, non-uniform, or
both.
• Example: The universe of discourse [-6.9, +4.5] is
transformed into the normalized closed interval [-1, 1].
Range Normalized segments Normalized universe
[−6.9, −4.1] [−1.0, −0.5]

[−4.1, −2.2] [−0.5, −0.3]

[−2.2, −0.0] [−0.3, 0.0] [−1.0, +1.0]


[−0.0, +1.0] [0.0, +0.2]

[+1.0, +2.5] [+0.2, +0.6]

[+2.5, +4.5] [+0.6, +1.0]


Linguistic Variables
• A numerical variables takes numerical values:
Age = 65
• A linguistic variables takes linguistic values:
Age is old
• A linguistic values is a fuzzy set.
• All linguistic values form a term set:
T(age) = {young, not young, very young, ...
middle aged, not middle aged, ...
old, not old, very old, more or less old, ...
not very yound and not very old, ...}
Fuzzy partition with linguistic terms
Linguistic variable
i. in the antecedent of a rule forms a fuzzy input
space,
ii. in the consequent of the rule forms a fuzzy output
space.
iii. In general, associated with a term set.
Z
N P
7 linguistic terms are often used:
◼NB: negative big

−1 0 +1
◼NM: negative medium
◼NS: negative small
N: negative, Z: zero, P: positive
◼ZE: zero

NB NM NS ZE PS PM PB ◼PS: positive small


◼PM: positive medium
◼PB: positive big

−1 0 +1

NB, NM, NS, ZE, PS, PM, PB


Fuzzy partition of the space
Fuzzy partition of input and output spaces:
• Determines how many terms should exist in a term set.
• To find the number of primary fuzzy sets(linguistic
terms)
x2
x2

PS
big
ZO
NS
NB small
x1 x1
NB NS ZO PS PB small big
A fuzzy partition in 2-dimension input space A fuzzy partition having three rules
the maximum number of control rules = 20 (5x4)
Rule base
Source of fuzzy control rules
Derivation of fuzzy control rules
a) Heuristic method
i. Rules are formed by analyzing the behavior
of a controlled process.
ii. The derivation relies on the qualitative
knowledge of process behavior.
b) Deterministic method
i. Can systematically determine the linguistic
structure of rules.
Rule base
4 modes of derivation of fuzzy control rules
➢Expert experience and control engineering knowledge:
operating manual and questionnaire
➢Based on operators’ control actions :
observation of human controller’s actions in terms of input-
output operating data
➢Based on the fuzzy model of a process :
linguistic description of the dynamic characteristics of a process
➢Based on learning :
ability to modify control rules such as self-organizing controller
Types of fuzzy control rules:
1. State evaluation fuzzy control rules
A collection of rules of the form(MISO version)
R1: if x is A1, … and y is B1 then z is C1
R2: if x is A2, … and y is B2 then z is C2

Rn: if x is An, … and y is Bn then z is Cn
where x, … y and z = linguistic variables representing the
process state variable and the control variable.
Ai, … Bi and Ci are linguistic values of the variables x, … y
and z in the universe of discourse U, … V and W,
respectively i = 1, 2, … , n.
That is,
x  U, Ai  U, …, y  V, Bi  V, z  W, Ci  W
Types of fuzzy control rules:
2. Object evaluation fuzzy control rules
To predict present and future control actions, and evaluate
control objectives (predictive fuzzy control)
Typical rules
R1: if (z is C1 → (x is A1 and y is B1)) then z is C1.

Rn: if (z is Cn → (x is An and y is Bn)) then z is Cn.
• Control action is determined by an objective evaluation that
satisfies the desired states and objectives.
• x and y are performance indices for the evaluation and z is
control command.
• Ai and Bi are fuzzy values such as NM and PS.
• The most likely control rule is selected through predicting the
results (x, y) corresponding to every control command Ci, i = 1,
2, … , n.
Decision making logic
(Inference)
Mandani method
➢ minimum operator for a fuzzy implication
➢ max-min operator for the composition

Minimum

Maximum
The product operator
Decision making logic multiplies the terms of a
sequence or partial
(Inference) sequence.
Larsen method
➢ product operator(•) for a fuzzy implication
➢ max-product operator for the composition
Decision making logic
(Inference)
Tsukamoto method
Consequent part : fuzzy set with a monotonic membership
function

monotonic
function
Decision making logic
TSK method
(Inference)
The consequent part : function of input variables.
Defuzzification
• Defuzzification means the fuzzy to crisp
conversion
• Fuzzification = mapping is done to convert the
crisp results into fuzzy results
• Defuzzification = mapping is done to convert the
fuzzy results into crisp results.
• This process is capable of generating a non-fuzzy
control action.
Mean of maximum method (MOM)
The MOM strategy generates a control action which
represents the mean value of all control actions, whose
membership functions reach the maximum.
𝑘
𝑧𝑗
𝑧0 = ෍
𝑘
𝑗=1

Zj: control action whose membership functions reach the


maximum.
k: number of such control actions.
(z)

z0 z
Center of area method (COA)
COA generates the center of gravity of the possibility
distribution of a fuzzy set C .
σ𝑛𝑗=1 𝜇𝐶 (𝑧𝑗 ) ⋅ 𝑧𝑗
𝑧0 =
σ𝑛𝑗=1 𝜇𝐶 (𝑧𝑗 )

n : the number of quantization levels of the output


C : a fuzzy set defined on the output dimension (z)
(z)

z0 z
Bisector of area (BOA)
The BOA generates the action (z0) which partitions the
area into two regions with the same area .
𝑧0 𝛽
න 𝜇𝐶 (𝑧) 𝑑𝑧 = න 𝜇𝐶 (𝑧) 𝑑𝑧
𝛼 𝑧0

= min{z | z  W}
 = max{z | z  W}
Lookup table

• Due to the problem of time complexity, it takes much


time to compute the fuzzy inference and defuzzification.
• Simply shows relationships between input variables and
control output actions, can be constructed after making
the FLC and identifying the relationships between the
input and output variables.
• In general, it is extremely difficult to get an acceptable
lookup table of a nonlinear control system without
constructing a corresponding FLC.
Lookup table
Example
The two input variables error (e) and change of error
(ce), and control variable (v).
when e = −1.0 and ce = −0.5, we can obtain v =
−0.5
ce −1.0 −0.5 0 0.5 1.0
e
−1.0 −1.0 −0.5 −0.5 −0.5 −0.5
−0.5 −1.0 −1.0 0.5 −0.5 −0.5

0 −1.0 −1.0 0.5 −0.5 −0.5

0.5 0.5 0.5 1.0 1.0 1.0

1.0 0.5 0.5 0.5 1.0 1.0


Fuzzy logic - one of the most
sophisticated control systems
• Fuzzy logic applies the concept of ‘certain degree’
which is similar to the way human beings think.
Instead of just being either true or false, fuzzy
logic can be true partially and also false partially
at the same time. This is similar to the human
mind.
• Fuzzy logic can uses exact points representing to
what degree an event occurs and with fuzzy rules
it generates precise outcomes.
Advantages of fuzzy logic controller
❖Useful cases
i. The control processes are too complex to analyze
by conventional quantitative techniques.
ii. The available sources of information are
interpreted qualitatively, inexactly, or uncertainly.
❖Advantage of FLC
i. Parallel or distributed control
multiple fuzzy rules – complex nonlinear system
ii. Linguistic control
linguistic terms - human knowledge
iii. Robust control
more than 1 control rules – a error of a rule is not
fatal
Design procedure of fuzzy logic controller
1) Determination of state variables and control
variables
2) Determination of inference method
3) Determination of fuzzification method
4) Discretization and normalization of state variable
space
5) Partition of variable space.
6) Determination of the shapes of fuzzy sets
7) Construction of fuzzy rule base
8) Determination of defuzzification strategy
9) Test and tuning
10) Construction of lookup table
Application of Fuzzy Logic
Washing Machine
• The fuzzy logic controller for washing machine
consists of linguistic inputs i.e. type of dirt,
type of clothes, dirtiness of clothes, mass of
clothes.
• The sensor system - collects data from outer
environment and send them to controller
• The controller system sets the washing time
based on the information received from the
sensor system a fuzzy logic controller will be
used.
Washing Machine
Washing Machine
Regulating motor speed stability with 3 inputs:
• Reference speed
• Error = difference between the reference
speed with the actual speed
• D-error = current error difference with the
Determine the Output defined as previous error.
washing speed the reference speed
at the second system
input.
Air cooler
• Fuzzy logic control systems are used in
controller room cooler to control temperature
and humidity.
• The design work of the room cooler may
consists of more than one input and output.
Example:
• Two input (linguistic) variables: temperature
and humidity
• Three output variables: cooler fan speed,
water pump speed and exhaust fan speed.
Air cooler
Controlling a car
1. Rules for controlling a car:
❖Variables are:
• Distance to car in front and how fast it is changing,
delta, and acceleration to apply
❖Sets are:
• Distant - Very small, small, perfect, big, very big .
• Delta - Shrinking fast, shrinking, stable, growing,
growing fast.
• Acceleration - Brake hard, slow down, none, speed
up.
❖Rules for every combination of distance and delta
sets, defining an acceleration set
Controlling a car
2. Relevant rules are:
• If distance is small and delta is growing, then
maintain speed
• If distance is small and delta is stable, then
slow down
• If distance is perfect and delta is growing, then
speed up
• If distance is perfect and delta is stable, then
maintain speed
Controlling a car
3. Example for first rule:
• Distance is small has 0.75 truth,
• Delta (how fast it is changing) is growing has
0.3 truth.
Other automotive application examples

• Trainable fuzzy systems for idle speed control.


• Shift scheduling method for automatic
transmission
• Intelligent highway systems.
Medical application examples

• Medical diagnostic support system


• Control of arterial pressure during anesthesia.
• Fuzzy inference diagnosis of diabetes and
prostate cancer.
• Modelling of neuropathological findings in
Alzheimer’s patients.
Aerospace application examples

• Altitude control of spacecraft and satellite.


• Flow and mixture regulation in aircraft deicing
vehicles
Chemical engineering application
examples
• Control of PH level.
• Drying process.
• Chemical distillation process.
• Polymer extrusion production.
• A coke oven gas cooling plant.
Manufacturing industry application
examples
Optimization of food production
Marine industry application examples
• Autopilot of ships.
• Optimal route selection.
• Control of autonomuos underwater vehicles.
Financial sector application examples
• Banknote transfer control
• Fund management
• Stock market predictions.
Other Industrial application examples
Activated sludge wastewater treatment process
control.
• Water purification plant control.
• Qualitative pattern analysis for industrial
quality control.
Traffic control application examples
• Fuzzy logic is applied to control an intersection
of two one way streets.
• Fuzzy inference system is used to control
traffic flows and trip distribution.
Advantages of Fuzzy Logic System
• The structure of Fuzzy Logic Systems is easy
and understandable
• Fuzzy logic is widely used for commercial and
practical purposes
• It helps you to control machines and consumer
products
• It may not offer accurate reasoning, but the
only acceptable reasoning
• It helps you to deal with the uncertainty in
engineering
Advantages of Fuzzy Logic System
• Mostly robust as no precise inputs required
• It can be programmed to in the situation when
feedback sensor stops working
• It can easily be modified to improve or alter
system performance
• inexpensive sensors can be used which helps
you to keep the overall system cost and
complexity low
• It provides a most effective solution to
complex issues
Disadvantages of Fuzzy Logic Systems
• Fuzzy logic is not always accurate, so The results are
perceived based on assumption, so it may not be
widely accepted.
• Fuzzy systems don't have the capability of machine
learning as-well-as neural network type pattern
recognition
• Validation and Verification of a fuzzy knowledge-
based system needs extensive testing with hardware
• Setting exact, fuzzy rules and, membership functions
is a difficult task
• Some fuzzy time logic is confused with probability
theory and the terms
Multi-input/output fuzzy inference
system using the Python
Fuzzy Inference System (Phyton)
The design is based on several considerations on
Fuzzy Inference Systems, some being:
• A Fuzzy Inference System will require input
and output variables and a collection of fuzzy
rules.
• Both input and output variables will contain a
collection of fuzzy sets if the Fuzzy Inference
System is of Mamdani type.
Fuzzy Inference System (Phyton)
• During execution, input variables use the
input values to the system to fuzzify their sets,
that is they determine the degree of belonging
of that input value to all of the fuzzy sets of
the variable.
• Each rule contributes to some extent to the
output variables;
• the totality of this contribution will determine
the output of the system.
Fuzzy Inference System (Phyton)
• Fuzzy rules have the structure of the form:
if {antecedent clauses} then {consequent clauses}
• Therefore a rule will contain several clauses of
antecedent type and some clauses of
consequent type.
• Clauses will be of the form:
{variable name} is {set name}
System Diagram
Fuzzy Set class
A Fuzzy Set requires the following parameters so
that it can be initiated:
• name — the name of the set
• minimum value — the minimum value of the
set
• maximum value — the maximum value of the
set
• resolution — the number of steps between
the minimum and maximum value
Fuzzy Set class

• It is possible to represent a fuzzy set by using two


numpy arrays;
• One that will hold the domain values and one that
will hold the degree-of-membership values.
• Initially, all degree-of-membership values will be
all set to zero.
Fuzzy Set class
• It can be argued that if the minimum and maximum
values are available with the resolution of the set,
the domain numpy array is not required as the
respective values can be calculated.
• While this is true, a domain array was preferred in
below example so that the code is more readable
and simple.

FuzzySet init
Fuzzy Set class
• In the context of a fuzzy variable, all the sets
will have the same minimum, maximum and
resolution values.
• As we are dealing with a discretized domain, it
will be necessary to adjust any value used to set
or retrieve the degree-of-membership to the
closest value in the domain array.

FuzzySet domain value adjustment


Fuzzy Set class
• The class contains methods whereby a set of a
given shape can be constructed given a
corresponding number of parameters.

• In the case of a triangular set,


for example, three parameters are provided, two
that define the extents of the sets and one for the
apex.
Fuzzy Set class
It is possible to construct a triangular set by
using these three parameters (a, b, c) as can be
seen in the figure below:
Fuzzy Set class
The sets are based on numpy arrays, the equation
above can be translated directly to code, as can be
seen below.

Triangular set creation


Fuzzy Set class
• The Fuzzy Set class also contains union, intersection
and negation operators that are necessary so that
inferencing can take place.
• All operator methods return a new fuzzy set with
the result of the operation that took place.
Union of two Fuzzy Set objects
FuzzySet class
• Finally, we implemented the ability to obtain a
crisp result from a fuzzy set using the centre-of-
gravity method.
• It is important to mention that there is a large
number of defuzzification methods but the
centre-of-gravity method is popular.
Centre of gravity defuzzification
Fuzzy Variable classes
Fuzzy Variable classes
• Variables can be of input or output in type,
with the difference affecting the fuzzy
inference calculation.
• A Fuzzy Variable is a collection of sets that are
held in a python dictionary having the set
name as the key.
• Methods are available to add Fuzzy Sets to the
variable, where such sets will take the
variable’s limits and resolution.
Fuzzy Variable classes
• For input variables, fuzzification is carried out by
retrieving the degree-of-membership of all the
sets in the variable for a given domain value.
• The degree-of-membership is stored in the set as
it will be required by the rules when they are
evaluated.
Fuzzification of an input variable
Fuzzy Variable classes
• Output variables will ultimately produce the
result of a fuzzy inference iteration.
• This means that for Mamdani-type systems, as
we are building here, output variables will
hold the union of the fuzzy contributions from
all the rules, and will subsequently defuzzify
this result to obtain a crisp value that can be
used in real-life applications.
Fuzzy Variable classes
Output variables will require an additional Fuzzy
Set attribute that will hold the output
distribution for that variable, where the
contribution that was resulting from each rule
and added using the set union operator. The
defuzzification result can then be obtained by
calling the centre-of-gravity method for output
distribution set.
Fuzzy Variable classes
Fuzzy output variable output distribution and defuzzification
methods
Fuzzy Rules classes
• The Fuzzy Clause class requires two attributes;
a (i) fuzzy variable and a (ii) fuzzy set so that
the statement “variable is set” can be
created.
• Clauses are used to implement statements
that can be chained together to form the
antecedent and consequent parts of the rule.
Fuzzy Rules classes
• When used as an antecedent clause, the Fuzzy
Clause returns the last degree-of-membership
value of the set, that is calculated during the
fuzzification stage .
• The rule will combine the degree-of-membership
values from the various antecedent clauses using
the min operator, obtaining the rule activation
that is then used in conjunction with the
consequent clauses to obtain the contribution of
the rule to the output variables.
Fuzzy Rules classes
This operation is a two-step process:
• The activation value is combined with the
consequent FuzzySet using the min operator,
that will act as a threshold to the degree-of-
membership values of the FuzzySet.
• The resultant FuzzySet is combined with the
FuzzySets obtained from the other rules using
the union operator, obtaining the output
distribution for that variable.
Fuzzy Rules classes

Execution methods of a fuzzy clause as either antecedent or


consequent
Fuzzy Rules classes
The FuzzyRule class will, therefore, require two
attributes:
• a list containing the antecedent clauses and
• a list containing the consequent clauses
Fuzzy Rules classes
• During the execution of the Fuzzy Rule, the
procedure explained above is carried out.
• The Fuzzy Rule coordinates all the tasks by
utilizing all the various Fuzzy Clauses as
appropriate.

Rule execution
Fuzzy System Class
(Bringing it all together)
• At the topmost level of this architecture, we have
the FuzzySystem that coordinates all activities
between the FuzzyVariables and FuzzyRules.
• Hence the system contains the input and output
variables, that are stored in python dictionaries
using variable-names as keys and a list of the
rules.
• One of the challenges at this stage is the method
that the end-user will use to add rules, that
should ideally abstract the implementation detail
of the FuzzyClause classes.
Fuzzy System Class
(Bringing it all together)
• The method that was implemented consists of
providing two python dictionaries that will
contain the antecedent and consequent
clauses of the rule in the following format;
variable name : set name
• A more user-friendly method is to provide the
rule as a string and then parse that string to
create the rule.
Fuzzy System Class
Addition of a new rule to the
FuzzySystem
The execution of the inference process can be achieved with
following steps (codes):
1. The output distribution sets of all the output variables are
cleared.
2. The input values to the system are passed to the
corresponding input variables (each set in the variable can
determine its degree-of-membership for that input value)
3. Execution of the Fuzzy Rules takes place (the output
distribution sets of all the output variables will now
contain the union of the contributions from each rule)
4. The output distribution sets are defuzzified using a
centre-of-gravity defuzzifier to obtain the crisp result.
Addition of a new rule to the
FuzzySystem
1

4
The use of the fuzzy inference system
• A fuzzy system begins with the consideration of the
input and output variables, and the design of the
fuzzy sets to explain that variable.
• The variables will require a lower and upper limit
and, as we will be dealing with discrete fuzzy sets,
the resolution of the system.
• Therefore a variable definition will look as follows
temp = FuzzyInputVariable('Temperature', 10, 40, 100)
• where the variable ‘Temperature’ ranges between
10 and 40 degrees and is discretized in 100 bins.
Fuzzy inference system
• The fuzzy sets define for the variable will require
different parameters depending on their shape.
• In the case of triangular sets, for example, three
parameters are needed, two for the lower and upper
extremes having a degree of membership of 0 and
one for the apex which has a degree-of-membership
of 1.
• A triangular set definition for variable ‘Temperature’
can, therefore, look as follows;
temp.add_triangular('Cold', 10, 10, 25)
• where the set called ‘Cold’ has extremes at 10 and 25
and apex at 10 degrees.
Fuzzy inference system
• If the system consists of two input variables,
‘Temperature’ and ‘Humidity’ and a single output
variable ‘Speed’. Each variable us described by
three fuzzy sets.
• The definition of the output variable ‘Speed’
looks as follows:
motor_speed = FuzzyOutputVariable('Speed', 0, 100, 100)
motor_speed.add_triangular('Slow', 0, 0, 50)
motor_speed.add_triangular('Moderate', 10, 50, 90)
motor_speed.add_triangular('Fast', 50, 100, 100)
Fuzzy inference system
As we have seen before, the fuzzy system is the
entity that will contain these variables and fuzzy
rules. Hence the variables will have to be added
to a system as follows:
system = FuzzySystem()
system.add_input_variable(temp)
system.add_input_variable(humidity)
system.add_output_variable(motor_speed)
Fuzzy Rules
• A fuzzy system executes fuzzy rules to operate of the
form

If x1 is S and x2 is M then y is S
• where the If part of the rule contains several
antecedent clauses and the then section will include
several consequent clauses.
• For simplification, we will assume rules that require
an antecedent clause from each input variable and
are only linked together with an ‘and’ statement.
• It is possible to have statements linked by ‘or’ and
statements can also contain operators on the sets like
‘not’.
Fuzzy Rules
• The simplest way to add a fuzzy rule to the
system is to provide a list of the antecedent
clauses and consequent clauses.
• One method of doing so is by using a python
dictionary that contains

Variable:Set

entries for the clause sets.


Fuzzy Rules
Hence the above rule can be implemented as
follows:
system.add_rule(
{ 'Temperature':'Cold',
'Humidity':'Wet' },
{ 'Speed':'Slow'})
Fuzzy Rules
• Execution of the system involves inputting values for
all the input variables and getting the values for the
output values in return.
• Again this is achieved through the use of dictionaries
that us the name of the variables as keys.

output = system.evaluate_output({
'Temperature':18,
'Humidity':60 })

• The system will return a dictionary containing the


name of the output variables as keys, and the
defuzzified result as values.
Thank you for listening

You might also like