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)
Show older comments
Ben Hatrick
on 6 Apr 2024
Answered: Abdesattar Mazouzi
on 18 Oct 2024
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
on 6 Apr 2024
Hi @Ben Hatrick
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')
Accepted Answer
Sam Chak
on 8 Apr 2024
Hi @Ben Hatrick
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:
- Is it acceptable to achieve numerical matching between the observed data and the tuned fuzzy system without considering the logical foundation of the MFs?
- 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
on 8 Apr 2024
Hi @Ben Hatrick
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.
More Answers (2)
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:
0 Comments
See Also
Categories
Find more on Fuzzy Inference System Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!