MEX file that gets the derivative of a fuzzy model with respect to its antecedents.
MATLAB help:
% FUZDERANTEC Gets the derivatives of a fuzzy model respect its antecedents.
%
% It is assumed that the output of the system is the same as the parameter,
% otherwise it should be considered derivative equal to 0.
%
% dh_dantec = fuzderconseq(Fuzzy_Model, Point)
%
% dh_dantec = fuzderconseq(Fuzzy_Model, Point, input, out, rule, parameter)
%
% Arguments:
%
% Fuzzy_Model -> This fuzzy model could be a '.txt' file, a '.fis' file,
% or a 'FIS' variable from MATLAB Workspace.
%
% Point -> Point where the derivative will be calculate.
%
% input -> Input for the parameter.
%
% out -> Output for select the rule for the parameter.
%
% rule -> Rule for the output 'out' for the parameter.
%
% parameter -> Parameter of the antecedent.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzcomb, fuzderconseq, fuzderparam, fuzeval, fuzjac,
% fuzlinear, fuzprint, mat2antec, mat2conseq, mat2fuz, fuzsubsystem,
% txt2fis
Source code:
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t input, output, rule, param, m;
int error=0;
double *Point, *dModel_dantec;
if(nrhs!=2 && nrhs!=6)
if (nlhs>1)
for (int i=0;i<nrhs;i++)
{
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
}
if (1 != mxGetN(prhs[1]))
if (S.
inputs() != mxGetM(prhs[1]))
Point = mxGetPr(prhs[1]);
if (nrhs==6)
{
if ((mxGetN(prhs[2])!=1) || (mxGetM(prhs[2])!=1))
if ((mxGetN(prhs[3])!=1) || (mxGetM(prhs[3])!=1))
if ((mxGetN(prhs[4])!=1) || (mxGetM(prhs[4])!=1))
if ((mxGetN(prhs[5])!=1) || (mxGetM(prhs[4])!=1))
input = ((size_t)*mxGetPr(prhs[2]))-1;
output = ((size_t)*mxGetPr(prhs[3]))-1;
rule = ((size_t)*mxGetPr(prhs[4]))-1;
if (rule >= S.
rules(output))
param = ((size_t)*mxGetPr(prhs[5]))-1;
{
plhs[0]=mxCreateDoubleMatrix(0,0,mxREAL);
if (!plhs[0])
return;
}
plhs[0] = mxCreateDoubleScalar(1);
if (!plhs[0])
dModel_dantec = mxGetPr(plhs[0]);
(*dModel_dantec) =
derantec(S, Point, input, output, rule, param, error);
if (error)
{
mxDestroyArray(plhs[0]);
}
}
else
{
if (!plhs[0])
dModel_dantec=mxGetPr(plhs[0]);
TNT::Array2D<double> dS_dantec =
derantec(S, Point);
if (dS_dantec.dim1()==0 || dS_dantec.dim2()==0 )
{
mxDestroyArray(plhs[0]);
}
for (size_t j=0;j<dS_dantec.dim2();j++)
{
for (size_t i=0;i<dS_dantec.dim1();i++)
{
*dModel_dantec = dS_dantec[i][j];
dModel_dantec++;
}
}
}
}