Scilab is a free alternative to Matlab.
It has a fuzzy logic toolbox called sciFLT but there are not many tutorials for it in English.
Here, I’ll take some examples from the Matlab’s tutorial and implement them in Scilab.
The first example is the tipping problem:
Given two sets of numbers between 0 and 10 (where 10 is excellent) that respectively represent the quality of the service and the quality of the food at a restaurant, what should the tip be?
In the non-fuzzy approach, the model consists of long formulas, and the surface of the solution doesn’t look nice.
clc clf function tip=f(food,service) servRatio=0.8; if (service<3) then tip=((0.10/3)*service+0.05)*servRatio + ... (1-servRatio)*(0.20/10*food+0.05); elseif (service<7) then tip=(0.15)*servRatio + ... (1-servRatio)*(0.20/10*food+0.05); else tip=((0.10/3)*(service-7)+0.15)*servRatio + ... (1-servRatio)*(0.20/10*food+0.05); end endfunction food=linspace(0,10); service=linspace(0,10); tip=feval(food,service,f)'; surf(food,service,tip) a=get("current_axes"); a.x_label.text="food"; a.y_label.text="service"; a.z_label.text="tip";
In this code we assume that we give a 15% tip in general, but will depart from this if the service is exceptionally good or bad.
Also, we give 80% of the tip for the quality of service 20% for the quality of food.
Now, let’s solve this problem “the fuzzy way”.
sciFLT works with Mamdani and Sugeno fuzzy logic systems (FLS).
The sciFLT is located in
ATOMS Module manager –> Modeling and Control Tools –> Fuzzy Logic Toolbox
Start the sciFLT graphical user interface with the command
In the menu of the FLS editor, go to
File –>New FLS –>
and choose which fuzzy inference method (Mamdani or Sugeno) you want to work with.
We choose Mamdani.
Click the ‘Description’ link and fill out the form (click the picture to enlarge).
Then specify the input and output variables as well as the rules.
We have two input variables
and one output variable
The food variable takes two fuzzy values: rancid and delicious.
The service variable takes three fuzzy values: poor, good, excellent.
The tip variable takes three fuzzy values: cheap, average, generous.
I model them with triangular membership functions.
Triangular functions in sciFLT have bugs in the ends of the variables’ universes. I work around these bugs by using trapezoidal functions (click the pictures to enlarge them and see the details).
To view the variables,
View –> Plot Current Var
Our fuzzy rules are:
1. If service is poor or the food is rancid, then tip is cheap
2. If service is good, then tip is average
3. If service is excellent or food is delicious, then tip is generous
To save the FLS into the workspace,
File –> Export –> to workspace
It will be available till the end of your session in Scilab.
To save the FLS on a hard drive,
File –> Export –> to fls file (scilab)
I saved it into the workspace under the name
Typing into the console
gives a good-looking, smooth, non-linear surface of the solution.
To load your FLS from the hard drive, type
tipfls is a name of the variable where I save my FLS from the file tipfls.fls
Part 2: link
Part 3: link
Part 4: link