Understanding Fuzzy Logic Basics
Fuzzy logic is a powerful concept that involves mapping inputs to outputs using rules, membership functions, and fuzzy sets. Logical operations like AND, OR, and NOT play a key role, along with if-then rules in formulating conditional statements. The fuzzy inference process includes fuzzification, applying operators, implications, aggregations, and defuzzification. A practical example of a dinner scenario with fuzzy rules is provided to illustrate how fuzzy logic works.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Experiment No. (14) Fuzzy Logic Concepts Object: The object of this experiment is the basics of fuzzy logic. Fuzzy logic: The point of fuzzy logic is to map an input space to an output space, and the primary mechanism for doing this if-then statements called rules. All rules are evaluated in parallel, and the order of the rules is unimportant. themselves are useful because they refer to variables and the adjectives that describe those variables. is a list of The rules Membership Functions and Fuzzy Sets: A membership function(MF) is a curve that defines how each point in the input space is mapped to a membership value (or degree of membership) between 0 and 1. A fuzzy set is an extension of a classical set. If X is the universe of discourse and its elements are denoted by x, then a fuzzy set Ain X is defined as a set of ordered pairs. A = {x, pA(x) | x X} HA(x) is called the membership function (or MF) of x in A. The toolbox includes 11 built-in membership function types such as (Piece-wise linear function, Gaussian distribution, Sigmoid curve, Quadratic, Triangular, ...). For example, a fuzzy set is the set of tall people. In this case, the universe of discourse is all potential heights, say from three feet to nine feet. 1
Logical Operations: There are three logical operations in fuzzy logic (AND, OR, NOT) AND OR NOT min(A,B) max(A,B) (1-A) If-Then Rules The 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 xis A, then yis B where Aand Bare linguistic values defined by fuzzy sets on the ranges (universes of discourse) X and Y, respectively. The if-part of the rule "x is A" is called the antecedent or premise, while the then-part of the rule "y is B" is called the consequent or conclusion. An example of such a rule might be If service is good then tip is average If sky is gray and wind is strong and barometer is falling, then ... Fuzzy Inference Process Fuzzy inference is the process of formulating the mapping from a given input to an output using fuzzy logic. Fuzzy inference process comprises of five parts: Fuzzification of the input variables Application of the fuzzy operator (AND or OR) in the antecedent part Implication from the antecedent to the consequent part Aggregation of the consequents across the rules Defuzzification 2
Dinner for Two a 2 input, 1 output, 3 rule system R . 1 If servce is poor or food is rancid then tip is cheap. Input 1 Service (0-10) Output Tip (5-25%) Rule 2 If servce is good, then tip is average. Input 2 Food (0-10 f servce is exce ent or food is delicious, then tip is generous. Rule 3 The inputs are crisp (non-fuzzy) numbers limited to a specific range. All rules are evaluated in parallel using fuzzy reasoning. The results of the rules are combined and distilled (defuzzified). The result is crisp (non-fuzzy) number (1) Fuzzify Inputs: 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 (fuzzification). (2) Apply fuzzy operator: If the antecedent of a rule has more than one part, the fuzzy operator is applied to obtain one number that represents the result of the rule antecedent. In the 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. The probabilistic OR method (also known as the algebraic sum) is calculated according to the equation: probor(a,b)= a+ b - ab 3
(3) Apply Implication Method: 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. (4) Aggregate All Outputs: The input of the aggregation process is the list of truncated output functions returned by the implication process for each rule. The output of the aggregation process is one fuzzy set for each output variable. Three built-in methods are supported for aggregation: max (maximum), probor (probabilistic OR), sum (sum of the rule output sets) 4
(5) Defuzzify: The aggregate of a fuzzy set encompasses a range of output values, which must be defuzzified to obtain a single output value from the set. There are five built-in defuzzification methods supported: centroid, bisector, middle of maximum (the average of the maximum value of the output set), largest of maximum, and smallest of maximum. 5
Procedure: 1- Plot eleven fuzzy membership functions according to given parameters over two rows? 1.1. Define the membership functions according to the given parameters mf = [... fismf('trapmf,[-19 -17 -12 -7]) ... fismf('gbellmf,[3 4 -8]) ... fismf('trimf,[-9 -1 2]) ... fismf('gaussmf,[3 5]) ... fismf('gauss2mf,[3 10 5 13]) ... fismf('smf,[11 17]) ... fismf('zmf,[-18 -10]) ... fismf('psigmf,[2 -11 -5 -4]) ... fismf('dsigmf,[5 -3 1 5]) ... fismf('pimf,[0 7 11 15]) ... fismf('sigmf,[2 15]) ... ]; 1.2. Evaluate the membership functions. x = linspace(-20,20,201); y = evalmf(mf,x); 1.3. Plot the evaluated membership functions with labels. subplot(2,1,1); plot(x,y(1:6,:)'); axis([min(x) max(x) 0 1.2]); text((mf(1 ).Parameters(2)+mf(1 ).Parameters(3))/2,1.1 ,mf(1 ).Type,... ,horizon',,center'); text(mf(2).Parameters(3),1.1,mf(2).Type,... 6
'horizon'/center'); text(mf(3).Parameters(2),1.1,mf(3).Type,... 'horizon','center'); text(mf(4).Parameters(2),1.1,mf(4).Type,... 'horizon','center'); text((mf(5).Parameters(2)+mf(5).Parameters(4))/2,1.1 ,mf(5).Type,... 'horizon','center'); text(mf(6).Parameters(2), 1.1,mf(6).Type,... 'horizon','center'); h_gca = gca; h_gca.XTick = []; subplot(2,1,2); plot(x,y(7:11,:)'); axis([min(x) max(x) 0 1.2]); text(mf(7).Parameters(1),1.1,mf(7).Type,... 'horizon','center'); text((mf(8).Parameters(2)+mf(8).Parameters(4))/2,1.1,mf(8).Type,... 'horizon','center'); text((mf(9).Parameters(2)+mf(9).Parameters(4))/2,1.1 ,mf(9).Type,... 'horizon','center'); text((mf(10).Parameters(2)+mf(10).Parameters(3 ))/2,1.1,mf(10).Type,... 'horizon','center'); text(mf(11 ).Parameters(2),1.1 ,mf(11 ).Type,... 'horizon','center'); h_gca = gca; h_gca.XTick = []; 2. Suppose you have the following region to be defuzzified. Display five defuzzification methods supported in the Fuzzy Logic Toolbox x = -10:0.1:10; 7
mfl = trapmf(x,[-10 -8 -2 2]); mf2 = trapmf(x,[-5 -3 2 4]); mf3 = trapmf(x,[2 3 8 9]); mf1 = max(0.5*mf2,max(0.9*mf1,0.1*mf3)); figure('Tag','defuzz'); plot(x,mf1 ,'LineWidth',3); h_gca = gca; h_gca.YTick = [0 .5 1] ; ylim([-1 1]); 2.1. Centroid Method returns the center of area under the curve. x1 = defuzz(x,mf1,'centroid'); h1 = line([x1 x1],[-0.2 1.2],'Color','k'); t1 = text(x1,-0.2,' centroid','FontWeight','bold'); 2.2. Bisector is the vertical line that will divide the region into two sub-regions of equal area. x2 = defuzz(x,mf1,'bisector'); gray = 0.7*[1 1 1]; h1.Color = gray; t1.Color = gray; h2 = line([x2 x2],[-0.4 1.2],'Color','k'); t2 = text(x2,-0.4,' bisector','FontWeight','bold'); 2.3. Middle, Smallest, and Largest of Maximum stand for Middle, Smallest, and Largest of Maximum, respectively. If the aggregate membership function has a unique maximum, then MOM, SOM, and LOM all take on the same value. x3 = defuzz(x,mf1,'mom') x4 = defuzz(x,mf1,'som') x5 = defuzz(x,mf1 ,'lom') h2.Color = gray; t2.Color = gray; h3 = line([x3 x3],[-0.7 1.2],'Color','k'); 8
t3 = text(x3,-0.7,' MOM,,,FontWeight,,,bold'); h4 = line([x4 x4],[-0.8 1.2],'Color,,,k'); t4 = text(x4,-0.8,' SOM',,FontWeight,,,bold'); h5 = line([x5 x5],[-0.6 1.2],'Color,,,k'); t5 = text(x5,-0.6,' LOM',,FontWeight,,,bold'); 2.4 Picking a Method, Which of these methods is the right one? There s no simple answer. you can always change your defuzzification method to see if another method works better. h3.Color = gray; t3.Color = gray; h4.Color = gray; t4.Color = gray; h5.Color = gray; t5.Color = gray; h1.Color = 'red'; t1.Color = 'red'; Discussion: 1. In which problems? the fuzzy logic is not suitable? 2. Define and plot your own fuzzy membership functions? 9