# Fuzzy Rule Systems

This chapter presents a brief introduction to fuzzy rule system technology and its applications. This introduction is not meant as a comprehensive description of the technology or its applications. See the "Bibliography" for a list of articles and books on fuzzy logic, rule-based expert systems, and fuzzy rule systems.

## History

Fuzzy rule systems as implemented in the Able framework is a hybrid technology, taking the best parts of the well-known rule-based expert system methodology and the latest work in fuzzy sets and fuzzy logic.

Rule-based expert systems (or knowledge-based systems) were first developed in the late 1970's. The basic idea is that a software system can be built to solve problems using the "rules" followed by an expert in the field when solving a similar problem.

A rule-based system consists of three parts:

1. The knowledge-base comprised of a set of if-then rules generated by the expert or through consultations with the expert
2. A working memory or state which includes input data to the expert system as well as intermediate results
3. The inference engine that uses the working memory and the knowledge base to derive the answer

Expert systems have gone through the technology cycles from the early stage of extremely high expectations and hyperbole; to being somewhat discredited in the 1980's; and to increased respect and understanding of their capabilities in commercial software applications more recently.

The concept of fuzzy sets was first proposed by Dr. Lotfi Zadeh, then the head of the electrical engineering department at the University of California at Berkeley in 1965. There was a strong reaction from many scientists against fuzzy logic. Some of it was a reaction to the label, and in some sense it is unfortunate that Zadeh chose the term "fuzzy." Another valid description is multi-valued logic which does not carry the negative connotations of "fuzzy" in the English language.

Over the years, a large amount of scientific work has been done in the field of fuzzy set theory, fuzzy logic, and now fuzzy calculus. Like neural networks, workers in the field of fuzzy logic labored in relative obscurity for many years. In the late 1980's, several Japanese consumer appliance manufacturers began using fuzzy logic in their products. The market for fuzzy logic systems was estimated to be well over a billion dollars and is growing rapidly.

## Basics

In this section, we briefly review rule-based systems and fuzzy logic technologies individually and discuss how they are synergistically combined into the fuzzy rule systems provided in the Able framework.

#### Rule Systems

Rule-based systems are usually classified as either forward or backward chaining. In forward chaining systems such as OPS-5 and SOAR, the initial data is placed in the working memory, the rules are evaluated using a conflict resolution procedure, and one rule is selected to "fire." When the rule fires, the consequent or then part of the rule is processed, changing the working memory and starting another rule selection and processing cycle. In this way, the forward-chaining rule system works forward from the initial data to compute an answer.

In backward chaining systems, the solution or goal is specified as the initial condition. The inference engine then works backward through the rules, searching for values of the input variables which would satisfy the antecedent clauses (the if part) of the rules.

The major portion of the development of rule-based systems is the definition and construction of the rule-base. A prerequisite of an expert system is that an expert exists to create the rule-base. Quite often, there is not one "expert" but a set of experts. They may disagree about the rules, may have difficulty describing their decision-making process in rule form, and may be too busy (and valuable) doing their day-to-day jobs to take time out to help in the development of a rule-base. This phase of the rule-base development is called knowledge acquisition, and its practitioners are called knowledge engineers.

#### Fuzzy Sets

Dr. Zadeh's fuzzy sets are based on a simple extension of standard boolean sets. In order to understand fuzzy sets, on which fuzzy logic and fuzzy rules are built, you should first review standard set theory.

A set consists of a group of objects. An object is either in the set or not in the set. For example, you can have a set of tall people and a set of short people. Larry, Curly and Moe are tall people. Groucho, Zeppo, and Hippo are short.

        Set A = { Larry, Curly, Moe }

        Set B = { Groucho, Zeppo, Hippo }

You can define membership functions for the six people mentioned previously:

        member(A,Curly) = 1      (Curly is in set A)

        member(B,Curly) = 0      (Curly is not in set B)

Similarly, you can define truth values for other people. In order to be logical, you need to have a rule to determine who is tall and who is short. Your rule will be:

        Anyone over 6 feet in height is tall.

Figure 22. Boolean Truth Values for Height

Now classify a new person, Shemp, who is exactly 6 feet tall. Does he belong in the tall set, A, or in the short set, B? Your rule says tall people are "over" 6 feet, so Shemp is in the short set B. This is completely arbitrary, but, with boolean logic, a decision must be made either one way or the other but not both.

One possible solution is to divide the population into more than two sets: very-short people, sort-of-short people, kind-of-short people, and short people. Also, a single person can be a member of more than one set. However, the basic point remains the same. A binary decision must be made for each set: is Shemp a member or not?

This example illustrates a major weakness of boolean logic. Every element either is, or is not, a member of a given set. However, there are instances where black and white classifications cannot be made, and in those cases boolean logic is not sufficient to represent real-world data. If you use boolean logic with 'gray' data, you may not achieve the desired results.

In Fuzzy sets, Zadeh introduced the idea that an object can have partial membership in a set. At the extremes, fuzzy logic is equivalent to boolean logic. For example, someone 4 feet tall has a membership value of 0 in the fuzzy tall set. Another person who is 7 feet tall has a membership value of 1 in the fuzzy tall set. Compare the fuzzy set membership function in Figure 23 to the boolean logic membership function shown in Figure 22.

Figure 23. Fuzzy Truth Set for Tallness

How about your 6 foot person Shemp? He could have a membership value of 0.75 in the fuzzy tall set as shown in Figure 23. His membership in the fuzzy short set (not shown graphically), could have a value of 0.2. In fuzzy logic, he does not have to be A or B, tall or short, one or the other. Shemp can be a member of the fuzzy set A to some degree ranging from 0 to 1.

This is the basic difference between boolean sets and fuzzy sets. Instead of A AND not-A = &phi., fuzzy set theory says that A AND not-A <> &phi.. Or, a glass may be both half empty, and half full.

#### Fuzzy Logic

Building from the basic fuzzy set theory, Zadeh also defined new logical operators to work on fuzzy sets. And so, fuzzy logic was born.

In standard set theory you can select common elements of two sets with the intersection, or AND, operator; in fuzzy set theory, this is usually performed by taking the MIN operator on paired elements of both sets.

In standard set theory, you can take the union, or OR, of two sets; in fuzzy set theory, this is usually taken as the MAX of the paired elements of the sets.

There is also a fuzzy complement operation, which is usually computed as 1 - x. So, if x has a membership value of 0.5, then its fuzzy complement, not x, is 0.5 also. Using fuzzy logic, the glass is half empty AND half full!

One of the chief advantages of fuzzy logic is that it maps well to an intuitive understanding of the real-world data. To classify the population by height into two sets, tall and short, the following boolean rule could be used:

        IF a > 6 feet THEN a is tall ELSE a is short

Instead of a boolean rule, a fuzzy rule as shown in Figure 23, could be used to define the set of tall people.

Modifiers, called linguistic hedges, can be used to change the membership values of the object. These modifiers in this case could be sort-of tall, moderately tall, and extremely tall. A 4 foot person is not tall, and so the member (4 feet, tall) = 0. However, a 7 foot person is extremely tall, and would have a membership value of 1.0. A 5 foot 6 inch person is sort-of tall with a membership value of 0.4. A 6 foot person is moderately tall with a membership value of 0.75.

A fuzzy membership function can also be thought of as survey results. If a number of people were asked if a 4 foot person was tall, and each said no, a membership value of zero would result. If the same people were asked if a 6 foot person was tall, and seventy-five percent said yes, that would define a membership value of 0.75.

Defining the shape of the membership function maps an intuitive understanding of real-world data to the mathematical functional view used by fuzzy membership functions. There is nothing imprecise or fuzzy about fuzzy logic. Fuzzy logic is simply plain mathematics.

#### Fuzzy Rule Systems

One of the prime success areas of work in artificial intelligence (AI) has been in the form of rule-based expert systems. Expert systems consist of three parts:

1. A set of if-then rules called the knowledge base
2. A program which processes the rules called an inference engine
3. A working memory area used to store data and information about the current state

Many expert systems have been built in a variety of application areas. One of the problems associated with rule-based systems is that the number of rules can quickly grow very large. Rule-based expert systems rely on boolean logic. A rule is either true or false. If it is true, you will perform the THEN part. However, what if the rule is only partially true? Researchers in AI tackled this problem by using confidence or certainty factors. Thus values in some expert systems have not only a current value, but also have a corresponding certainty of the correctness of the value.

Fuzzy rule processing combines fuzzy sets and fuzzy logic with the rule-based framework, yielding a more natural approach to handling uncertainty in rule-based systems. A rule is more-or-less true based on the values of the fuzzy variables and their membership functions. For example, if you had a fuzzy rule set to control an air conditioner, you might have the following fuzzy rule set (based on an example in Bart Kosko's book Fuzzy Thinking):

1. If temperature is cold then motor is stopped.
2. If temperature is cool then motor speed is slow.
3. If temperature is just right then motor speed is medium.
4. If temperature is warm then motor speed is fast.
5. If temperature is hot then motor speed blasts.

This example has two fuzzy variables, temperature and motor speed. For each fuzzy variable, you can define one or more fuzzy subsets. For example, five fuzzy sets on temperature are cold, cool, just right, warm, and hot. In order to map from these linguistic fuzzy rules into mathematics, you need to define the membership functions for each of the fuzzy sets you use.

Figure 24 diagrams the fuzzy membership functions defined for the temperature variable fuzzy sets. They are shaped either as triangles or as half triangles. Any functional form with a output range of 0 to 1 can be used. Triangles or trapezoids are most common.

Figure 24. Membership Functions for Temperature Variable Fuzzy Sets

Once the fuzzy rule set and the associated membership functions are defined, a fuzzy inference engine is used to process data using three basic steps.

First, the raw input value (temperature) is mapped onto a range of 0 to 1 using the fuzzy membership functions.

Next, each of the rules are executed (or fired, in AI terminology) in parallel; each producing a single truth value ranging from 0 to 1. There is no notion of search (or backward or forward chaining) in fuzzy inference engines. Because all of the rules are evaluated in parallel, fuzzy inference engines can be implemented in parallel hardware, providing extremely fast performance. Also, since the fuzzy AND and OR operators are implemented using the mathematical MIN and MAX functions, they are simple and fast.

Finally, the output value is determined by selecting the MAX of all of the rule outputs (since the rules are joined using a fuzzy OR). Using a process called defuzzification, the output value is converted back to a "crisp" output value that has meaning in the external world. In the air conditioner example, a fuzzy output value of 0.5 might be translated back into the slow fan motor speed.

## Capabilities

Fuzzy rule systems offer great promise in letting non-experts develop applications using their own language. To date, most fuzzy logic applications have been in the embedded control area, with uses in: cameras and camcorders (autofocus, reduced jitter); air conditioners (improved temperature control); cars (anti-lock brakes, engine control); subway trains (smoother starts and stops); and elevators (reduced waiting time). People are now starting to apply fuzzy logic to business applications such as decision support. Many rule-based, expert-system applications could be replaced by fuzzy rule systems. Proponents of fuzzy rule systems claim that equivalent fuzzy rule systems use fewer rules than traditional expert systems.

According to experienced fuzzy logic practitioners, generating the fuzzy rule set is usually the easiest part of the process. Mapping the fuzzy sets to membership functions is considered the hardest part of developing working fuzzy rule systems. Researchers have turned to neural networks to learn the appropriate membership functions, and the Neural Network Utility provides this capability.

#### Fuzzy Variables

Fuzzy variables are used in if-then statements that are used to represent the fuzzy rules. These variables are defined as needed by your application. For example, in a decision-support application, you may have a variable named RISK which measures the relative uncertainty of a decision.

Variables are either continuous or discrete. Continuous variables have values distributed over a specified range of real numbers. Discrete variables can take only a finite set of values, and can be either numeric or symbolic. For example, the variable RISK may take values LOW, MEDIUM, and HIGH.

Defining a fuzzy variable consists of the following steps:

1. Name the fuzzy variable.
2. Specify the fuzzy variable input/output attributes.
3. Specify the fuzzy variable type (discrete or continuous).
4. If discrete, specify the number of discrete values or provide a list of symbolic values.
5. If continuous, specify the range (minimum and maximum) of the variable.

#### Fuzzy Sets

Each continuous fuzzy variable must have one or more fuzzy sets associated with it. Fuzzy sets are defined as linguistic terms relating to the values of a fuzzy variable. To define a fuzzy set specify:

1. The fuzzy set name.
2. The fuzzy variable name.
3. The type of membership function, which may be:

- Trapezoidal (four point form)
- Segmented (piecewise; a set of points joined by line segments)

A Trapezoidal fuzzy set requires four parameters: the left support, left core, right core, and right support. Trapezoidal fuzzy sets can define membership functions with rectangular, triangular, or trapezoidal shapes as shown in Figure 25.

Figure 25. Trapezoidal Membership Function Examples

| Left Support | Left Core | Right Core | Right Support
Trapezoid | 0 | 1 | 2 | 4
Triangle | 3 | 5 | 5 | 8
Rectangle | 7 | 7 | 10 | 10

A Segmented fuzzy set is defined by a list of points; each point is a value of the variable followed by the degree of membership at that value. The degree of membership must be between zero and one. The first and last points must have zero degree of membership, and the values must be listed in an increasing sequence.

For example, the crisp set of numbers with values between 0 and 2, inclusive, can be represented piecewise as (0,0), (0,1), (2,1), and (2,0). A definition of a fuzzy set membership function for "tallness" might be represented as (0,0), (5,0), (6,0.75), (7,1), (8,1), and (8,0). You could interpret the 0.75 value for membership at a height of six feet as "Seventy-five percent of people consider a six foot person to be tall." The set arbitrarily ends at eight as a practical upper limit to human height.

Figure 26. Segmented Membership Function Examples

The integer example in Figure 26 shows "steps" at values of 0 and 2. When a "step" is required in the membership function, you supply two points for the coordinate where the step occurs. The point with lesser degree of membership represents the limit of membership degrees as the values approach the coordinate from below (for a rising step) or above (for a descending step). The point with greater degree of membership is the actual degree of membership at the value where the step occurs.

#### Fuzzy Rules

Once you have defined the fuzzy variables and their associated fuzzy sets, you can create a fuzzy rule-base. To do this, you provide:

1. The rule-base settings, also called computational options
2. The set of rules

Here is an example of a fuzzy rule:

        if FuzzyVar1 is LOW and FuzzyVar2 is HIGH then Answer is MEDIUM

Each fuzzy rule must have an antecedent or if part, consisting of one or more fuzzy clauses, and a single consequent or then part. In the example rule above, FuzzyVar1, FuzzyVar2, and Answer are variables, and LOW, MEDIUM, HIGH are fuzzy sets defined on the respective variables. LOW, MEDIUM, and HIGH could also be symbolic values of a discrete variable, in which case they are treated as singleton sets where the membership value is 1 at the stated value and 0 elsewhere. 'FuzzyVar1 is LOW', 'FuzzyVar2 is HIGH', and 'Answer is MEDIUM' are fuzzy clauses.

If multiple clauses are used in the antecedent, they must be joined by an AND keyword. The maximum number of antecedent clauses in a single rule is 10. OR is not used to join clauses; use multiple rules with the same consequent to represent this situation.

There may be more than one clause in the antecedent but only a single clause in the consequent of a rule. Several variables may appear in consequence of rules in a rule-base, allowing rules to be chained together to enforce a multiple-step inference. Antecedents, in general, deal with the same variables, but not all antecedent variables need to be used in each rule. Ordering of rules in a rule base is not critical.

Rules may have weights associated with them. The fuzzy set outputs of each AND-gate are further scaled by the rule weights before being summed in the OR-gate. Weights must be between 0.0 and 1.0 inclusive. If a weight is not given explicitly for a rule, the weight is 1.0 by default. However, weights are required if sum is specified as the computational option for the OR-gate rulebase parameter. See the description of the Rulebase statement on page reference #6 for more information on computational options.

#### Creating a Fuzzy Rule-Base

Here is an example of a fuzzy rule-base. For a complete description of the language elements, refer to "Fuzzy Rule-Base Language Definition".

    variable PROFIT inout continuous 0 to 100

    variable CAPITAL inout continuous 0 to 1

    variable INTEREST inout continuous 0 to 1

    variable DEBT inout continuous 0 to 1

    variable RATING out continuous 0 to 1

    variable SYMRATING out discrete (A  AA  AAA)

    fuzzyset HIGH of RATING segments (0.6 0, 1 1, 1 0)

    fuzzyset MEDIUM of RATING trapezoid (0.3 0.5 0.5 0.6)

    fuzzyset LOW of RATING segments (0 0, 0 1, 0.4 0)

    fuzzyset HIGH of DEBT segments (0.4 0, 1 1, 1 0)

    fuzzyset LOW of DEBT segments (0 0, 0 1, 0.6 0)

    fuzzyset HIGH of INTEREST segments (0.4 0, 1 1, 1 0)

    fuzzyset LOW of INTEREST segments (0 0, 0 1, 0.6 0)

    fuzzyset SMALL of CAPITAL segments (0 0, 0 1, 0.6 0)

    fuzzyset LARGE of CAPITAL segments (0.4 0, 1 1, 1 0)

    fuzzyset SMALL of PROFIT segments (0 0, 0 1, 13 0)

    fuzzyset MEDIUM of PROFIT trapezoid (0 13 13 100)

    fuzzyset LARGE of PROFIT segments (13 0, 100 1, 100 0)

    fuzzy_rule_base BONDRATING ( andgate=min ,  orgate=sum )

    begin

      if PROFIT is LARGE then RATING is HIGH

      if PROFIT is MEDIUM then RATING is MEDIUM

      if PROFIT is SMALL then RATING is LOW

      if CAPITAL is LARGE then RATING is HIGH weight 0.3

      if CAPITAL is SMALL then RATING is LOW weight 0.2

      if INTEREST is HIGH then RATING is HIGH weight 0.2

      if INTEREST is LOW then RATING is LOW weight 0.2

      if DEBT is LOW then RATING is HIGH weight 0.2

      if DEBT is HIGH then RATING is LOW weight 0.2

      if RATING is LOW then SYMRATING is A

      if RATING is MEDIUM then SYMRATING is AA

      if RATING is HIGH then SYMRATING is AAA

    end

Fuzzy Inference Engine Processing

A fuzzy rule-base is processed by supplying it with a value for each of the fuzzy variables specified as input or input/output. The input to a rule-base is a vector of input values. Input values for continuous variables are real numbers. For discrete variables, the input values may be either the symbolic value or an integer which is the index into the discrete set.

Each if-then rule of the rule base defines a fuzzy AND-gate. The membership values of the inputs in their corresponding antecedent fuzzy sets are "AND-ed" together and this result is used to scale the fuzzy set of the consequent clause. This scaled fuzzy set is the output of the rule.

The output of each rule that references the same variable in its consequent then goes into a fuzzy OR-gate. The fuzzy set outputs are "OR-ed" together to construct the output of the entire rule-base for that particular output variable and a particular set of inputs. This output can be left fuzzy if it is a temporary consequent variable which is referenced in the antecedent clauses of other rules. If it is an output variable, it must be defuzzified, that is, translated into a real number or discrete set member.

The fuzzy inference engine manages the processing of related rules which have the same consequent variable and insures that the rule blocks are computed in the correct order. If circular references exist in the rule set such that an output variable cannot be computed, then an error is returned by the fuzzy inference engine.

Topics Index APIs