Code covered by the BSD License

Sugeno-type FIS output tuning

Konstantin Sidelnikov (view profile)

12 Aug 2010 (Updated )

Tunes linear parameters of Sugeno-type FIS output using various methods of solving linear equations

kalman(A, B, ~, options)
```function X = kalman(A, B, ~, options)
%KALMAN Uses recursive LSE to estimate output parameters
%
%   It is to be called by SUGENOTUNE as method
%   for solving to linear problem A * X = B.
%
%   It also accepts additional argument variable 'options':
%       options(1) - data forgetting factor (default: 1.0);
%       options(2) - increasing factor of data forgetting
%                    factor (default: 1.0);
%       options(3) - initial diagonal element of
%                    covariance matrix (default: 1E4);
%       options(4) - info display during iteration (default: 1).
%
%
%   Example:
%       A = rand(5, 4);
%       B = rand(5, 2);
%       X = kalman(A, B);

%   References:
%   1. Jang, J.-S. R., ANFIS: Adaptive-Network-based Fuzzy Inference
%   Systems, IEEE Transactions on Systems, Man, and Cybernetics, Vol. 23,
%   No. 3, pp. 665-685, 1993.
%   2. Isermann, R., Digital Control Sytems, Springer-Verlag, 1981.

%   Per Konstantin A. Sidelnikov, 2010.

L = size(B, 2);
[M, N] = size(A);

% Set options
default_opts = [1.0, 1.0, 1E4, 1];
if nargin < 4
options = default_opts;
else
if length(options) < length(default_opts)
tmp = default_opts;
tmp(1 : length(options)) = options;
options = tmp;
end
k = find(isnan(options));
options(k) = default_opts(k);
end
lambda = options(1);  % forgetting factor
lambda0 = options(2); % increasing factor of lambda
gamma = options(3);   % diagonal element
display = options(4); % display option

X = zeros(N, L);
for l = 1 : L
% Initial covariance matrix and unknowns
S = diag(repmat(gamma, N, 1));
x = zeros(N, 1);

% Main loop
b = B(:, l);
for k = 0 : M - 1
a = A(k + 1, :);
% Update lambda that converges to 1.0 with rate
% specified by lambda0 (the lesser lambda0 the higher rate)
lambda = lambda0 * lambda + (1 - lambda0);
% Update covariance matrix and unknowns
S = 1 / lambda * (S - S * (a' * a) * S ./ ...
(lambda + a * S * a'));
x = x + S * a' * (b(k + 1) - a * x);

if display
fprintf('%d. Kalman iteration: %d of %d\n', ...
l, k + 1, M);
end
end

X(:, l) = x;
end```