如何在matlab的anfis.m中获得关于隶属函数的训练范围?

问题描述

我需要获取matlab中anfis中输入的隶属函数范围。我使用以下代码来训练我的网络并成功训练网络。但是我需要的是获得网络为输入的隶属函数找到的范围的值。我的意思是,如果隶属函数是钟形的,例如gbellmf,它将具有公式(x)= exp{-((x-c)/a)^(2*b)},并且我需要知道abc经过网络培训之后。


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

我的数据也是三个输入和一个输出数据(输入3列,输出1列)。 我使用matlab的内置genfis1anfis

解决方法

您可以通过以下方式访问第j个输入的第i个隶属函数的所有参数:

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

在下面的示例中,我为Iris数据训练了fis,该数据具有4个输入。然后,我使用存储在fismat中的数据来绘制所有隶属函数:

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');
fismat = genfis1(data,numMFs,mfType);

%% plot input membership function using plotmf
subplot(2,2,1),plotmf(fismat,'input',1);
subplot(2,2),2);
subplot(2,3),3);
subplot(2,4),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,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