## Introduction To Fuzzy Logic & Matlab Fuzzy Toolbox

P=Getting hotter Z=Not changing N=Getting colder. OUTPUT Conclusion & System Response. Output H = Call for heating - = Don't change anything C = ...

Introduction To Fuzzy Logic & Matlab Fuzzy Toolbox By: Hanieh Borhanazad

Rule-based expert systems The human mental process is internal, and it is too complex to be represented as an algorithm.  However, most experts are capable of expressing their knowledge in the form of rules for problem solving IF the ‘traffic light’ is green THEN the action is go IF the ‘traffic light’ is red THEN the action is stop 

Rules as a knowledge representation technique 

The term rule in AI, can be defined as an IF-THEN structure that relates given information or facts in the IF part to some action in the THEN part. A rule provides some description of how to solve a problem. Rules are relatively easy to create and understand.

Rules as a knowledge representation technique Any rule consists of two parts: the IF part, called the antecedent (premise or condition) and the THEN part called the consequent (conclusion or action). IF THEN

Rules as a knowledge representation technique A rule can have multiple antecedents joined by the keywords AND (conjunction), OR (disjunction) or a combination of both.

IF AND . . .

. . .

AND THEN

IF OR

. . .

. . .

OR THEN

The antecedent of a rule incorporates two parts: an object (linguistic object) and its value. The object and its value are linked by an operator. The operator identifies the object and assigns the value. Operators such as is, are, is not, are not are used to assign a symbolic value to a linguistic object. Expert systems can also use mathematical operators to define an object as numerical and assign it to the numerical value. IF ‘age of the customer’ < 18

AND THEN

‘cash withdrawal’ > 1000 ‘signature of the parent’ is required

Rules can represent relations, recommendations, directives, strategies and heuristics: Relation IF THEN

the ‘fuel tank’ is empty the car is dead

Recommendation IF the season is autumn AND the sky is cloudy AND the forecast is drizzle THEN the advice is ‘take an umbrella’

Directive IF AND THEN

the car is dead the ‘fuel tank’ is empty the action is ‘refuel the car’

Strategy IF THEN

the car is dead the action is ‘check the fuel tank’; step1 is complete

IF

step1 is complete

AND

the ‘fuel tank’ is full

THEN

the action is ‘check the battery’; step2 is complete

Heuristic IF AND AND THEN

the spill is liquid the ‘spill pH’ < 6 the ‘spill smell’ is vinegar the ‘spill material’ is ‘acetic acid’

Forward chaining and backward chaining 

In a rule-based expert system, the domain knowledge is represented by a set of IF-THEN production rules and data is represented by a set of facts about the current situation.  The inference engine compares each rule stored in the knowledge base with facts contained in the database.  When the IF (condition) part of the rule matches a fact, the rule is fired and its THEN (action) part is executed.  The matching of the rule IF parts to the facts produces inference chains.  The inference chain indicates how an expert system applies the rules to reach a conclusion.

Inference engine cycles via a matchfire procedure Database Fact: A is x Fact: B is y

Match

Fir e Knowledge Base Rule: IF A is x THEN B is y

An example of an inference chain

EXAMPLE!

A simple block diagram of the control system.

It is necessary to establish a meaningful system for representing the linguistic variables in the matrix. For this example, the following will be used: "N" = "negative" error or error-dot input level "Z" = "zero" error or error-dot input level "P" = "positive" error or error-dot input level "H" = "Heat" output response "-" = "No Change" to current output "C" = "Cool" output response Define the minimum number of possible input product combinations and corresponding output response conclusions using these terms. For a three-by-three matrix with heating and cooling output responses, all nine rules will need to be defined. The conclusions to the rules with the linguistic variables associated with the output response for each rule are transferred to the matrix.

Typical control system response

Linguistic rules describing the control system consist of two parts; an antecedent block (between the IF and THEN) and a consequent block (following THEN). Depending on the system, it may not be necessary to evaluate every possible input combination (for 5-by-5 & up matrices) since some may rarely or never occur. By making this type of evaluation, usually done by an experienced operator, fewer rules can be evaluated, thus simplifying the processing logic and perhaps even improving the FL system performance.

DEFINITIONS: INPUT#1: ("Error", positive (P), zero (Z), negative (N))  INPUT#2: ("Error-dot", positive (P), zero (Z), negative (N))  CONCLUSION: ("Output", Heat (H), No Change (-), Cool (C))  INPUT#1 System Status  Error = Command-Feedback  P=Too cold, Z=Just right, N=Too hot  INPUT#2 System Status  Error-dot = d(Error)/dt  P=Getting hotter Z=Not changing N=Getting colder  OUTPUT Conclusion & System Response  Output H = Call for heating - = Don't change anything C = Call for cooling  SYSTEM OPERATING RULES 

INPUT#1: ("Error", positive (P), zero (Z), negative (N)) INPUT#2: ("Error-dot", positive (P), zero (Z), negative (N)) CONCLUSION: ("Output", Heat (H), No Change (-), Cool (C))

Introduction to Fuzzy Logic

The closer one looks at a real world problem, the fuzzier becomes its Solution (Zadeh 1973)

Introduction to Fuzzy Logic 

The Fuzzy Logic tool was introduced in 1965, also by Lotﬁ Zadeh, and is a mathematical tool for dealing with uncertainty. It oﬀers to a soft computing partnership the important concept of computing with words’. The fuzzy theory provides a mechanism for representing linguistic constructs such as “many,” “low,” “medium,” “often,” “few.”

The utility of fuzzy sets lies in their ability to model uncertain or ambiguous data.  A fuzzy system is a set of fuzzy rules that converts inputs to outputs. 

A fuzzy logic system which accepts imprecise data and vague statements such as low, medium, high and provides decisions

Why fuzzy?

Fuzzy logic is determined as a set of mathematical principles for knowledge representation based on degrees of membership rather than on crisp member-ship of classical binary logic. Unlike two-valued Boolean logic, fuzzy logic is multi-valued. It deals with degrees of membership and degrees of truth. Fuzzy logic uses the continuum of logical values between 0 (completely false) and 1 (completely true). Instead of just black and white, it employs the spectrum of colours, accepting that things can be partly true and partly false at the same time. As can be seen in Figure fuzzy logic adds a range of logical values to Boolean logic. Classical binary logic now can be considered as a special case of multi-valued fuzzy logic.

Fuzzy logic

classical logic

If we take “short” as a height equal to or less than 140 cm, then 139 cm would easily become the member of the set “short” and 141 cm will not be a member of the set “short.”  The membership value is “1” if it belongs to the set or “0” if it is not a member of the set. Thus membership in a set is found to be binary i.e., the element is a member of aset or not. 

It can be indicated as,

Where XA(x) is the membership of element x in set A and A is the entire seton the universe.  This membership was extended to possess various “degree of membership”  on the real continuous interval [0,1]. Zadeh formed fuzzy sets as the sets on the universe X which can accommodate “degrees of membership.” 

Fuzzy Sets Degree of Membership Name

Height, cm

Chris

Crisp

Fuzzy

208

1

1.00

Mark

205

1

1.00

John Tom

198 181

1 1

0.98 0.82

David

179

0

0.78

Mike

172

0

0.24

Bob

167

0

0.15

Steven

158

0

0.06

Bill

155

0

0.01

Peter

152

0

0.00

Fuzzy Sets The values 0 and 1 describe “not belonging to” and “belonging to” a conventional set respectively;  values in between represent “fuzziness.” Determining the membership function is subjective to varying degrees depending on the situation. 

Fuzzy sets The fuzzy sets “tall” and “short.” The classiﬁcation is subjective – it depends on what height is measured relative to. At the extremes, the distinction is clear, but there is a large amount of overlap in the middle

Operations on Fuzzy Sets 

There are various operations that can be performed in the classical or crisp sets. The results of the operation performed on the classical sets will be deﬁnite. The operations that can be performed on the classical sets are dealt in detail below: Consider two sets A and B deﬁned on the universe X. The deﬁnitions of the operation for classical sets are based on the two sets A and B deﬁned on the universe X.

Operations on Fuzzy Sets 

Let A be a fuzzy interval between 5 and 8 and B be a fuzzy number about 4. The corresponding figures are shown below.

Operations on Fuzzy Sets Complement/Negation  2 fuzzy sets are complementary if for all elements of A, the degree of membership in B is 1-A(s). (notice the blue line). 

Operations on Fuzzy Sets Union (A or B)  The union of two fuzzy sets will assign degree of membership equal to the highest of the two sets. (notice the blue line). 

Operations on Fuzzy Sets Intersection (A and B)  The intersection of two fuzzy sets will assign degree of membership equal to the lowest of the two sets. (notice the blue line). 

Q??? Example 2.5. We want to compare two sensors based upon their detection levels and gain settings. The following table of gain settings and sensor detection levels with a standard item being monitored provides typical membership values to represents the detection levels for each of the sensors.  The universe of discourse is X = { 0, 20, 40, 60, 80, 100 } . Find the membership function for the two sensors: 

A!!! 

Solution. The membership functions for the two sensors in standard discrete form are:

Q&A

Fuzziﬁcation The process of ﬁnding the membership grade of an input:

Defuzziﬁcation There are seven methods used for defuzzifying the fuzzy output functions. They are: (1) Max-membership principle, (2) Centroid method, (3) Weighted average method, (4) Mean–max membership, (5) Centre of sums, (6) Centre of largest area, and (7) First of maxima or last of maxima

Centroid method This is the most widely used method. This can be called as center of gravity or center of area method. It can be deﬁned by the algebraic expression:

Defuzziﬁcation: Getting back to crisp numbers The process of reducing a fuzzy set to a single crisp value  Centre of area is most commonly used: 

Fuzzy Logic Systems

Fuzzy Logic Systems