MEX file that calculates the fulfillment degree and the derivative of a rule.
MATLAB help:
% ACTIVATION Calculates the fulfillment degree and the derivative of a rule.
%
% W = activation(Fuzzy_Model, Point, out)
%
% [W, SumW] = activation(Fuzzy_Model, Point, out)
%
% For a specific rule:
%
% W = activation(Fuzzy_Model, Point, out, rule)
%
% [W, dW] = activation(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.
%
% out -> Output of the model for select the rule.
%
% rule -> The rule for the output 'out'. If 'rule' is omitted will be
% calculated the degree of activation of all rules of 'out'.
%
% Point -> Point where the fulfillment degree will be calculate.
%
% W -> Matching degree of the rule/s.
%
% SumW -> Sumatory of all fulfillment degrees for the output 'out' => sum(W)
%
% dW -> Derivative of the fulfillment degree. 'rule' must be used.
% Note: dW will be correct only if all inputs of Fuzzy_Model are independent.
%
% See also 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[])
{
size_t i, output, rule, m;
double *Point,*W,*dW, *SumW;
if(nrhs<3 || nrhs>4)
if (nlhs>2)
for (i=0;i<nrhs;i++)
{
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
}
if (1!=mxGetN(prhs[1]))
if (S.
inputs()!=mxGetM(prhs[1]))
if ( (mxGetN(prhs[2])!=1) || (mxGetM(prhs[2])!=1))
if (nrhs==4)
{
if ((mxGetN(prhs[3])!=1) || (mxGetM(prhs[3])!=1))
rule = ((size_t)*mxGetPr(prhs[3]))-1;
if (rule>=S.
rules(output))
}
output = ((size_t)*mxGetPr(prhs[2]))-1;
Point = mxGetPr(prhs[1]);
if (nrhs==4)
{
plhs[0] = mxCreateDoubleScalar(1);
W = mxGetPr(plhs[0]);
if (!plhs[0])
if (nlhs==1)
(*W) = S.
readRule(output,rule)->activation(Point);
else
{
plhs[1] = mxCreateDoubleMatrix(1,m,mxREAL);
dW = mxGetPr(plhs[1]);
(*W) = S.
readRule(output,rule)->activation(Point, dW);
}
}
else
{
plhs[0] = mxCreateDoubleMatrix(1,S.
rules(output),mxREAL);
W = mxGetPr(plhs[0]);
if (!plhs[0])
if (nlhs==2)
{
plhs[1] = mxCreateDoubleScalar(1);
if (!plhs[1])
SumW = mxGetPr(plhs[1]);
*SumW = 0.0;
}
for (rule=0;rule<S.
rules(output);rule++)
{
(*W) = S.
readRule(output,rule)->activation(Point);
if (nlhs==2)
(*SumW) += (*W);
W++;
}
}
}