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.
if the service is poor or the food is rancid, then the tip is cheap.
if the service is good, then the tip is average.
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:
since you will define the rules for your fis manually, clear the generate rules automatically check box.
under template fuzzy inference systems, select mamdani type-1.
the app creates the template fis and loads it in the app.
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
.
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.
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 inputfood
.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]
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.
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]
you can add output variables if they are required for your application. to do so, in the add components gallery, click output.
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.
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.
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.
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.
similarly, configure the properties for the food input variable.
finally, define the membership functions for the tip output.
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.
if the service is poor or the food is rancid, then the tip is cheap.
if the service is good, then the tip is average.
if the service is excellent or the food is delicious, then the tip is generous.
open the rule editor document.
to add a rule, click . the app adds a rule to the rule table and shows the rule properties in the property editor.
modify the rule properties for the first rule — if the service is poor or the food is rancid, then the tip is cheap.
set the connection parameter to or.
for the service input, select
poor
as the linguistic term.for the food input, select
rancid
as the linguistic term.for the tip output, select
cheap
as the linguistic term.
similarly, add the next rule — if the service is good, then the tip is average. for this rule:
for the service input, select
good
as the linguistic term.for the tip output, select
average
as the linguistic term.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:
set the connection parameter to or.
for the service input, select
excellent
as the linguistic term.for the food input, select
delicious
as the linguistic term.for the tip output, select
generous
as the linguistic term.
view the final rule base in the rule editor.
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.
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.
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.
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.
in the design browser section, the app creates a sugeno version of
the fis called tipper_1
.
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.
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.
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.
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.
the export fuzzy inference system to workspace dialog box lists the active fis design along with any stored designs.
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 .