Particle swarm algorithm in Fuzzy Logic Designer is breaking unity sum property of membership functions, how can I stop this?

12 views (last 30 days)
I am using the Fuzzy Logic Designer App to fine-tune a Type-I Mamdani FIS. I have preset a number of inputs with three membership functions each, using Trapezoidal->Triangular->Trapezoidal. I want to optimize the parameters of these membership functions using the built-in PSO algorithm, but when I do, it significantly warps the shape of my membership functions (see the example below).
The new membership functions do not adhere to the key property of unity, where the sum of the membership values for a given input is 1. Is there a way to stop this from happening, or should I just tune my functions empirically?
  2 Comments
Sam Chak
Sam Chak on 6 Apr 2024
Could you please share the code that produced the unexpected result? If you used the standard triangular membership function 'trimf()' as a tunable object for the built-in PSO algorithm 'particleswarm()' to adjust the three parameters, it seems unlikely to achieve such a result unless you manually scaled the standard triangular membership function, when I attempted to construct it below.
x = 0:1e-2:5;
mf = trimf(x, [0.9 2.0 2.8]); % standard triangular MF
plot(x, mf), grid on, xticks(0:0.5:5), ylim([0, 1]), xlabel('Input'), ylabel('Degree of Membership'), title('Standard Triangular MF')
amp = 0.43; % amplitude
y = amp*mf; % scaled triangular MF
plot(x, y), grid on, xticks(0:0.5:5), ylim([0, 1]), xlabel('Input'), ylabel('Degree of Membership'), title('Scaled Triangular MF')
Ben Hatrick
Ben Hatrick on 7 Apr 2024
Hi Sam,
Thanks for the response,
I am not manually coding the membership functions/ rules as part of a script but using the fuzzy logic designer GUI. When I view the generated FIS in the editor, I get the below for the function in question.
[Output1]
Name='Complexity'
Range=[0 5]
NumMFs=3
MF1='Simple':'trapmf',[0 0 1.5 3]
MF2='Moderately Complex':'trimf',[2 3 4]
MF3='Complex':'trapmf',[3 4.5 5 5]
I then used the built-in PSO to first generate rules only before fixing them tuning the membership functions themselves and getting these oddly shaped functions returned. The model achieves a satisfactory level of performance by tuning the MFs empirically so not all is lost. Maybe the PSO/other tuning algorithms are not forced to ensure that the sum of membership values is 1 and focus purely on the optimisation of output.

Sign in to comment.

Accepted Answer

Sam Chak
Sam Chak on 8 Apr 2024
I have rarely used PSO to tune fuzzy systems, and I hadn't realized this phenomenon until you brought it up.
As a test, I applied PSO to tune a fuzzy system for a Clipped Sine wave. Although the error between the observed data and the PSO-tuned fuzzy system is relatively small, I'm facing a challenge in logically interpreting the degrees of some membership functions (MFs). Specifically, the 'in1mf' MFs exhibit an illogical sequence, and 'in1mf4' completely overlaps with 'in1mf1', 'in1mf2', 'in1mf5', 'in1mf6', and 'in1mf7'. Are such overlaps and inconsistencies acceptable from a human reasoning perspective?
This raises a deeper question to ponder:
  1. Is it acceptable to achieve numerical matching between the observed data and the tuned fuzzy system without considering the logical foundation of the MFs?
  2. Or, should we prioritize the logical validity during the tuning process?
I'm afraid that the answers to these questions have to be evaluated on a case-by-case basis. It is essential to consider the specific context and requirements of each situation.
Similarly, I have observed numerous users in the forum blindly fitting popular polynomial models to finite response data from dynamical systems. However, it is important to note that these systems often have well-established mathematical models or even analytical solutions. Blindly fitting polynomial models without considering the underlying mathematical structure might not yield meaningful results for prediction purposes.
%% Data generated by a Clipped Sine wave
x = (0:0.1:10)';
y = max(-0.5, min(sin(pi/5*x), 0.5));
%% Generate FIS
fisOpts = genfisOptions('GridPartition');
fisOpts.NumMembershipFunctions = 7;
fisOpts.InputMembershipFunctionType = "trapmf";
fisOpts.OutputMembershipFunctionType = "linear";
fisin = genfis(x, y, fisOpts);
%% Tune FIS
[in, out, rule] = getTunableSettings(fisin);
metOpts = tunefisOptions("Method", "particleswarm", "Display", "none");
fisout = tunefis(fisin, [in; out; rule], x, y, metOpts)
%% Plots
figure(1)
plotmf(fisin, 'input', 1), grid on, title('Input MFs before tuning with pso')
plotmf(fisout, 'input', 1), grid on, title('Input MFs after tuning with pso')
yTuned = evalfis(fisout, x);
figure(2)
plot(x, y, x, yTuned), grid on, ylim([-1 1])
xlabel('x'), ylabel('y'), legend('data', 'pso-tuned'), title('Results')
"Elapsed time is 3383.380043 seconds."
  1 Comment
Sam Chak
Sam Chak on 8 Apr 2024
You may want to explore alternative tuning methods. In my Clipped Sine example, I found that the ANFIS-tuned fuzzy system produced superior and meaningful results compared to the PSO-tuned fuzzy system.

Sign in to comment.

More Answers (2)

Ben Hatrick
Ben Hatrick on 12 Apr 2024
Hi Sam,
I appreciate your going to such lengths to investigate this issue. The main problem is that the in-built PSO algorithm for MF tuning is designed to minimize the cost function without restrictions on how the resultant MFs relate to one another. ANFIS does seem to be a more robust algorithm in this regard but can only be applied to Sugeno fuzzy systems, and I am using a Mamdani. Optimization methods such as the one attached below have been developed to retain the logical foundations of tuned MFs.
I will accept your answer and close this thread as it provides valuable insight into the problem and you are right; answers must be evaluated on a case-by-case basis.

Abdesattar Mazouzi
Abdesattar Mazouzi on 18 Oct 2024
I have used Fuzzy Logic Designer to tune a fuzzy logic controller, with two inputs and one output, I've selected Genetic Algorithm within the fuzzy logic designer tuning options, and after optimization was completed, the FLC indeed has been optimized, but I got that Membership function shape that seems to be not acceptable,
In your case, you mentioned that the problem lies within the PSO algorithm, which produced incompatible MF parameters. However after I used GA instead of PSO, it seems that the problem is in the FuzzyLogicDesigner code, which sometimes doesn't restrict the output of the optimization algorithm.
I thought of manually adjusting the produced MF parameters, but after doing that, I tested the FLC's performance, and it resulted in very bad performance. I hope you figured out the issue.
In my case I've created my own tuneable 2-input/1-output mamdani fuzzy logic inference system. you can check it here:

Categories

Find more on Fuzzy Inference System Modeling in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!