scl-fuzzy toolbox

21
1 Universidade Nova de Lisboa Faculdade de Ciências e Tecnologia Practice on Science of Computational Logic Ning Chen([email protected])

Upload: titou05

Post on 26-Mar-2015

78 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: SCL-fuzzy toolbox

1

Universidade Nova de LisboaFaculdade de Ciências e Tecnologia

Practice on Science of Computational Logic

Ning Chen([email protected])

Page 2: SCL-fuzzy toolbox

2

Universidade Nova de Lisboa

What is Matlab?

MATLAB is a numerical computing environment and programming language. Created by The MathWorks.MATLAB allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages.

Page 3: SCL-fuzzy toolbox

3

Universidade Nova de Lisboa

Fuzzy Logic Toolbox of Matlab

The Fuzzy Logic Toolbox extends the MATLAB technical computing environment with tools for the design of systems based on fuzzy logic.The Fuzzy Logic Toolbox allows you to do several things, but the most important thing it lets you do is create and edit fuzzy inference systems. You can create these systems using graphical tools or command-line functions.

Page 4: SCL-fuzzy toolbox

4

Universidade Nova de Lisboa

Membership Function

The Fuzzy Logic Toolbox includes 11 built-in membership function types. These 11 functions are, in turn, built from several basic functions: piecewise, linear functions, Gaussian distribution function, the sigmoid curve, quadratic and cubic polynomial curves.

Page 5: SCL-fuzzy toolbox

5

Universidade Nova de Lisboa

Page 6: SCL-fuzzy toolbox

6

Universidade Nova de Lisboa

Page 7: SCL-fuzzy toolbox

7

Universidade Nova de Lisboa

Summary of Membership Functions

Fuzzy sets describe vague concepts (fast runner, hot weather, weekend days).A fuzzy set admits the possibility of partial membership in it. (Friday is sort of a weekend day, the weather is rather hot).The degree an object belongs to a fuzzy set is denoted by a membership value between 0 and 1. (Friday is a weekend day to the degree 0.8).A membership function associated with a given fuzzy set maps an input value to its appropriate membership value.

Page 8: SCL-fuzzy toolbox

8

Universidade Nova de Lisboa

Fuzzy Rules

Fuzzy sets and fuzzy operators are the subjects and verbs of fuzzy logic. These if-then rule statements are used to formulate the conditional statements that comprise fuzzy logic.A single fuzzy if-then rule assumes the form: if x is A then y is B, where A and B are linguistic values defined by fuzzy sets on theranges (universes of discourse) X and Y, respectively. The if-part of the rule “x is A” is called the condition or premise, while the then-part of the rule “y is B” is called the consequent or conclusion. More examples

If service is good then tip is averageif sky is gray and wind is strong then barometer is falling.if temperature is cold then hot water valve is open and cold water valve is shut

Page 9: SCL-fuzzy toolbox

9

Universidade Nova de Lisboa

Step 1: Fuzzy Input

The first step is to take the inputs and determine the degree to which they belong to each of the appropriate fuzzy sets via membership functions.In the Fuzzy Logic Toolbox, the input is always a crisp numerical value limited to the universe of the input variable

Page 10: SCL-fuzzy toolbox

10

Universidade Nova de Lisboa

Step 2: Apply Fuzzy OperatorOnce the inputs have been fuzzified, we know the degree to which each part of the condition has been satisfied for each rule. If the condition of a given rule has more than one part, the fuzzy operator is applied to obtain one number that represents the result of the condition for that rule. This number will then be applied to the output function.In the Fuzzy Logic Toolbox, two built-in AND methods are supported: min(minimum) and prod (product). Two built-in OR methods are also supported: max (maximum), and the probabilistic OR method probor.

Page 11: SCL-fuzzy toolbox

11

Universidade Nova de Lisboa

Step 3: Apply Implication Method

Use the degree of support for the entire rule to shape the output fuzzy set. The consequent of a fuzzy rule assigns an entire fuzzy set to the output. This fuzzy set is represented by a membership function that is chosen to indicate the qualities of the consequent. Implication is implemented for each rule. Two built-in methods are supported, and they are the same functions that are used by the AND method: min(minimum), which truncates the output fuzzy set, and prod (product), which scales the output fuzzy set.

Page 12: SCL-fuzzy toolbox

12

Universidade Nova de Lisboa

Page 13: SCL-fuzzy toolbox

13

Universidade Nova de Lisboa

Step 4: Aggregate All Outputs

Since decisions are based on the testing of all of the rules in an FIS, the rules must be combined in some manner in order to make a decision. Aggregation is the process by which the fuzzy sets that represent the outputs of each rule are combined into a single fuzzy set.Three built-in methods are supported: max (maximum), probor (probabilistic OR), and sum (simply the sum of each rule’s output set).

Page 14: SCL-fuzzy toolbox

14

Universidade Nova de Lisboa

Page 15: SCL-fuzzy toolbox

15

Universidade Nova de Lisboa

Step 5: Defuzzify

The input for the defuzzification process is a fuzzy set and the output is a single number.There are five built-in methods supported: centroid, bisector, middle of maximum (the average of the maximum value of the output set), largest of maximum, and smallest of maximum.

Page 16: SCL-fuzzy toolbox

16

Universidade Nova de Lisboa

Fuzzy Inference System in Matlab

Page 17: SCL-fuzzy toolbox

17

Universidade Nova de Lisboa

The FIS Editor: handle the high-level issues for the system: How many input and output variables? What are their names?The Membership Function Editor: define the shapes of all the membership functions associated with each variable.The Rule Editor: edit the list of rules that defines the behavior of the system.The Rule Viewer: display the fuzzy inference diagram. It can show (for example) which rules are active, or how individual membership function shapes are influencing the results. The Surface Viewer: display the dependency of one of the outputs on any one or two of the inputs—that is, it generates and plots an output surface map for the system.

Page 18: SCL-fuzzy toolbox

18

Universidade Nova de Lisboa

Demo: How to Pay Tipper? The Basic Tipping Problem: Given a number between 0 and 10 that represents the quality of service at a restaurant (where 10 is excellent), and another number between 0 and 10 that represents the quality of the food at that restaurant (again, 10 is excellent), what should the tip be?Fuzzy Inference SystemInput: service, foodOutput: tipperLinguistic terms:

Service: poor, good, excellentFood: rancid, deliciousTipper: low, average, generous

Rules1. If the service is poor or the food is rancid, then tip is cheap.2. If the service is good, then tip is average.3. If the service is excellent or the food is delicious, then tip is generous.

Page 19: SCL-fuzzy toolbox

19

Universidade Nova de Lisboa

Structure of ‘Tipper’ Inference System

Page 20: SCL-fuzzy toolbox

20

Universidade Nova de Lisboa

System Display Functions

High-level view of interference system from command line:

Plotfis: display the whole system as a block diagram as it would appear in FIS Editor.Plotmf: plots all membership functions associated with a given variables.Gensurf: plot one or two inputs versus any one output of a given system.

Page 21: SCL-fuzzy toolbox

21

Universidade Nova de Lisboa

Exercise: A Fuzzy Inference SystemA single-input and single-output fuzzy inference system is described as

follows:IF X is small THEN Y is small.IF X is medium THEN Y is medium.IF X is large THEN Y is large.

The trapezoid membership functions for input linguistic values ‘small, medium, and Large’ described as follows:

trapmf(x,[−20,−15, −6, −3]),trapmf(x,[−6,−3,3,6]), trapmf(x,[3,6,15,20])(refer to trapmf.m in Fuzzy Logic Toolbox). The trapezoid membership functions for output linguistic values ‘small,

medium, and large’ described as follows:trapmf(x,[−2.46,−1.46,1.46,2.46]),trapmf( x,[1.46,2.46,5,7]),

trapmf(x,[5,7,13,15]).Note that the input and output membership functions are defined on

different universes. Suppose the input values are x = −8, −5,0,5,8, calculate the correspondingdefuzzified outputs with centroid defuzzification strategy.