getFISCodeGenerationData
Create homogeneous fuzzy inference system structure
Syntax
Description
To generate code for evaluating a fuzzy inference system (FIS) using MATLAB®
Coder™, you must convert your fuzzy inference system object into a homogeneous
structure using getFISCodeGenerationData
.
converts the FIS tree object fisTreeOut
= getFISCodeGenerationData(fisTreeIn
)fisTreeIn
into the homogeneous structure
fisTreeOut
.
Examples
Convert FIS Object into Homogeneous Structure
Create a fuzzy inference system. For this example, load a fuzzy system from a file.
fisObject = readfis('tipper');
Convert the resulting mamfis
object into a homogeneous structure.
fisStructure = getFISCodeGenerationData(fisObject)
fisStructure = struct with fields:
name: 'tipper'
type: 'mamdani'
andMethod: 'min'
orMethod: 'max'
defuzzMethod: 'centroid'
impMethod: 'min'
aggMethod: 'max'
input: [1x2 struct]
output: [1x1 struct]
rule: [1x3 struct]
In this structure, if a field is a structure array, all the elements of that array are the same size. For example, consider the elements of input variable array fisStructure.input
.
fisStructure.input(1)
ans = struct with fields:
name: 'service'
origNameLength: 7
range: [0 10]
mf: [1x3 struct]
origNumMF: 3
fisStructure.input(2)
ans = struct with fields:
name: 'food '
origNameLength: 4
range: [0 10]
mf: [1x3 struct]
origNumMF: 2
The name
fields are character vectors of the same length. Also, even though the second input variable has only two membership functions, the mf
fields both contain three membership function structures. The original number of membership functions for a given input variable is stored in the origNumMF
field.
You can also convert a type-2 FIS into a homogeneous structure for code generation. For example, convert fisObject
into a type-2 system and create a corresponding homogeneous structure.
fisObject2 = convertToType2(fisObject); fisStructure2 = getFISCodeGenerationData(fisObject2)
fisStructure2 = struct with fields:
name: 'tipper'
type: 'mamdani'
andMethod: 'min'
orMethod: 'max'
defuzzMethod: 'centroid'
impMethod: 'min'
aggMethod: 'max'
input: [1x2 struct]
output: [1x1 struct]
rule: [1x3 struct]
typeReductionMethod: 'karnikmendel'
Load FIS from File into Homogeneous Structure
Load the type-1 FIS stored in the file tipper.fis
into a homogeneous structure.
fisData = getFISCodeGenerationData("tipper.fis");
You can also load a type-2 FIS from a file into a homogeneous structure. To do so, you must specify that the FIS in the file is a type-2 system.
For example, create a type-2 FIS and save it to a file.
fis2 = mamfistype2("NumInputs",3,"NumOutputs",2); writeFIS(fis2,"type2.fis");
Load the saved file into a homogeneous structure.
fisData2 = getFISCodeGenerationData("type2.fis","FuzzySetType","type2");
Convert FIS Tree Object into Homogeneous Structure
Create a type-1 Mamdani FIS and a type-2 Sugeno FIS.
fis1 = mamfis('Name','fis1','NumInputs',2,'NumOutputs',1); fis2 = sugfistype2('Name','fis2','NumInputs',2,'NumOutputs',1);
Create a FIS tree object where the output of fis1
connects to the first input of fis2
.
con1 = ["fis1/output1" "fis2/input1"]; tree = fistree([fis1 fis2],con1);
Convert the FIS tree object into a homogeneous structure.
treeStructure = getFISCodeGenerationData(tree)
treeStructure = struct with fields:
FIS: {[1x1 struct] [1x1 struct]}
Connections: {'fis1/output1' 'fis2/input1'}
Outputs: {'fis2/output1'}
EvaluationFcn: [1x1 struct]
Input Arguments
fisIn
— Input fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object
Input fuzzy inference system, specified as one of the following:
mamfis
object — Mamdani fuzzy inference systemsugfis
object — Sugeno fuzzy inference systemmamfistype2
object — Type-2 Mamdani fuzzy inference system (since R2019b)sugfistype2
object — Type-2 Sugeno fuzzy inference system (since R2019b)
getFISCodeGenerationData
supports fuzzy inference system
objects for simulation only.
When getFISCodeGenerationData
loads a fuzzy system that uses
custom functions, it writes additional files to the current folder to support code
generation for the custom functions.
fileName
— Fuzzy inference system file name
string | character vector
Fuzzy inference system file name, specified as a string or character vector. The
specified file must be a .fis
file in the current working folder or
on the MATLAB path.
fisTreeIn
— Input FIS tree
fistree
object
Input FIS tree, specified as a fistree
object. You can specify a FIS tree that contains any combination of
mamfis
, sugfis
, mamfistype2
, or
sugfistype2
objects.
Output Arguments
fisOut
— Output fuzzy inference system
structure
Output fuzzy inference system, returned as a homogeneous structure. In the
homogeneous structure, if a field is a structure array, all the elements of that array
are the same size. For example, in the input variable array
fisOut.input
:
The names of all the variables are character vectors of the same length.
The lengths of the membership function arrays for all variables are the same.
For any character vectors or structure arrays that are padded to increase their lengths, the original lengths of these elements are saved within the structure.
The fisOut
structure is different from the structure created
using convertToStruct
.
Note
Modifying the fields of fisOut
can produce unexpected
results. Instead, modify fisIn
and call
getFISCodeGenerationData
again.
fisTreeOut
— Output FIS tree
structure
Output FIS tree, returned as a structure with the following fields.
FIS
— Homogeneous FIS structuresConnections
— Connections between FISsOutputs
— FIS tree outputsEvaluationFcn
— Generated function for evaluating the FIS tree
Note
Modifying the fields of fisTreeOut
can produce unexpected
results. Instead, modify fisTreeIn
and call
getFISCodeGenerationData
again.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
getFISCodeGenerationData
supports FIS objects (mamfis
,sugfis
,mamfistype2
, orsugfistype2
) for simulation only. To generate code forgetFISCodeGenerationData
, specify the input fuzzy inference system using a file name.getFISCodeGenerationData
supportsfistree
objects for simulation only.It is good practice to not use
getFISCodeGenerationData
within a MATLAB Function block. This function is a utility function for generating code for evaluating a fuzzy inference system using MATLAB Coder.
Version History
Introduced in R2018bR2022b: C and C++ code generation support for evaluating FIS trees
You can generate homogeneous structures for FIS trees. You can then use these structures for code generation using MATLAB Coder. For more information, see Generate Code for Fuzzy System Using MATLAB Coder.
See Also
mamfis
| sugfis
| mamfistype2
| sugfistype2
| evalfis
| evalfisOptions
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)