# Evalfis Plus Fuzzy Exponentials

### Rogério Andrade Flauzino (view profile)

09 Sep 2004 (Updated )

This functions eval a Fis extructure using fuzzy exponentials.

evalFisBetter.m
```function y=evalFisBetter(x,fisMat)
% Processamento de sistema fuzzy mandani com exponete nebuloso
y=[];
for i=1:size(x,1)
SC=fuzzificationInput(fisMat,x(i,:));

% Obtenao das variaveis de saida das regas
ruleOut=evalrule(fisMat,SC);

% realizaao da implicaao das regras
M=fuzzyImplication(fisMat,evalrule(fisMat,fuzzificationInput(fisMat,x(i,:))));

% agregaao das regras fuzzy
Magre=fuzzyAgregation(fisMat,M);

% defuzzificaao do conjunto nebuloso agregado
aux=defuzz(linspace(fisMat.output.range(1),fisMat.output.range(2),length(M)),M,fisMat.defuzzMethod);
y=[y
aux];
end

% =========================================================================
function SC=fuzzificationInput(fisMat,x)
for j=1:length(fisMat.input)
SC(j).fuzzyInput=[];
for k=1:length(fisMat.input(j).mf)
SC(j).fuzzyInput=[SC(j).fuzzyInput
evalmf(x(j),fisMat.input(j).mf(k).params,fisMat.input(j).mf(k).type)];
end
end

% =========================================================================

function ruleOut=evalrule(fisMat,SC)
ruleOut=[];
for i=1:length(fisMat.rule)
x=[];
for j=1:length(fisMat.rule(i).antecedent)
if fisMat.rule(i).antecedent(j)~=0
if sign(fisMat.rule(i).antecedent(j))==1
x=[x SC(j).fuzzyInput(fisMat.rule(i).antecedent(j))];
else
x=[x (1-SC(j).fuzzyInput(abs(fisMat.rule(i).antecedent(j))))];
end
end
end
if fisMat.rule(i).connection==1
if isequal(fisMat.andMethod,'min')
aux=min(x');
elseif isequal(fisMat.andMethod,'prod')
aux=prod(x');
end
ruleOut=[ruleOut
aux];
else
if isequal(fisMat.orMethod,'max')
aux=max(x');
elseif isequal(fisMat.orMethod,'probor')
aux=probor(x');
end
ruleOut=[ruleOut
aux];
end
for j=1:size(ruleOut,1)
ruleOut(j)=ruleOut(j)^fisMat.rule(j).weight;
end
end

% =========================================================================
function M=fuzzyImplication(fisMat,ruleOut)
N=181;
M=[];
for i=1:length(fisMat.rule)
aux1=ones(1,N)*ruleOut(i);
aux2=evalmf(linspace(fisMat.output.range(1),fisMat.output.range(2),N),fisMat.output.mf(abs(fisMat.rule(i).consequent)).params,fisMat.output.mf(abs(fisMat.rule(i).consequent)).type);
if (fisMat.rule(i).consequent)<0
aux2=1-aux2;
end
if isequal(fisMat.impMethod,'min')
aux=min([aux1;aux2]);
else
aux=prod([aux1;aux2]);
end
if isempty(M)
M=aux;
else
M=[M
aux];
if isequal(fisMat.aggMethod,'sum')
M=sum(M);
elseif isequal(fisMat.aggMethod,'max')
M=max(M);
else
M=probor(M);
end
end
end

% =========================================================================
function Magre=fuzzyAgregation(fisMat,M)
if isequal(fisMat.aggMethod,'sum')
Magre=sum(M);
elseif isequal(fisMat.aggMethod,'max')
Magre=max(M);
else
Magre=probor(M);
end
```