This is documentation for an obsolete product.
Current products and services

 Documentation /  Fuzzy Logic /  Manual /

CompositionsFuzzy Arithmetic

1.8 Fuzzy Inferencing

1.8.1 Introduction

Fuzzy Logic provides three different functions for performing fuzzy inferencing. The inferencing functions are a little more involved than the other functions in this package, and consequently they need a little more setup. In this chapter, we demonstrate how to set up and use the inferencing functions.

This loads the package.


1.8.2 Inference Functions

Functions for fuzzy inferencing.

Option for RuleBasedInference.

1.8.3 Composition-Based Inference

The CompositionBasedInference function works for single-input/single-output systems. To use the CompositionBasedInference function, a fuzzy relation must be created which models a system's input-output response. The fuzzy inference function then takes a fuzzy set as input and performs a composition to arrive at the output. What follows is a description of what is needed to perform a CompositionBasedInference and a demonstration of the inferencing operation.

Defining Inputs

To create the fuzzy relation needed to perform a CompositionBasedInference, we first need to define our collection of input fuzzy sets. Each fuzzy set used to define the collection of input fuzzy sets can be created individually using one of the techniques discussed in the Chapter 1.1 Creating Fuzzy Sets, or the entire collection of fuzzy sets can be created all at once using the CreateFuzzySets function as shown here. We look at our input fuzzy sets with the FuzzyPlot function.



In this example, we have created five fuzzy sets which are named NegBig, NegSmall, Zero, PosSmall, and PosBig. Notice that these fuzzy sets are labeled with linguistic terms that describe the input's universal space.

Defining Outputs

With the input membership functions defined, we must create a set of output fuzzy sets. We again use the CreateFuzzySets function for convenience.



Defining Rules

The final item we need to create the fuzzy relation that will define our system model is a set of rules relating the input conditions to the output responses. These rules are formed as a list of if-then pairs, where the input condition is the first element of the pair, and the output response is the second element. Here is an example of a set of rules for the input and output we defined above.


The rules shown above constitute an if-then pair. For example, the first rule, {NegBig, PBO}, would be translated as follows:

    If the input is NegBig (Negative Big), then the output should be PBO (Positive Big).


In general, there can be a rule corresponding to each input membership function, but there should not be more than one rule for any one input condition.

Building the Model

To create the fuzzy relation that will serve as our fuzzy model, we call the BuildModel function with a set of rules. The BuildModel function creates a fuzzy relation that can serve as a system model. This function works by applying the SetsToRelation function to each of the rule pairs and performing a union with the resulting fuzzy relations to form one universal relation describing the set of rules. Let's create a fuzzy model to represent our system. We can view the fuzzy model we created with the FuzzySurfacePlot function.



Note that the input and output fuzzy sets to which the rules refer must have been created prior to using the BuildModel function.


To perform a fuzzy inference using the model just created, we need to provide a fuzzy set input. The universal space of our input fuzzy set must be equal to the universal space of the input used to build the model. Here we create a fuzzy set that will serve as input to the inferencing function.



Now we can use the CompositionBasedInference function to evaluate the model response to the input.

CompositionBasedInference[A, B] returns a fuzzy set that is the result of performing a MaxMin composition-based inference, where A is the input fuzzy set, and B is the model fuzzy relation. The output fuzzy set can be defuzzified using either the CenterOfArea or MeanOfMax function. Here we use the MeanOfMax defuzzification to find a crisp output for our inferencing operation.


For this example, we see that for an input fuzzy set centered around 5, we receive an output response of 7.5.

1.8.4 Rule-Based Inference

The RuleBasedInference functions work with two-input/one-output systems and with multiple-input/one-output systems. The following is a description of what is needed to perform a RuleBasedInference and a demonstration of the inferencing operation using a two-input/one-output system.

Defining Inputs

As with the CompositionBasedInference, the first thing we need to do to perform a RuleBasedInference is define our input fuzzy sets. Unlike the CompositionBasedInference, we need to create two sets of input fuzzy sets. We again use the CreateFuzzySets function to define our input fuzzy sets, and we use the FuzzyPlot function to look at the fuzzy sets.





Notice how we divided our two inputs into different numbers of membership functions. The choice for the number of membership functions used to define an input is entirely up to the designer. Notice also that the names of the membership functions are different. It is important that all of the input and output membership functions have distinct names for the inferencing to work correctly.

Defining Outputs

Again we need to define a collection of output fuzzy sets. We define these just as we did the input, making sure that we use distinct names for the individual fuzzy sets.



Defining Rules

The final piece needed to perform a RuleBasedInference is a list of rules. The RuleBasedInference function expects the rules to be a list of triplets. The first two items in the triplet correspond to the input conditions, and the third item corresponds to the output. Here is an example.


The list of rules we just created can again be interpreted as an if-then statement. For example, the first rule, {LE, RB, PS}, could be interpreted in the following manner:

    If the FirstInput is LE and the SecondInput is RB, then TheOutput response should be PS.

The order of the inputs should be the same throughout the list because the order does matter when performing the fuzzy inference.


RuleBasedInference[{A1, ... , An}, {B1, ... ,Bn}, {C1, ... ,Cn}, {{Ai, Bj, Ck}, ...}, a, b] returns a fuzzy set that is the result of performing a rule based inference Mamdani (MaxMin) type, where {A1, ... , An} and {B1, ... , Bn} represent the collections of two input membership functions; {C1, ... , Cn} represent the collection of output membership functions; the {Ai, Bj, Ck} triplets represent rules relating the two inputs to the one output; and a and b represent the crisp inputs. Here we use the CenterOfArea defuzzification to come up with a crisp output. Crisp inputs of 70 and 210 give a crisp output of -12.4138.


The RuleBasedInference example shown in this section contains the specifications for a fuzzy logic controller, which can be used to back a truck up to a loading dock. To see a complete simulation of the truck-backer example, see the FuzzyControl notebook.

The scaled inference is like the Mamdani except instead of clipping the output membership functions, the output membership functions are scaled to have a height equivalent to the input fuzzification value. Here is an example.


The Model inference, instead of clipping the output membership functions, raises the membership function values to 1 for all elements of the output membership function greater than the input fuzzification value. Also, instead of Max-Union the Min-Intersection is taken for all of the output membership functions. Here is an example.


CompositionsFuzzy Arithmetic