MEX file that gets the derivative of a fuzzy model with respect to its consequents.
MATLAB help:
% FUZDERAFFINE Gets the derivative of a fuzzy model respect its affine consequents.
%
% 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_daffine = fuzderaffine(Fuzzy_Model, Point)
%
% dh_dconseq = fuzderaffine(Fuzzy_Model, Point, out, rule)
%
% 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.
%
% out -> Output for select the rule for the parameter.
%
% rule -> Rule for the output 'out' for the parameter.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzcomb, fuzderantec, 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 output, rule, parameter;
int error=0;
double *Point, *dModel_daffine;
if(nrhs!=2 && nrhs!=4)
if (nlhs>1)
for (int i=0;i<nrhs;i++)
{
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
}
if (mxGetN(prhs[1])!=1)
if (n != mxGetM(prhs[1]))
Point = mxGetPr(prhs[1]);
if (nrhs==4)
{
if ( (mxGetN(prhs[2])!=1) || (mxGetM(prhs[2])!=1))
if ((mxGetN(prhs[3])!=1) || (mxGetM(prhs[3])!=1))
output = ((size_t)*mxGetPr(prhs[2]))-1;
if (output >= m)
rule = ((size_t)*mxGetPr(prhs[3]))-1;
if (rule >= S.
rules(output))
plhs[0] = mxCreateDoubleScalar(1);
if (!plhs[0])
dModel_daffine = mxGetPr(plhs[0]);
(*dModel_daffine) =
derconseq(S, Point, output, rule, (
size_t)0, error);
if (error)
{
mxDestroyArray(plhs[0]);
}
}
else
{
TNT::Array2D<double> dS_daffine =
deraffine(S, Point);
if (dS_daffine.dim1()==0 || dS_daffine.dim2()==0 )
{
mxDestroyArray(plhs[0]);
}
plhs[0] = mxCreateDoubleMatrix(dS_daffine.dim1(), dS_daffine.dim2(),mxREAL);
if (!plhs[0])
dModel_daffine = mxGetPr(plhs[0]);
for (size_t j=0;j<dS_daffine.dim2();j++)
{
for (size_t i=0;i<dS_daffine.dim1();i++)
{
*dModel_daffine = dS_daffine[i][j];
dModel_daffine++;
}
}
}
}