Main Content

getFISCodeGenerationData

Create homogeneous fuzzy inference system structure

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.

example

fisOut = getFISCodeGenerationData(fisIn) converts the FIS object fisIn into the homogeneous structure fisOut. fisIn can be either a type-1 or type-2 FIS.

example

fisOut = getFISCodeGenerationData(fileName) creates a homogeneous structure for the type-1 FIS stored in the file indicated by fileName.

example

fisOut = getFISCodeGenerationData(fileName,"FuzzySetType","type2") creates a homogeneous structure for the type-2 FIS stored in the file indicated by fileName.

example

fisTreeOut = getFISCodeGenerationData(fisTreeIn) converts the FIS tree object fisTreeIn into the homogeneous structure fisTreeOut.

Examples

collapse all

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 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");

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

collapse all

Input fuzzy inference system, specified as a mamfis, sugfis, mamfistype2, or sugfistype2 object.

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.

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.

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

collapse all

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.

Output FIS tree, returned as a structure with the following fields.

  • FIS — Homogeneous FIS structures

  • Connections — Connections between FISs

  • Outputs — FIS tree outputs

  • EvaluationFcn — 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

Version History

Introduced in R2018b

expand all