Main Content

Build FIS Tree Using Fuzzy Logic Designer

Since R2023b

This example shows how to interactively construct a FIS tree using the Fuzzy Logic Designer app. For more information on FIS trees, see FIS Trees.

For this example you create a FIS tree that computes a tip percentage based on the following inputs.

  • Rating of food quality on a scale of 0 to 10, where 0 is poor and 10 is excellent

  • Rating of service quality on a scale of 0 to 10, where 0 is poor and 10 is excellent

  • Relative weight factor from 0 to 1, where a lower value indicates a higher service priority and a higher value indicates a higher food priority

To create a FIS tree, you create multiple FIS objects and connect them in hierarchical tree structure. Then, you configure each FIS object as shown in Build Fuzzy Systems Using Fuzzy Logic Designer.

In this example, you build the FIS tree from scratch. Alternatively, you can load the final FIS tree using the following commands.

load("weightedTipper")
fuzzyLogicDesigner(weightedTipper)

Define FIS Tree Structure

For this example, you create a FIS tree that contains three FIS objects:

  • foodFIS — Compute an adjusted food rating based on the food quality and the relative weight.

  • serviceFIS — Compute an adjusted service rating based on the service quality and the relative weight.

  • tipFIS — Compute a tip percentage based on the ratings computed by the other FIS objects.

Open Fuzzy Logic Designer. On the Apps tab, under Control System Design and Analysis, click the app icon.

The app opens a Getting Started dialog box. For more information on the options for creating your initial FIS structure, see Get Started Using Fuzzy Logic Designer.

Since you define the rules for your FIS tree manually, clear the Generate rules automatically check box.

Since you are creating a FIS tree with three FIS objects, under General Fuzzy Inference Systems, select Custom FIS.

Getting Started dialog - In the top-right corner, the Generate rules automatically parameter is cleared. The Mamdani Type-1 template is highlighted.

In the Custom System dialog box:

  • Under System type, select FIS Tree.

  • In the Name field, enter weightedTipper

  • Under Number of FISs, select 3.

Custom System dialog box, showing configuration for a FIS tree containing three FIS objects.

Click OK.

The app creates and loads the initial FIS tree.

Initial Fuzzy Logic Designer view, showing three unconnected FIS objects, each with two inputs and one output.

Specify names for the FIS objects. In the System Browser pane, click FIS.

System Browser, showing the FIS element as selected.

In the Property Editor pane, specify the following FIS names.

  • Rename fis1 to foodFIS.

  • Rename fis2 to serviceFIS.

  • Rename fis3 to tipFIS.

Property Editor, showing table with names and input/output counts for each FIS.

Configure FIS Tree Connections

Once you create your FIS objects, you must define the connections between them.

In the System Browser, click weightedTipper.

To add a connection, on the Design tab, in the Add Components gallery, click Connection.

Design tab showing Connection option and System browser showing weightedTipper selection.

The app adds a default connection to the FIS tree.

In the Property Editor, configure the connection from the output of foodFIS to the first input of tipFIS.

  • In the From section:

    • Under FIS, select foodFIS.

    • Under Output, select output1.

  • In the To section:

    • Under FIS, select tipFIS.

    • Under Input, select input1.

Design tab showing Connection option and System browser showing weightedTipper selection.

Click Apply. If you make a mistake, undo the connection change by clicking Revert.

The FIS Tree Plot document shows the updated FIS connection.

FIS Tree Plot document showing a highlighted connection from foodFIS to tipFIS.

Similarly, create a connection from the output of serviceFIS to the second input of tipFIS.

On the left, the FIS Tree Plot document shows the highlighted connection from serviceFIS to tipFIS. On the right, the Property Editor shows the connection details.

Since both foodFIS and serviceFIS use the same weight factor as an input, create a connection between the second input of foodFIS and the second input of serviceFIS.

On the left, the FIS Tree Plot document shows the highlighted connection between the inputs of foodFIS and serviceFIS. On the right, the Property Editor shows the connection details.

Since these two FIS inputs are connected, the FIS tree now has three inputs.

Configure FIS Tree Outputs

In the System Browser, under weightedTipper, select Outputs. The Property Editor shows the output configuration of the FIS tree.

Property Editor showing the tree output configuration, with free outputs in the top table and connected outputs in the bottom table.

The FIS tree has one free output, the output of tipFIS, and two connected outputs, the outputs of the other FIS objects. You can configure any of these outputs as an output of the FIS tree.

  • To ignore a free output and not use it as a FIS tree output, in the Free Outputs table, select the corresponding entry in the Unused Output column.

  • To use a connected output as an output of the FIS tree, in the Connected Outputs table, select the corresponding entry in the Intermediate Output column.

By default, the outputs of foodFIS and serviceFIS are configured as FIS tree outputs. Since the goal of the FIS tree is to compute the tip and not intermediate food and service ratings, clear the Intermediate Output entries for the foodFIS and serviceFIS outputs.

Connected Outputs table with both entries in the Intermediate Outputs column cleared.

Click Apply.

Design Food FIS

After defining the FIS tree structure, you can design each of the component FIS objects, starting with foodFIS. For more information on configuring a FIS, see Build Fuzzy Systems Using Fuzzy Logic Designer.

Configure Input Variables

foodFIS has two input variables, one for the food quality and one for the relative weight factor.

Configure the food quality input of foodFIS. In the System Browser, select the first input of foodFIS. Then, in the Property Editor, specify:

  • The variable name as quality

  • The variable range as [0 10]

  • Three evenly distributed triangular membership functions (MFs):

    • poor — The food is poor.

    • average — The food average.

    • excellent — The food is excellent.

For more information on configuring MFs, see Define Membership Functions Using Fuzzy Logic Designer.

Food quality input configuration. On the right, the Property Editor shows the name, range, and membership details for the variable. In the middle, the Membership Function Editor document shows three evenly distributed triangular MFs, from left to right across the range, poor, average, and excellent.

Similarly, configure the relative weight input of foodFIS. In the System Browser, select the second input of foodFIS. Then, in the Property Editor, specify:

  • The variable name as weight

  • The variable range as [0 1]

  • Three evenly distributed triangular MFs:

    • serviceHIgh — Place a higher weight on service quality.

    • equal — Consider food and service quality equally.

    • foodHigh — Place a higher weight on food quality.

Weight input configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows three evenly distributed triangular MFs, from left to right across the range, serviceHigh, equal, and foodHigh.

Configure Output Variable

The output of foodFIS is an adjusted food rating based on the food quality and weight factor.

Configure the food rating output of foodFIS. In the System Browser, select the output of foodFIS. Then, in the Property Editor, specify:

  • The variable name as rating

  • The variable range as [0 10]

  • Five evenly distributed triangular MFs:

    • VL — Very low rating

    • L — Low rating

    • M — Medium rating

    • H — High rating

    • VH — Very high rating

Food rating output configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows five evenly distributed triangular MFs, from left to right across the range, VL, L, M, H, and VH.

When you evenly distribute MFs across the output variable range by clicking Evenly Distribute MFs, the VL and VH MFs are centered on ratings of 0 and 10, respectively. With this MF configuration, where VL and VH are not within the output variable range, the aggregation and defuzzification process never generates an output of either 0 or 10.

To expand the output range to include all five MFs, set the variable range to [-2.1 12.1].

Food rating output configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows five evenly distributed triangular MFs, from left to right across the range, VL, L, M, H, and VH.

Define Rules

To specify rules for foodFIS, in the System Browser, select foodFIS. Then, in the document area, select the Rule Editor. For more information on configuring rules, see Define Fuzzy Rules Using Fuzzy Logic Designer.

To define rules for foodFIS, consider the following:

  • If the food quality is average, then the food rating is medium, no matter the weight value.

  • Poor and excellent food quality produce low and high food ratings, respectively.

  • If the weight factor is serviceHigh, then the food quality has no impact on the tip. So, no matter the food quality value, the food rating is medium.

  • As the weight factor shifts toward foodHigh, the food quality has a greater impact on the food rating.

Given these considerations, define the following rules for foodFIS, where the quality and weight columns are combined using an AND operation.

qualityweightrating
serviceHighM
averageM
poorequalL
excellentequalH
poorfoodHighVL
excellentfoodHighVH

For more information on configuring rules, see Define Fuzzy Rules Using Fuzzy Logic Designer.

The final rule base is shown in the following figure.

Rule Editor showing six rules for foodFIS.

Analyze Control Surface

To validate the behavior of foodFIS, view its control surface. For more information on analyzing a FIS, see Analyze Fuzzy System Using Fuzzy Logic Designer.

In the System Browser, select foodFIS, then in the Simulation gallery, click Control Surface.

Control surface for foodFIS.

When weight is zero, changes in food quality do not affect the food rating. As the weight increases, changes in food quality have a greater impact on the food rating.

Design Service FIS

Design serviceFIS, which has a similar configuration to foodFIS.

Configure Variables

serviceFIS has the same input and output variables as foodFIS. Therefore, configure the input and output variables of serviceFIS using the same settings as the corresponding variables of foodFIS.

Define Rules

To specify rules for serviceFIS, in the System Browser, select serviceFIS. Then, in the document area, select the Rule Editor.

serviceFIS has the same general rule structure as foodFIS. The difference is in how the weight factor is processed.

Define the following rules for serviceFIS, where the quality and weight columns are combined using an AND operation.

qualityweightrating
foodHighM
averageM
poorequalL
excellentequalH
poorserviceHighVL
excellentserviceHighVH

The final rule base is shown in the following figure.

Rule Editor showing six rules for serviceFIS.

Analyze Control Surface

To validate the behavior of serviceFIS, view its control surface.

In the System Browser, select serviceFIS, then in the Simulation gallery, click Control Surface.

Control surface for serviceFIS.

This control surface is a mirror image of the control surface for foodFIS. When the weight is one, changes in service quality do not affect the service rating. As the weight decreases, changes in service quality have a greater impact on the service rating.

Design Tip FIS

The tipFIS system computes a tip percentage based on the food and service ratings foodFIs and serviceFIS, respectively.

Configure Input Variables

tipFIS has two input variables, one for each rating.

Configure the food rating input of tipFIS. In the System Browser, select the first input of tipFIS. Then, in the Property Editor, specify:

  • The variable name as food

  • The variable range as [0 10]

  • Five evenly distributed triangular MFs:

    • VL — Very low rating

    • L — Low rating

    • M — Medium rating

    • H — High rating

    • VH — Very high rating

Food rating input configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows five evenly distributed triangular MFs, from left to right across the VL, L, M, H, and VH.

Configure the service rating input of tipFIS. In the System Browser, select the second input of tipFIS. Then, in the Property Editor, specify the variable settings.

Specify the name of the input variable as service. The membership function and range parameters of the service rating input are the same as those for the food rating input.

Service rating input configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows five evenly distributed triangular MFs, from left to right across the VL, L, M, H, and VH.

Configure Output Variable

The output of tipFIS is a tip percentage based on the food and service ratings.

Configure output of tipFIS. In the System Browser, select the output of tipFIS. Then, in the Property Editor, specify:

  • The variable name as tip

  • The variable range as [0 30]

  • Five evenly distributed triangular MFs:

    • VL — Very low tip (centered on the value 5)

    • L — Low tip

    • M — Medium tip

    • H — High tip

    • VH — Very high tip (centered on the value 25)

The specified range and membership functions produce a final tip between 5% and 25%.

Tip output configuration. On the right, the Property Editor shows the name, range, and membership function details for the variable. In the middle, the Membership Function Editor document shows five evenly distributed triangular MFs, from left to right across the range, VL, L, M, H, and VH.

Define Rules

To specify rules for tipFIS, in the System Browser, select tipFIS. Then, in the document area, select the Rule Editor.

To define rules for tipFIS, consider the following:

  • Due to the way that foodFIS and serviceFIS interpret the weight factor input, there is no situation where the food and service inputs of tipFIS are any combination of very high and very low.

  • If either the food or service rating is very high, then the corresponding input had a high weight factor and a high rating. Therefore, the tip is very high.

  • If either the food or service rating is very low, then the corresponding input had a high weight factor and a low rating. Therefore, the tip is very low.

  • For combinations of low, medium, and high food and service ratings, set the tip MF according to the following table.

     food = Lfood = Mfood = H
    service = LVLLM
    service = MLMH
    service = HMHVH

Given these considerations, specify the final rule base.

Rule Editor showing 11 rules for tipFIS. There are two OR rules for the VH and VL cases and nine rules to cover the remaining MF combinations.

Analyze Control Surface

To validate the behavior of tipFIS, view its control surface.

In the System Browser, select tipFIS, then in the Simulation gallery, click Control Surface.

Control surface for tipFIS.

When the ratings are at their respective extremes, the very high and very low rules place the tip value at the corresponding high and low ends of the range, respectively.

The transition between the extremes is nonlinear and monotonically increasing along both rating axes.

Since both input variables have the same membership function and rule definitions, the resulting control surface is symmetrical.

Analyze FIS Tree Design

Control Surface

After designing and validating each individual FIS object, you can analyze the overall behavior of the FIS tree. As with the individual FIS objects, you can do so using the control surface.

In the System Browser, select weightedTipper, then in the Simulation gallery, click Control Surface.

To view the tip behavior based on the food and service ratings, in the Control Surface document, in the Axes drop-down lists:

  • Under X, select foodFIS/quality.

  • Under Y, select serviceFIS/quality.

For any inputs not specified in the Axes drop-down lists, you can specify reference values in the Reference Inputs field. Initially, the reference value for the weight input is 0.5. Therefore, the control surface shows the tip behavior when both food and service are weighted equally. The resulting surface is symmetric.

Control surface for FIS tree when food and service weighted equally.

As you adjust the weight input value, the tip behavior changes to reduce the contribution of one of the ratings. For example, to reduce the contribution of the service quality, increase the weight to 0.75.

Control surface for FIS tree when food is weighted higher than service.

For each value of food quality, the range of possible tip values decreases, which indicates that the service quality has a smaller impact on the final tip value.

To eliminate the contribution of the service quality entirely, increase the weight to 1.

Control surface for FIS tree when food is weighted higher than service.

The tip value increases as the food quality increases. However, changes in the service quality do not impact the tip value.

Data Propagation

Since R2024a

If your control surface analysis highlights areas where the FIS tree is not behaving as expected, you can further analyze the propagation of results through the FIS tree for given input values. By examining the intermediate FIS outputs, you can identify potentially problematic FISs within the FIS tree.

To view the FIS tree data propagation, in the System Browser, select weightedTipper, then in the Simulation gallery, click FIS Tree Data Flow.

The FIS Tree Plot document displays input and output values for each FIS in the FIS tree. To specify input values for the first layer of FIS objects, use the Input values field.

The following figure shows a sample data flow scenario for weightedTipper system.

  • The Input values field contains the specified input values: 8 for food quality, 3 for service quality, and 0.2 for the weighting factor.

  • The 0.2 weight factor indicates a higher preference for the service rating. Therefore:

  • The final low tip value reflects the low service rating and higher service weighting.

  • The foodFIS system lowers the food rating to 5.92, which is closer to a medium rating of 5.

  • The serviceFIS system does not modify the service rating, passing through the 3 rating.

FIS Tree Plot document in simulation mode. At the top of the document, the Input values field shows the values specified for each FIS input. For each FIS in the system, the input and output variables show values corresponding to the specified input values.

These results align with the expected behavior of the weightedTipper system.

If the final tip value had been high for these input values, the output of one or both of foodFIS and serviceFIS could indicate a problematic FIS design. If both of these FISs were behaving as expected, then the problem would likely lie in the tipFIS design.

Export FIS Tree

To export the FIS tree to the MATLAB® workspace, on the Design tab, select Export > Export Fuzzy Inference System to Workspace.

In the Export Fuzzy Inference System to Workspace dialog box, select the FIS tree in the Export column, and click Export.

Export dialog box with the corresponding entry in the Export column selected for weightedTipper.

You can also save your FIS tree to a MAT file. To do so, on the Design tab, under Save, click the FIS tree you want to save.

App toolstrip with the cursor pointing to weightedTipper in the Save drop-down list.

Then, in the Save Fuzzy Inference System dialog box, specify the file name and click OK.

See Also

Related Topics