Fuzzy Logic Models in Simulink

Fuzzy logic can also be incorporated into a Simulink model, as demonstrated above.

There are special blocks for membership functions and fuzzy logic controllers. The following troubleshooting tips apply to such models:

1. The FIS must be "read" into the workspace, using the command readfis. This is often done in an initialization routine, before the model is simulated.

2. If you receive an error message indicating that the FIS you have selected is unknown, make sure that the FIS has been read into the workspace. For example, if the readfis command shown in the example code fragment 15-2 had been issued, the parameter for the fuzzy logic controller would be fismat, not myfis.

3. The inputs can be fed by a command-line script or into a Simulink model. In an m-file, the syntax is described in Code Fragment 15-2, "Read FIS Command" on page 400.

4. Carefully check the orientation of the inputs.

5. Look under the mask of the fuzzy logic controller as well as simply clicking it to set the parameter.386®

6. Check to see that the proper FIS name is included in all the blocks (the animation and the controller blocks), drilling down twice for the controller. Do not assume that the parameter will pass through to the lower levels; there may be a bug preventing this.

7. When all else fails, delete the block. Break the library link for a new block from the Simulink library and import it into the model. Go through all the above steps systematically as you hook up the new block.

Appendix Code Fragment 15-3. Fuzzy Logic Audit Risk

% Fuzzy Logic Example: Risk of Audit %

% (c) 2001-2003, Anderson Economic Group

% Use with license only.

% August 2003, ver 3

% Uses: Fuzzy Logic Toolbox, generat^_tax_input.m echo on;

% Fuzzy Logic Audit Predictor % Patrick L. Anderson

386a If you have the block with the ruleviewer animation, you may need to look under the mask twice in order to get down to the actual FIS controller block. You enter the parameter first by clicking on the controller block, then put it into the animation block, and then look under the controller block mask again (for a total of three times) to set the parameter.

% AEG LLC, Lansing Michigan

% Read in Fuzzy Inference System (fis).

% Note that FIS must already be created; that the

% file must be in the path;

% that the name of the file must be in single

fismat = readfis('tax5.fis')

% Note that fuzzy inference system is a MATLAB % structure.

% Examine the items within the structure, fismat. .name fismat. .input fismat. .input. .name fismat. .rule % --------------

% Now print rules in workspace rules_text = showrule(fismat)

% Now use specific tools to plot parts of FIS figure(1), plotfis(fismat);

title('Fuzzy Logic Tax Audit Predictor Structure',

text (0.4, -0.2, ['Printed by AEG, 'datestr(now, 1)] 'units', 'normal ized', 'fontangle', 'italic'); figure(2), plotmf(fismat, 'input;', 1); tltle('Tax Audit Predictor; Income MF', 'fontweight;', 'bold');

% text (0.0, -0.2, ['Printed by AEG, 'datestr(now, 1)], 'units', 'normalized', 'fontangle', 'ital ic'); figure(3), plotmf(fismat, 'input;', 2) title('Tax Audit Predictor; Flag MF', 'fontweight;', 'bold');

1)], 'units', 'normalized', 'fontangle', 'ital ic');

% Now use GUI to see rules ruleview(fismat)

% Create input vector of many cases, using random

% variables; display generate_tax_input

% evaluate input vector rating = evalfis(test_input, fismat);

% Display numerical and verbal assessments;

disp('Gross income, audit flags, deduct ions, accuracy inputs are:');


disp('Audit risk index on a 0 to 1 scale (1 is highest): '); disp (rating);

% Create bar chart of ratings of sample tax returns figure, bar (rating);

title('Ratings of test tax returns', 'fontweight;', 'bold');

ylabel ('Rating (higher number is higher risk)'); text (0.0, -0.1, ['Printed by AEG, 'datestr(now,

1)], 'units', 'normalized', 'fontangle', 'ital ic');

% Check to see what is in the workspace now. whos

% end of script

0 0

Post a comment