📄 nefrules.m
字号:
function nefrules(fuzzy_error, input_stack, nef_rule);
%NEFRULES Rule learning function (Phase1)
% This function learns the rules of the
% fismatrix by using the fuzzy_error and the current input_stack.
% The rule learning method is selected by nef_rule.
%
% nefrules(fuzzy_error, input_stack, nef_rule)
%
% 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
global IN_N O 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 IN_PARAM OUT_PARAM
global output_stack in_mf_value qualified_out_mf overall_out_mf
global NEFCON_C
global NEFCON_FIS
global NEFCON_RRATE NEFCON_RPER
if nef_rule == 1, % 'bottom-up' rule learning
% look for MF's in input set's which match best input (step i)
mfElemIn = zeros(1, IN_N);
pos = 1;
for i = 1 : IN_N, % inputs
maxAct = 0;
for j = 1 : IN_MF_N(1,i) % MF's
m = nefevmf(input_stack(i), IN_PARAM(pos,:), IN_MF_TYPE(pos,:));
if m > maxAct,
maxAct = m;
mfElemIn(1,i) = j;
end
pos = pos + 1;
end
end
mfElemOut = zeros(1, OUT_N);
pos = 1;
% look for MF's in output set's which match best heuristic output value o (step ii)
for i = 1 : OUT_N, % outputs (usually one)
%calculate output value (scale to outbounds)
E = fuzzy_error(i);
m = (out_bound(i,2) + out_bound(i,1)) * 0.5;
if E >= 0
o = m + E * (out_bound(i,2) - m);
else
o = m + E * (m - out_bound(i,1));
end
maxAct = 0;
for j = 1 : OUT_MF_N(1,i) % MF's
m = nefevmf(o, OUT_PARAM(pos,:), OUT_MF_TYPE(pos,:));
if m > maxAct,
maxAct = m;
mfElemOut(1,i) = j;
end
pos = pos + 1;
end
end
% look if rule exist (if not - add rule to rulelist) (step iii)
pos = 0;
for i = 1 : RULE_N,
if RULE_LIST(i,1:IN_N) == [mfElemIn],
pos = i;
break;
end
end
if pos == 0, % add rule to rulelist
NEFCON_FIS = addrule(NEFCON_FIS, [mfElemIn mfElemOut 1 1]);
% update globals
RULE_N = RULE_N + 1;
NEFCON_C = [NEFCON_C 0];
tmp = getfis(NEFCON_FIS, 'Rulelist');
RULE_WEIGHT = tmp(:, IN_N+OUT_N+1);
AND_OR = tmp(:, IN_N+OUT_N+2);
RULE_LIST = tmp(:, 1:IN_N+OUT_N);
end
elseif nef_rule == 2, % nefcon rule learning
point_n = 101;
newrlist = [];
newC = [];
delta = (out_bound(2) - out_bound(1)) * NEFCON_RRATE;
for r = 1:RULE_N
% if rule is firing
if (sum(qualified_out_mf(:, r)) ~= 0)
%defuzzify output membership function for rule r (step i.b)
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 (step i.e)
o = min(in_mf_value(r,:)); % (and method)
else
t = 0;
o = 0;
end;
% (step i.c,d)
% if sign(t) == sign(fuzzy_error) | abs(fuzzy_error) < delta | abs(t) < delta | o == 0
if sign(t) == sign(fuzzy_error) | abs(fuzzy_error) < delta | o == 0
newrlist = [newrlist; RULE_LIST(r,:)];
if o > 0
NEFCON_C(r) = NEFCON_C(r) + 1;
end
newC = [newC NEFCON_C(r)];
end
end
RULE_LIST = newrlist;
NEFCON_C = newC;
NEFCON_FIS = setfis(NEFCON_FIS, 'RuleList', [RULE_LIST ones(size(RULE_LIST,1),2)]);
RULE_N = size(RULE_LIST,1);
NEFCON_FIS = setfis(NEFCON_FIS, 'numRules', RULE_N);
else % illegal rule learning or disabled
disp(['nefrules: Rule learning disabled or illegal modus (' nef_rule ').']);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -