MEX file that calculates an iteration of EKF only for consequents.
MATLAB help:
function [Model, P, err] = Kalmanconseq(Model, inputs, outputs, covariance, P)
% KALMANCONSEQ. Calculates an iteration of EKF only for consequents.
%
% [Model, P, err] = Kalmanconseq(Model, inputs, outputs, covariance, P)
%
% [Model, P, err] = Kalmanconseq(Model, inputs, outputs, covariance, P, Phi)
%
% Arguments:
%
% Model -> This fuzzy model could be a '.txt' file, a '.fis' file,
% or a 'FIS' variable from MATLAB Workspace.
%
% inputs -> Current input vector.
%
% outputs -> Real outputs of the system in the current iteration.
%
% covariance -> Noise covariance matrix estimated from the hope operator.
%
% P -> Covariance matrix of the filter.
%
% Phi -> Jacobian matrix that relates the parameters to be set with the
% following value of these parameters.
% If not specified, Phi is assumed to be the identity matrix.
%
% See also Kalmanantec, Kalmanfuz, activation, antec2mat, aproxjac, aproxlinear
% conseq2mat, fis2txt, fuz2mat, fuzcomb, fuzeval, fuzjac, fuzlinear,
% fuzprint, mat2antec, mat2conseq, mat2fuz, fuzsubsystem, txt2fis
Source code:
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if(nrhs<5 | nrhs>6)
if (nlhs>3)
for (size_t i=0;i<nrhs;i++)
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
double *p_input = mxGetPr(prhs[1]);
if (!p_input)
int n = mxGetM(prhs[1]);
if (n==1)
n = mxGetN(prhs[1]);
Array1D<double> input(n, p_input);
double *p_output = mxGetPr(prhs[2]);
if (!p_output)
n = mxGetM(prhs[2]);
if (n==1)
n = mxGetN(prhs[2]);
Array1D<double> output(n, p_output);
double *p_covariance = mxGetPr(prhs[3]);
if (!p_covariance)
double *p_P = mxGetPr(prhs[4]);
if (!p_P)
n = mxGetM(prhs[4]);
Array1D<double> error;
if (nrhs==5)
else
{
double *p_Phi = mxGetPr(prhs[5]);
if (!p_Phi)
error =
KalmanConseq(Model, input, output, covariance, P, Phi);
}
if (error.dim() == 0)
const char* names[]={"name","type","andMethod","orMethod","defuzzMethod","impMethod","aggMethod","input","output","rule"};
mwSize dim[] = {1,1};
plhs[0] = mxCreateStructArray(2,dim,10,names);
{
mxDestroyArray(plhs[0]);
}
if (nlhs>1)
{
plhs[1] = mxCreateDoubleMatrix(n,n,mxREAL);
double *p_newP = mxGetPr(plhs[1]);
if (!p_newP)
{
mxDestroyArray(plhs[0]);
mxDestroyArray(plhs[1]);
}
if (nlhs>2)
{
plhs[2] = mxCreateDoubleMatrix(m,1,mxREAL);
double *p_error = mxGetPr(plhs[2]);
if (!p_error)
{
mxDestroyArray(plhs[0]);
mxDestroyArray(plhs[1]);
mxDestroyArray(plhs[2]);
}
for (size_t i=0;i<m;i++)
{
*p_error = error[i];
p_error++;
}
}
}
}