%% Fuzzy_Paper Implementation : 
%  IEEE TRANSACTIONS ON FUZZY SYSTEMS, VOL. 20, NO. 4, AUGUST 2012
%  ---------------------------------------------------------------
%  Compute Derivative of Error With respect to the modulation parameter : 

function [ErDrvtC, ErDrvtSig] = computeErrorDrvt(X, Y, C, Sig, D)

    ErDrvtC = zeros(size(C));
    ErDrvtSig = zeros(size(Sig));

    A = computeA(X, C, Sig); 
    Coef = (A*D - Y)*D';
    
    for c=1:size(C, 1)
        for i=1:size(X, 1)
            [alphaDrvtC, alphaDrvtSig, Mu] = firingStrngthDrvt(X(i, :), C(c, :), Sig(c, :)); 
            Cf = Coef(i, c:size(C, 1):end)*[1, X(i, :)]'; 
%             ErDrvtC(c, :) = ErDrvtC(c, :) + Cf*mysoftmin(Mu)*alphaDrvtC; 
%             ErDrvtSig(c, :) = ErDrvtSig(c, :) + Cf*mysoftmin(Mu)*alphaDrvtSig;          
            ErDrvtC(c, :) = ErDrvtC(c, :) + Cf*prod(Mu)*alphaDrvtC; 
            ErDrvtSig(c, :) = ErDrvtSig(c, :) + Cf*prod(Mu)*alphaDrvtSig; 
        end
    end

end











