build fuzzy systems using fuzzy logic designer -凯发k8网页登录

main content

build fuzzy systems using fuzzy logic designer

this example shows how to interactively create a type-1 mamdani fuzzy inference system (fis) to solve the tipping problem defined in . for this problem, tipping behavior is defined using the following three rules.

  1. if the service is poor or the food is rancid, then the tip is cheap.

  2. if the service is good, then the tip is average.

  3. if the service is excellent or the food is delicious, then the tip is generous.

while this example creates a type-1 mamdani fis, the general methods used apply to creating type-2 and sugeno systems as well. for more information on the different types of fuzzy systems, see and type-2 fuzzy inference systems.

for more information on building a fis at the command line, see .

for this example, you build a tipper fis from scratch. alternatively, you can load the system from the tipper.fis file. to do so, use the following command.

fuzzylogicdesigner('tipper.fis')

create fis structure

to build the fis yourself, first open the app. on the apps tab, under control system design and analysis, click the app icon.

the apps opens a getting started dialog box. for more information the options for creating your initial fis structure, see .

for this example, since you are creating a type-1 mamdani system with the two inputs and one output, you can use a built in template as a starting point. to do so:

  1. since you will define the rules for your fis manually, clear the generate rules automatically check box.

  2. under template fuzzy inference systems, select mamdani type-1.

getting started dialog - in the top-right corner, the generate rules automatically parameter is cleared. the type-1 mamdani template is highlighted.

the app creates the template fis and loads it in the app.

initial fuzzy logic designer view, showing the input and output variables in the fuzzy inference system plot document.

in the property editor section, you can specify the name of your fis along with its inference methods. for this example, use the default inference methods. for more information on the available inference methods, see and .

in the name field, enter the name tipper.

property editor with name field highlighted and the name value set to

define input variables

for this example, the template fis already has two input variables. in the system browser section, click inputs. the app displays the properties of the input variables in the property editor.

app with inputs label selected in the system browser on the left and the corresponding input variable properties listed in the property editor on the right

in the property editor, define the following properties for each input variable.

  • name — input variable name. for this example, name the first input service and the second input food.

  • range — input variable range. for this example, both inputs are rated on a scale from 0 through 10. therefore, specify each variable range as [0 10]

property editor input table with three columns including the name column on the left, the range column in the middle and the number of mfs column on the right. the updated settings for the two input variables are specified in the name and range columns.

you can add more input variables if they are required for your application. to do so, on the design tab, in the add components gallery, click input.

app toolstrip with the input option listed as the only option in the add components gallery

define output variables

for this example, the template fis already has one input variable. in the system browser section, click outputs. the app displays the properties of the output variable in the property editor.

in the property editor, define the following properties for the output variable.

  • name — output variable name. for this example, name the output variable tip.

  • range — output variable range. for this example, specify the output variable range as [0 30]

property editor input table with updated settings for the output variable specified in the name and range columns.

you can add output variables if they are required for your application. to do so, in the add components gallery, click output.

app toolstrip with the output option listed as the only option in the add components gallery

define membership functions

to add or remove membership functions for a given variable, select the variable in the system browser or click the variable in the fuzzy inference system document. for example, select the food input variable. in the property editor, the app shows the input variable and membership function properties.

fuzzy inference system plot document on the left showing the food input as selected and the property editor on the right showing the three default mfs for the food input.

by default, the template adds three membership functions for each variable. for this example, the service input variable and the tip output variable both require three membership functions.

however, the food variable requires two membership functions. to remove one of the default membership functions, in the system browser, under food, right-click the membership function and select delete.

system browser with the food variable expanded to show the mfs and the right-click menu showing the delete option for the second mf.

you can add membership functions to a given variable if they are required for your application. to do so, in the add components gallery, click mf.

app toolstrip with the mf option listed as the only option in the add components gallery

to edit membership function properties, in the system browser, select the membership function or the corresponding variable. then, in the property editor, specify the following membership function properties.

  • name — membership function name

  • type — membership function type

  • parameters — membership function parameters

to view a plot of the membership functions for a given variable, select the variable in the system browser and open the membership function editor document. the following figure shows the membership functions for the service input variable.

configure the membership functions for the service input using the properties shown in the following figure.

membership function editor on the left showing a plot of three gaussian mfs: poor on the left side of the plot, good in the middle, and excellent on the right. the property editor table on the right lists the mfs and their parameters: poor with parameters [1.5 0], good with parameters [1.5 5], and excellent with parameters [1.5 10].

similarly, configure the properties for the food input variable.

membership function editor on the left showing a plot of two trapezoidal mfs: rancid on the left side of the plot and delicious on the right. the property editor table on the right lists the mfs and their parameters: rancid with parameters [0 0 1 3] and delicious with parameters [7 9 10 10.

finally, define the membership functions for the tip output.

membership function editor on the left showing a plot of three triangular mfs: cheap on the left side of the plot, average in the middle, and generous on the right. the property editor table on the right lists the mfs and their parameters: cheap with parameters [0 5 10], average with parameters [10 15 20], and generous with parameters [20 25 30].

for more information on defining membership functions, see .

define rule base

once you define the variables and membership functions for your fis, you can define the if-then rule base for the system.

for this example, use the following rules.

  1. if the service is poor or the food is rancid, then the tip is cheap.

  2. if the service is good, then the tip is average.

  3. if the service is excellent or the food is delicious, then the tip is generous.

open the rule editor document.

rule editor with no rules currently listed in the table. there is a plus icon on the right edge of the rule editor near the top of the rule table

to add a rule, click plus icon. the app adds a rule to the rule table and shows the rule properties in the property editor.

rule editor on the left showing the single default rule in the rule table as selected. on the right, the property editor shows the properties of this rules.

modify the rule properties for the first rule — if the service is poor or the food is rancid, then the tip is cheap.

  1. set the connection parameter to or.

  2. for the service input, select poor as the linguistic term.

  3. for the food input, select rancid as the linguistic term.

  4. for the tip output, select cheap as the linguistic term.

property editor showing the updated parameters for the first rule

similarly, add the next rule — if the service is good, then the tip is average. for this rule:

  1. for the service input, select good as the linguistic term.

  2. for the tip output, select average as the linguistic term.

  3. since this rule has only the service input in the antecedent, ignore the food input by setting its linguistic term to none.

finally, add the rule — if the service is excellent or the food is delicious, then the tip is generous. for this rule:

  1. set the connection parameter to or.

  2. for the service input, select excellent as the linguistic term.

  3. for the food input, select delicious as the linguistic term.

  4. for the tip output, select generous as the linguistic term.

view the final rule base in the rule editor.

rule editor showing the final three rules in the rule table.

for more information on specifying rules for your fis, see

analyze design

once you define your rule base, you can analyze your design using the following documents.

  • rule inference — specify input values and view the inference diagram and resulting output value.

  • control surface — plot the output values for all combinations of two input variables.

  • system validation — compare the outputs from each fis design with the corresponding output value from the testing data.

  • error distribution — for a given fis design and testing data, view the output error for different combinations of inputs.

for more information on fis analysis methods, see .

for this example, analyze the fis using the rule inference and control surface documents. to open either document, on the design tab, click the corresponding icon in the simulation gallery.

app toolstrip highlighting the rule inference and control surface options in the simulation gallery.

rule inference

in the rule inference document, you specify values for your input variables, inspect the inference process, and view the resulting output value.

for example, consider the case where the service was quite poor (1/10) but the food was very good (9/10). specify these input values using the input values parameter. alternatively, you can drag the input bars in the inference diagram.

rule inference document for input values [1 9]. for each rule, there is one row with three plots in order left-to-right: service input, food input, and tip output. each plot show the mf for that rule. there are vertical lines indicating the input value for each variable that intersect the mfs in the plots. the fuzzy intersection values are combined using the or inference operator (maximum) and used to clip the output mfs. the aggregate output mf is shown in a plot on the bottom right of the document.

the low service rating causes the first rule to fire with a high firing strength and the high food rating causes the third rule to fire with a high firing strength. when the resulting output membership functions are aggregated and defuzzified, the final tip value 15.2%.

for more information on fuzzy inference, see .

control surface

the control surface document shows the fis output value for all possible combinations of two input variables. for this example, the plot shows the tip value for all service and food rating combinations.

control surface document showing a nonlinear surface plot of tip values. generally, the tip is low (5%) when the food and service inputs are both near 0 and high (25% when the food and service inputs are both near 10.

store and modify designs

you can store multiple fis designs in the app, which allows you to explore possible design options. all stored designs must have the same number of inputs and the same number of outputs.

a common design option to explore is converting a mamdani system into a sugeno system. in general, sugeno systems are more computationally efficient, which is an important consideration when deploying a fis.

to convert the fis to a sugeno system, on the design tab, select mamdani to sugeno.

app toolstrip with the mamdani to sugeno option highlighted in the convert fis toolstrip section.

in the design browser section, the app creates a sugeno version of the fis called tipper_1.

design browser table showing two rows, each with one design. the table has three columns, listed left-to-right: active, design, type. the first row, which is the original fis design, has a check mark in the active column, its name tipper in the design column, and mamdani type-1 in the type column. the second row, which is the converted fis design, has an empty active column, its name tipper in the design column, and sugeno type-1 in the type column.

to make this design active, select the design in the table and click set active design.

you can also manually store a copy of your current fis in the design browser. to do so, on the design tab, select store current design.

app toolstrip with the store current design option highlighted in the designs toolstrip section.

you can then analyze the alternative design in the same manner as the first design.

the plot for the sugeno system in the control surface document looks similar to the plot for the mamdani system.

control surface document showing a nonlinear surface plot of tip values. generally, the tip is low (5%) when the food and service inputs are both near 0 and high (25% when the food and service inputs are both near 10.

using the rule inference document, you can see that, for the same service and food ratings, the sugeno system generates a 16.1% tip, which is similar to the 15.2% tip for the mamdani system.

rule inference document for input values [1 9]. the input mf plots match those of the previous mamdani rule inference plot. the difference is that the output mfs are now singleton mfs rather than fuzzy sets.

export fis

once you design your fis using fuzzy logic designer, you can export the active and stored designs to the matlab® workspace for further simulations and deployment.

to export a fis design to the matlab workspace, in fuzzy logic designer, select export > export fuzzy inference system to workspace.

app toolstrip showing the export fuzzy inference system to workspace selection in the export drop-down menu on the far right side of the toolstrip.

the export fuzzy inference system to workspace dialog box lists the active fis design along with any stored designs.

export fuzzy inference systems to workspace dialog box listing two fis designs to export. the table contains three columns: export on the left with check boxes for selecting designs, fuzzy inference system in the middle with the design names, and export as on the right with default variable names that match the design names.

in the export column, select one or more systems that you want to export.

in the export as column, specify names for the workspace variables.

click export.

the app saves the fis to the matlab workspace.

for more information on exporting and saving your fis, see .

see also

related topics

    网站地图