📄 nefopt.m
字号:
function nefopt(fuzzy_error, input_stack, nef_opt);
%NEFOPT NEFCON Optimization function (Nefcon Learning Algorithms)
% This function optimizes the membership functions of the
% fismatrix by using the fuzzy_error and the current input_stack.
% The optimization method is selected by nef_opt.
%
% nefopt(fuzzy_error, input_stack, nef_opt)
%
% See also NEFCON.
% Author: Andreas Nuernberger, TU Braunschweig, August 1996; a.nuernberger@tu-bs.de
% contact: Ludger Merz, DASA-Airbus GmbH, Hamburg; ludger.merz@airbus.de
%globals in users-matrix ablegen (siehe gui handbuch)
global IN_N OUT_N
global IN_MF_N OUT_MF_N FIS_TYPE IN_MF_TYPE OUT_MF_TYPE RULE_N DEFUZZ_METHOD in_bound out_bound
global IMP_METHOD RULE_WEIGHT AND_OR RULE_LIST
global output_stack in_mf_value qualified_out_mf overall_out_mf
global NEFCON_RATE NEFCON_FIS
% local state: 0 : get E and activation; 1 : get E' and move MFs
global NEFCON_RSTATE NEFCON_E
% if using buttons and nefcon1 learning selected
if size(qualified_out_mf,2) ~= RULE_N
return;
end
t=zeros(1, RULE_N);
E=zeros(1, RULE_N);
point_n = 101;
point_n1 = 1.0 / point_n;
IN_PARAM = getfis(NEFCON_FIS, 'inMFParams');
OUT_PARAM = getfis(NEFCON_FIS, 'outMFParams');
if nef_opt == 1, % nefcon I modified
sigma = NEFCON_RATE;
for r=1:RULE_N
%calculate t[r] and E[r] for every rule (algorithm step iv)
if (sum(qualified_out_mf(:, r)) == 0)
%rule r ist not firing
E(r) = 0;
else
%defuzzify output membership function for rule r
t = nefdfz(linspace(out_bound(1), out_bound(2), point_n), ...
qualified_out_mf(:,r)', ...
DEFUZZ_METHOD);
%calculate o[r] the firing strength of Rule R
o = min(in_mf_value(r,:));
E(r) = -o * fuzzy_error * sign(t);
%modify MF v[r] (shift it) - modified algorithm step (v)
outMF = RULE_LIST(r,IN_N+OUT_N);
if strcmp(deblank(OUT_MF_TYPE(outMF,:)), 'trimf')
% immer in Richtung des opt. stellwertes gehen
% event. bestrafen durch verkleinern!
%delta = sigma * E(r) * (OUT_PARAM(outMF,3) - OUT_PARAM(outMF,1));
delta = sigma * E(r) * (OUT_PARAM(outMF,3) - OUT_PARAM(outMF,1));
delta = delta * sign(t);
%check out_bound (peak must stay in bounds)
if (delta > 0)
delta = min(OUT_PARAM(outMF,2) - out_bound(1), delta);
else
delta = max(OUT_PARAM(outMF,2) - out_bound(2), delta);
end
OUT_PARAM(outMF,1) = OUT_PARAM(outMF,1) - delta;
OUT_PARAM(outMF,2) = OUT_PARAM(outMF,2) - delta;
OUT_PARAM(outMF,3) = OUT_PARAM(outMF,3) - delta;
%fprintf('OutMF: Rule outMF= %i, delta= %f, peak= %f, o= %f\n', outMF,delta,OUT_PARAM(outMF,2),o);
elseif strcmp(deblank(OUT_MF_TYPE(outMF,:)), 'trapmf')
delta = sigma * E(r) * (OUT_PARAM(outMF,4) - OUT_PARAM(outMF,1));
delta = delta * sign(t);
%check out_bound (peak must stay in bounds)
if (delta > 0)
delta = min(OUT_PARAM(outMF,2) - out_bound(1), delta);
else
delta = max(OUT_PARAM(outMF,3) - out_bound(2), delta);
end
OUT_PARAM(outMF,1) = OUT_PARAM(outMF,1) - delta;
OUT_PARAM(outMF,2) = OUT_PARAM(outMF,2) - delta;
OUT_PARAM(outMF,3) = OUT_PARAM(outMF,3) - delta;
OUT_PARAM(outMF,4) = OUT_PARAM(outMF,4) - delta;
elseif strcmp(deblank(OUT_MF_TYPE(outMF,:)), 'gaussmf')
% calculate base of gaussmf
delta = sigma * E(r) * (4.7*OUT_PARAM(outMF,1));
delta = delta * sign(t);
%check out_bound (peak must stay in bounds)
if (delta > 0)
delta = min(OUT_PARAM(outMF,2) - out_bound(1), delta);
else
delta = max(OUT_PARAM(outMF,2) - out_bound(2), delta);
end
% move center
OUT_PARAM(outMF,2) = OUT_PARAM(outMF,2) - delta;
else
disp('Unsupported OutMFType - not modified');
end
%modify MF u[j[r]] - algorithm step (vi)
for i = 1:IN_N
% find actual MF
inMF = RULE_LIST(r,i);
%fprintf('Rule r= %i, i= %i , inMF= %i \n', r,i,inMF);
% check if any MF is active
if (inMF ~= 0)
%skip MF's of Inputs 1..i-1
firstMF = 0; % ersetzen durch sum(...)
for j = 1:(i-1)
firstMF = firstMF + IN_MF_N(1,j);
end
inMF = inMF + firstMF;
%fprintf('Rule r= %i, i= %i , inMF= %i \n', r,i,inMF);
if strcmp(deblank(IN_MF_TYPE(inMF,:)), 'trimf')
%check bounds
%IN_PARAM
lb = IN_PARAM(inMF,1);
rb = IN_PARAM(inMF,3);
delta = -sigma * E(r) * (IN_PARAM(inMF,2) - lb);
lb = lb - delta;
delta = sigma * E(r) * (rb - IN_PARAM(inMF,2));
rb = rb - delta;
if 0
IN_PARAM(inMF,1) = lb;
IN_PARAM(inMF,3) = rb;
else
%躡erdeckungspr黦ungen ev. ebenfalls abschalten k鰊nen
% r鋘dern d黵fen 黚erschritten werden, aber max. 黚erschreitung beschr鋘ken
% (sonst senkrechte kante f黵 a=b oder b=c)
de = (in_bound(i, 2) - in_bound(i, 1)) * point_n1;
if (lb <= in_bound(i, 1))
IN_PARAM(inMF,1) = max(in_bound(i, 1) - de, lb);
else
% 黚erdeckungpr黤ung
stat = 0;
for j = (firstMF + 1) : (firstMF + IN_MF_N(1,i))
if (inMF ~= j) & (IN_PARAM(j,1) < lb-de) & (lb+de < IN_PARAM(j,3))
stat = 1;
end
end
if stat == 1
IN_PARAM(inMF,1) = lb;
end
end
if (rb >= in_bound(i, 2))
IN_PARAM(inMF,3) = min(in_bound(i, 2) + de, rb);
else
% 黚erdeckungpr黤ung
stat = 0;
for j = (firstMF + 1) : (firstMF + IN_MF_N(1,i))
if (inMF ~= j) & (IN_PARAM(j,1) < rb) & (rb < IN_PARAM(j,3))
stat = 1;
end
end
if stat == 1
IN_PARAM(inMF,3) = rb;
end
end
end
elseif strcmp(deblank(IN_MF_TYPE(inMF,:)), 'trapmf')
lb = IN_PARAM(inMF,2);
rb = IN_PARAM(inMF,3);
diff = rb - lb;
delta = -sigma * E(r) * diff;
lb = lb - delta;
rb = rb + delta;
IN_PARAM(inMF,1) = IN_PARAM(inMF,1) - delta;
IN_PARAM(inMF,2) = lb;
IN_PARAM(inMF,3) = rb;
IN_PARAM(inMF,4) = IN_PARAM(inMF,4) + delta;
elseif strcmp(deblank(IN_MF_TYPE(inMF,:)), 'gaussmf')
diff = IN_PARAM(inMF,1)*2.35;
delta = sigma * E(r) * diff;
IN_PARAM(inMF,1) = IN_PARAM(inMF,1) - delta;
else
disp('Unsupported InMFType - not modified');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -