How to get trained ranges for membership functions in anfis.m of matlab?

432 Views Asked by At

I need to get ranges of membership functions of inputs in an anfis in matlab. I use the following code to train my network and successfully train the network. But what I need is to get the value of ranges that the network finds for membership functions of inputs. I mean if a membership function is a bell-shaped one, like gbellmf, it would have this formula (x)= exp{-((x-c)/a)^(2*b)} and I need to know the value of a, b and c after the network is trained.


function trainedfis = main(data,chkdata)
    
fis = genfis1(data,[3 3 3],char('gbellmf','gbellmf', 'gbellmf'));
    
[trainedfis,errors,stepssize,chkfis,errchk] = anfis(data,fis,3,[1 1 1 1],chkdata);
        
end

also my data is a three input and one output data (3 columns for input and 1 column for output). I use the built in genfis1 and anfis of matlab.

1

There are 1 best solutions below

4
On BEST ANSWER

You can access all parameters of j-th membership function of i-th input by:

fis.input(i).mf(j).params

In the following example I trained fis for the Iris Data, which has 4 inputs. Then I used data stored in fismat to plot all membership functions:

close all; clc; clear variable;
%% import iris data
[x, t] = iris_dataset;
y = t(1, :)*1 + t(1, :)*2 + t(3, :)*3;
data = [x' y'];
%% train fis moddel
numMFs = [3 3 3 3];
mfType = char('gbellmf','gbellmf', 'gbellmf', 'gbellmf');
fismat = genfis1(data,numMFs,mfType);

%% plot input membership function using plotmf
subplot(2,2,1), plotmf(fismat,'input',1);
subplot(2,2,2), plotmf(fismat,'input',2);
subplot(2,2,3), plotmf(fismat,'input',3);
subplot(2,2,4), plotmf(fismat,'input',4);

%% plot input membership function manually, using fismat object
figure;
% get number of inputs
ni = numel(fismat.input);
for i=1:ni
    % get total range of all mem-funs of i-th input
    range = fismat.input(i).range; 
    subplot(2, 2, i);
    xlabel(['input ' num2str(i)]);
    xlim(range); hold on;
    x = linspace(range(1), range(2), 100);
    % get number of mem-funs of i-th input
    nmf = numel(fismat.input(i).mf);
    for j=1:nmf
        % get j-th mem-fun of i-th input
        mf = str2func(fismat.input(i).mf(j).type);
        % get parameters of j-th mem-fun of i-th input
        params = fismat.input(i).mf(j).params;
        y = mf(x, params);
        plot(x, y, 'displayname', ...
            [fismat.input(i).mf(j).type '(' num2str(params, '%.1f,') ')']);
    end
    legend('show')
end

enter image description here