# Fuzzy logic

Trainer em bits bhopal
3 de Jan de 2013
1 de 12

### Fuzzy logic

• 1. fuzzy logic: Fuzzy logic is a superset of conventional (Boolean) logic that has been extended to handle the concept of partial truth -- truth values between "completely true" and "completely false". It was introduced by Dr. Lotfi Zadeh of UC/Berkeley in the 1960's as a means to model the uncertainty of natural language. Zadeh says that rather than regarding fuzzy theory as a single theory, we should regard the process of ``fuzzification'' as a methodology to generalize ANY specific theory from a crisp (discrete) to a continuous (fuzzy) form. Fuzzy Subsets: Just as there is a strong relationship between Boolean logic and the concept of a subset, there is a similar strong relationship between fuzzy logic and fuzzy subset theory. In classical set theory, a subset U of a set S can be defined as a mapping from the elements of S to the elements of the set {0, 1}, U: S --> {0, 1} This mapping may be represented as a set of ordered pairs, with exactly one ordered pair present for each element of S. The first element of the ordered pair is an element of the set S, and the second element is an element of the set {0, 1}. The value zero is used to represent non-membership, and the value one is used to represent membership. The truth or falsity of the statement x is in U is determined by finding the ordered pair whose first element is x. The statement is true if the second element of the ordered pair is 1, and the statement is false if it is 0. Similarly, a fuzzy subset F of a set S can be defined as a set of ordered pairs, each with the first element from S, and the second element from the interval [0,1], with exactly one ordered pair present for each element of S. This defines a mapping between elements of the set S and values in the interval [0,1]. The value zero is used to represent
• 2. complete non-membership, the value one is used to represent complete membership, and values in between are used to represent intermediate DEGREES OF MEMBERSHIP. The set S is referred to as the UNIVERSE OF DISCOURSE for the fuzzy subset F. Frequently, the mapping is described as a function, the MEMBERSHIP FUNCTION of F. The degree to which the statement x is in F is true is determined by finding the ordered pair whose first element is x. The DEGREE OF TRUTH of the statement is the second element of the ordered pair. In practice, the terms "membership function" and fuzzy subset get used interchangeably. That's a lot of mathematical baggage, so here's an example. Let's talk about people and "tallness". In this case the set S (the universe of discourse) is the set of people. Let's define a fuzzy subset TALL, which will answer the question "to what degree is person x tall?" Zadeh describes TALL as a LINGUISTIC VARIABLE, which represents our cognitive category of "tallness". To each person in the universe of discourse, we have to assign a degree of membership in the fuzzy subset TALL. The easiest way to do this is with a membership function based on the person's height. tall(x) = { 0, if height(x) < 5 ft., (height(x)-5ft.)/2ft., if 5 ft. <= height (x) <= 7 ft., 1, if height(x) > 7 ft. } A graph of this looks like: 1.0 + +------------------- | / | / 0.5 + / | / | / 0.0 +-------------+-----+------------------- | | 5.0 7.0 height, ft. -> Given this definition, here are some example values: Person Height degree of tallness
• 3. -------------------------------------- Billy 3' 2" 0.00 [I think] Yoke 5' 5" 0.21 Drew 5' 9" 0.38 Erik 5' 10" 0.42 Mark 6' 1" 0.54 Kareem 7' 2" 1.00 [depends on who you ask] Expressions like "A is X" can be interpreted as degrees of truth, e.g., "Drew is TALL" = 0.38. Note: Membership functions used in most applications almost never have as simple a shape as tall(x). At minimum, they tend to be triangles pointing up, and they can be much more complex than that. Also, the discussion characterizes membership functions as if they always are based on a single criterion, but this isn't always the case, although it is quite common. One could, for example, want to have the membership function for TALL depend on both a person's height and their age (he's tall for his age). This is perfectly legitimate, and occasionally used in practice. It's referred to as a two-dimensional membership function, or a "fuzzy relation". It's also possible to have even more criteria, or to have the membership function depend on elements from two completely different universes of discourse. Logic Operations:-> Now that we know what a statement like "X is LOW" means in fuzzy logic, how do we interpret a statement like X is LOW and Y is HIGH or (not Z is MEDIUM) The standard definitions in fuzzy logic are: truth (not x) = 1.0 - truth (x) truth (x and y) = minimum (truth(x), truth(y)) truth (x or y) = maximum (truth(x), truth(y)) Some researchers in fuzzy logic have explored the use of other interpretations of the AND and OR operations, but the definition for the NOT operation seems to be safe. Note that if you plug just the values zero and one into these definitions, you get the same truth tables as you would expect from
• 4. conventional Boolean logic. This is known as the EXTENSION PRINCIPLE, which states that the classical results of Boolean logic are recovered from fuzzy logic operations when all fuzzy membership grades are restricted to the traditional set {0, 1}. This effectively establishes fuzzy subsets and logic as a true generalization of classical set theory and logic. In fact, by this reasoning all crisp (traditional) subsets ARE fuzzy subsets of this very special type; and there is no conflict between fuzzy and crisp methods. Some examples:-> assume the same definition of TALL as above, and in addition, assume that we have a fuzzy subset OLD defined by the membership function: old (x) = { 0, if age(x) < 18 yr. (age(x)-18 yr.)/42 yr., if 18 yr. <= age(x) <= 60 yr. 1, if age(x) > 60 yr. } And for compactness, let a = X is TALL and X is OLD b = X is TALL or X is OLD c = not (X is TALL) Then we can compute the following values. height age X is TALL X is OLD a b c ---------------------------------------------------------- used of fuzzy logic :-> Fuzzy logic is used directly in very few applications. The Sony PalmTop apparently uses a fuzzy logic decision tree algorithm to perform handwritten (well, computer lightpen) Kanji character recognition. A fuzzy expert system:-> A fuzzy expert system is an expert system that uses a collection of fuzzy membership functions and rules, instead of Boolean logic, to reason about data. The rules in a fuzzy expert system are usually of a form similar to the following: if x is low and y is high then z = medium
• 5. where x and y are input variables (names for know data values), z is an output variable (a name for a data value to be computed), low is a membership function (fuzzy subset) defined on x, high is a membership function defined on y, and medium is a membership function defined on z. The antecedent (the rule's premise) describes to what degree the rule applies, while the conclusion (the rule's consequent) assigns a membership function to each of one or more output variables. Most tools for working with fuzzy expert systems allow more than one conclusion per rule. The set of rules in a fuzzy expert system is known as the rulebase or knowledge base. The general inference process proceeds in three (or four) steps. 1. Under FUZZIFICATION, the membership functions defined on the input variables are applied to their actual values, to determine the degree of truth for each rule premise. 2. Under INFERENCE, the truth value for the premise of each rule is computed, and applied to the conclusion part of each rule. This results in one fuzzy subset to be assigned to each output variable for each rule. Usually only MIN or PRODUCT are used as inference rules. In MIN inferencing, the output membership function is clipped off at a height corresponding to the rule premise's computed degree of truth (fuzzy logic AND). In PRODUCT inferencing, the output membership function is scaled by the rule premise's computed degree of truth. 3. Under COMPOSITION, all of the fuzzy subsets assigned to each output variable are combined together to form a single fuzzy subset for each output variable. Again, usually MAX or SUM are used. In MAX composition, the combined output fuzzy subset is constructed by taking the pointwise maximum over all of the fuzzy subsets assigned tovariable by the inference rule (fuzzy logic OR). In SUM composition, the combined output fuzzy subset is constructed by taking the pointwise sum over all of the fuzzy subsets assigned to the output variable by the inference rule.
• 6. 4. Finally is the (optional) DEFUZZIFICATION, which is used when it is useful to convert the fuzzy output set to a crisp number. There are more defuzzification methods than you can shake a stick at (at least 30). Two of the more common techniques are the CENTROID and MAXIMUM methods. In the CENTROID method, the crisp value of the output variable is computed by finding the variable value of the center of gravity of the membership function for the fuzzy value. In the MAXIMUM method, one of the variable values at which the fuzzy subset has its maximum truth value is chosen as the crisp value for the output variable. Extended Example: Assume that the variables x, y, and z all take on values in the interval [0,10], and that the following membership functions and rules are defined: low(t) = 1 - ( t / 10 ) high(t) = t / 10 rule 1: if x is low and y is low then z is high rule 2: if x is low and y is high then z is low rule 3: if x is high and y is low then z is low rule 4: if x is high and y is high then z is high Notice that instead of assigning a single value to the output variable z, each rule assigns an entire fuzzy subset (low or high). Notes: 1. In this example, low(t)+high(t)=1.0 for all t. This is not required, but it is fairly common. 2. The value of t at which low(t) is maximum is the same as the value of t at which high(t) is minimum, and vice-versa. This is also not required, but fairly common. 3. The same membership functions are used for all variables. This isn't required, and is also *not* common.
• 7. In the fuzzification subprocess, the membership functions defined on the input variables are applied to their actual values, to determine the degree of truth for each rule premise. The degree of truth for a rule's premise is sometimes referred to as its ALPHA. If a rule's premise has a nonzero degree of truth (if the rule applies at all...) then the rule is said to FIRE. For example, x y low(x) high(x) low(y) high(y) alpha1 alpha2 alpha3 alpha4 ------------------------------------------------------------------------------ 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0 3.2 1.0 0.0 0.68 0.32 0.68 0.32 0.0 0.0 0.0 6.1 1.0 0.0 0.39 0.61 0.39 0.61 0.0 0.0 0.0 10.0 1.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 3.2 0.0 0.68 0.32 1.0 0.0 0.68 0.0 0.32 0.0 6.1 0.0 0.39 0.61 1.0 0.0 0.39 0.0 0.61 0.0 10.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 3.2 3.1 0.68 0.32 0.69 0.31 0.68 0.31 0.32 0.31 3.2 3.3 0.68 0.32 0.67 0.33 0.67 0.33 0.32 0.32 10.0 10.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 1.0 In the inference subprocess, the truth value for the premise of each rule is computed, and applied to the conclusion part of each rule. This results in one fuzzy subset to be assigned to each output variable for each rule. MIN and PRODUCT are two INFERENCE METHODS or INFERENCE RULES. In MIN inferencing, the output membership function is clipped off at a height corresponding to the rule premise's computed degree of truth. This
• 8. corresponds to the traditional interpretation of the fuzzy logic AND operation. In PRODUCT inferencing, the output membership function is scaled by the rule premise's computed degree of truth. For example, let's look at rule 1 for x = 0.0 and y = 3.2. As shown in the table above, the premise degree of truth works out to 0.68. For this rule, MIN inferencing will assign z the fuzzy subset defined by the membership function: rule1(z) = { z / 10, if z <= 6.8 0.68, if z >= 6.8 } For the same conditions, PRODUCT inferencing will assign z the fuzzy subset defined by the membership function: rule1(z) = 0.68 * high(z) = 0.068 * z Note: The terminology used here is slightly nonstandard. In most texts, the term "inference method" is used to mean the combination of the things referred to separately here as "inference" and "composition." Thus you'll see such terms as "MAX-MIN inference" and "SUM-PRODUCT inference" in the literature. They are the combination of MAX composition and MIN inference, or SUM composition and PRODUCT inference, respectively. You'll also see the reverse terms "MIN-MAX" and "PRODUCT-SUM" -- these mean the same things as the reverse order. It seems clearer to describe the two processes separately. In the composition subprocess, all of the fuzzy subsets assigned to each output variable are combined together to form a single fuzzy subset for each output variable. MAX composition and SUM composition are two COMPOSITION RULES. In MAX composition, the combined output fuzzy subset is constructed by taking the pointwise maximum over all of the fuzzy subsets assigned to the output variable by the inference rule. In SUM composition, the combined
• 9. output fuzzy subset is constructed by taking the pointwise sum over all of the fuzzy subsets assigned to the output variable by the inference rule. Note that this can result in truth values greater than one! For this reason, SUM composition is only used when it will be followed by a defuzzification method, such as the CENTROID method, that doesn't have a problem with this odd case. Otherwise SUM composition can be combined with normalization and is therefore a general purpose method again. For example, assume x = 0.0 and y = 3.2. MIN inferencing would assign the following four fuzzy subsets to z: rule1(z) = { z / 10, if z <= 6.8 0.68, if z >= 6.8 } rule2(z) = { 0.32, if z <= 6.8 1 - z / 10, if z >= 6.8 } rule3(z) = 0.0 rule4(z) = 0.0 MAX composition would result in the fuzzy subset: fuzzy(z) = { 0.32, if z <= 3.2 z / 10, if 3.2 <= z <= 6.8 0.68, if z >= 6.8 } PRODUCT inferencing would assign the following four fuzzy subsets to z: rule1(z) = 0.068 * z rule2(z) = 0.32 - 0.032 * z rule3(z) = 0.0 rule4(z) = 0.0 SUM composition would result in the fuzzy subset: fuzzy(z) = 0.32 + 0.036 * z Sometimes it is useful to just examine the fuzzy subsets that are the result of the composition process, but more often, this FUZZY VALUE needs to be converted to a single number -- a CRISP VALUE. This is what the defuzzification subprocess does.
• 10. fuzzy numbers and fuzzy arithmetic:-> Fuzzy numbers are fuzzy subsets of the real line. They have a peak or plateau with membership grade 1, over which the members of the universe are completely in the set. The membership function is increasing towards the peak and decreasing away from it. Fuzzy numbers are used very widely in fuzzy control applications. A typical case is the triangular fuzzy number 1.0 + + | / | / 0.5 + / | / | / 0.0 +-------------+-----+-----+-------------- | | | 5.0 7.0 9.0 which is one form of the fuzzy number 7. Slope and trapezoidal functions are also used, as are exponential curves similar to Gaussian probability densities. There are more defuzzification methods than you can shake a stick at. A couple of years ago, Mizumoto did a short paper that compared about ten defuzzification methods. Two of the more common techniques are the CENTROID and MAXIMUM methods. In the CENTROID method, the crisp value of the output variable is computed by finding the variable value of the center of gravity of the membership function for the fuzzy value. In the MAXIMUM method, one of the variable values at which the fuzzy subset has its maximum truth value is chosen as the crisp value for the output variable. There are several variations of the MAXIMUM method that differ only in what they do when there is more than one variable value at which this maximum truth value occurs. One of these, the AVERAGE-OF-MAXIMA method, returns the average of the variable values at which the maximum truth value occurs.
• 11. For example, go back to our previous examples. Using MAX-MIN inferencing and AVERAGE-OF-MAXIMA defuzzification results in a crisp value of 8.4 for z. Using PRODUCT-SUM inferencing and CENTROID defuzzification results in a crisp value of 5.6 for z, as follows. Earlier on in the FAQ, we state that all variables (including z) take on values in the range [0, 10]. To compute the centroid of the function f(x), you divide the moment of the function by the area of the function. To compute the moment of f(x), you compute the integral of x*f(x) dx, and to compute the area of f(x), you compute the integral of f(x) dx. In this case, we would compute the area as integral from 0 to 10 of (0.32+0.036*z) dz, which is (0.32 * 10 + 0.018*100) = (3.2 + 1.8) = 5.0 and the moment as the integral from 0 to 10 of (0.32*z+0.036*z*z) dz, which is (0.16 * 10 * 10 + 0.012 * 10 * 10 * 10) = (16 + 12) = 28 Finally, the centroid is 28/5 or 5.6. Note: Sometimes the composition and defuzzification processes are combined, taking advantage of mathematical relationships that simplify the process of computing the final output variable values. The Mizumoto reference is probably "Improvement Methods of Fuzzy Controls", in Proceedings of the 3rd IFSA Congress, pages 60-62, 1989. ===================================================== =========== Used of fuzzy expert systems :-> To date, fuzzy expert systems are the most common use of fuzzy logic. They