how do I set membership function to this ANFIS?

I want to add membership function to this ANFIS code to be able to train it. the membership function type is Gaussian and the number of mfs is numMembershipFunctions = [3 2 4 3 3 2 3 3 2 3 3 4 3] .The raw code is:
% Observational Data
data = readtable('heart_dataset.csv');
X = table2array(data(:, 1:13)); % 13 Inputs of patient data
Y = table2array(data(:, 14)); % 1 Output (target)
data_Train = [X Y];
% Setting up the initial FIS using Subtractive Clustering method
genOpt = genfisOptions('SubtractiveClustering');
inFIS = genfis(X, Y, genOpt);
anOpt = anfisOptions('InitialFIS', inFIS, 'EpochNumber', 100);
% Training data with ANFIS
outFIS = anfis(data_Train, anOpt);

 Accepted Answer

In ANFIS training, only the Grid Partitioning method provides the flexibility to assign a fixed number of membership functions and their types for each input. However, for a relatively large dataset with 13 independent variables, genfis() will generate a large number of rules, as estimated below.
% Setting up the initial FIS using Grid Partitioning method
genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = [3 2 4 3 3 2 3 3 2 3 3 4 3];
genOpt.InputMembershipFunctionType = "gaussmf";
inFIS = genfis(X, Y, genOpt);
% Check the number of rules will be generated
MFs = [3 2 4 3 3 2 3 3 2 3 3 4 3];
numRules = prod(MFs)
numRules = 839808

5 Comments

Ahmad
Ahmad on 27 Oct 2023
Edited: Ahmad on 27 Oct 2023
ok Sir @Sam Chak, but I want to use a metaheuristic algorithm in this case the PSO algorithm to finely tune the ANFIS parameters.
Consider this example: You have Sam's Optimizer, which returns either a maximum or minimum point on a quadratic function. You may not have the space to use the PSO optimizer to optimize Sam's Optimizer directly.
However, you can employ PSO to optimize an objective function proposed in the form of parameters related to the properties of the membership functions or the fuzzy system. It's important to note that Sam's Optimizer and ANFIS Optimizer are not "Objective Functions" themselves. I hope this clarifies the concept for you.
p1 = 1; p2 = 2; p3 = 3; a = -3; b = 1;
[xopt, fval] = samsoptimizer(p1, p2, p3, a, b)
xopt = -1
fval = 2
function [xmin, fmin] = samsoptimizer(p1, p2, p3, a, b)
f = @(x) p1*x.^2 + p2*x + p3;
x = a:0.001:b;
plot(x, f(x)), hold on, grid on, ylim([0 6])
xmin = - p2/(2*p1);
fmin = f(xmin);
plot(xmin, fmin, 'p', 'markersize', 12, 'linewidth', 2), hold off
xlabel('x'), ylabel('f(x)')
title('Vertex of a Quadratic Function')
end
yes Sir @Sam Chak, I want to ask some questions,
  1. Rather than using ANFIS, since the inputs are too much, is it advisible to use artficial neural network to train my dataset? then employ the PSO to optimize it again ?
  2. can you please refer me to a tutorial where I can learn more about PSO algorithm in matlab?
Previously, I demonstrated that the 13-input ANFIS can predict the output perfectly. However, I'm not exactly sure about your current requirements. If ANFIS can predict the output perfectly, why would you want to use neural nets? Although I believe they can also predict the output perfectly. This leads me to deduce that your interest lies in researching the optimization capabilities of PSO itself, rather than the prediction capabilities of ANFIS or neural nets.
Regarding your request for a tutorial about PSO in MATLAB, I must be honest and admit that my knowledge of PSO is limited because I didn't invent the optimization algorithm. I use PSO as a tool, much like a calculator, to help me achieve my goals once the objective function is cleverly formulated. Designing an effective objective function can be considered an art that requires some skill.
If you are interested in inventing a new variant of PSO, you can read about the PSO algorithm here: https://www.mathworks.com/help/gads/particle-swarm-optimization-algorithm.html
You can also find an example that demonstrates how to optimize using the particleswarm() solver here: https://www.mathworks.com/help/gads/optimize-using-particle-swarm-optimization.html
Last but not least, you can explore the options for using the particleswarm() solver here: https://www.mathworks.com/help/gads/particleswarm.html
ok sir @Sam Chak, thanks for your contribution

Sign in to comment.

More Answers (0)

Categories

Find more on Fuzzy Logic Toolbox in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 26 Oct 2023

Commented:

on 30 Oct 2023

Community Treasure Hunt

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

Start Hunting!