simuff.c

来自「nnToolKit 神经网络工具包是基于 MATLAB 神经网络工具箱自行开发的」· C语言 代码 · 共 469 行 · 第 1/2 页

C
469
字号
      mprhs[5],
      mprhs[6],
      mprhs[7],
      mprhs[8],
      mprhs[9]);
    mplhs[0]
      = Msimuff(
          &mplhs[1],
          &mplhs[2],
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3],
          mprhs[4],
          mprhs[5],
          mprhs[6],
          mprhs[7],
          mprhs[8],
          mprhs[9]);
    mlfRestorePreviousContext(
      0,
      10,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6],
      mprhs[7],
      mprhs[8],
      mprhs[9]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 3 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 3; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

/*
 * The function "Msimuff" is the implementation version of the "simuff"
 * M-function from file "d:\matlab6p5\toolbox\nnet\nnobsolete\simuff.m" (lines
 * 1-48). It contains the actual compiled code for that M-function. It is a
 * static function and must only be called from one of the interface functions,
 * appearing below.
 */
/*
 * function [a1,a2,a3] = simuff(p,w1,b1,f1,w2,b2,f2,w3,b3,f3)
 */
static mxArray * Msimuff(mxArray * * a2,
                         mxArray * * a3,
                         int nargout_,
                         mxArray * p,
                         mxArray * w1,
                         mxArray * b1,
                         mxArray * f1,
                         mxArray * w2,
                         mxArray * b2,
                         mxArray * f2,
                         mxArray * w3,
                         mxArray * b3,
                         mxArray * f3) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_simuff);
    int nargin_ = mclNargin(10, p, w1, b1, f1, w2, b2, f2, w3, b3, f3, NULL);
    mxArray * a1 = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&p);
    mclCopyArray(&w1);
    mclCopyArray(&b1);
    mclCopyArray(&f1);
    mclCopyArray(&w2);
    mclCopyArray(&b2);
    mclCopyArray(&f2);
    mclCopyArray(&w3);
    mclCopyArray(&b3);
    mclCopyArray(&f3);
    /*
     * %SIMUFF Simulate feed-forward network.
     * %  
     * %  This function is obselete.
     * %  Use NNT2FF and SIM to update and simulate your network.
     * 
     * nntobsf('simuff','Use NNT2FF and SIM to update and simulate your network.')
     */
    mlfNntobsf(_mxarray0_, _mxarray2_, NULL);
    /*
     * 
     * %  SIMUFF will simulate networks with up to 3 layers.
     * %  
     * %  SIMUFF(P,W1,B1,'F1',...,Wn,Bn,'Fn')
     * %    P  - Matrix of input (column) vectors.
     * %    Wi - Weight matrix of the ith layer.
     * %    Bi - Bias (column) vector of the ith layer.
     * %    Fi - Transfer function of the ith layer (string).
     * %  Returns output of nth layer.
     * %  
     * %  [A1,A2,...] = SIMUFF(P,W1,B1,'F1',...,Wn,Bn,'Fn')
     * %  Returns:
     * %    Ai - Output of the ith layer.
     * %
     * %  EXAMPLE: [w1,b1,w2,b2] = initff([0 10; -5 5],3,'tansig',2,'purelin');
     * %           p = [2; -3];
     * %           a = simuff(p,w1,b1,'tansig',w2,b2,'purelin')
     * %  
     * %  See also NNSIM, BACKPROP, INITFF, TRAINBPX, TRAINLM.
     * 
     * % Mark Beale, 12-15-93
     * % Copyright 1992-2002 The MathWorks, Inc.
     * % $Revision: 1.11 $  $Date: 2002/03/25 16:54:11 $
     * 
     * if all([4 7 10] ~= nargin),error('Wrong number of input arguments'),end
     */
    if (mlfTobool(mlfAll(mclNe(_mxarray4_, mlfScalar(nargin_)), NULL))) {
        mlfError(_mxarray6_, NULL);
    }
    /*
     * 
     * if nargin == 4
     */
    if (nargin_ == 4) {
        /*
         * a1 = feval(f1,w1*p,b1);
         */
        mlfAssign(
          &a1,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f1, "f1"),
            mclMtimes(mclVa(w1, "w1"), mclVa(p, "p")),
            mclVa(b1, "b1"),
            NULL));
    /*
     * 
     * elseif nargin == 7
     */
    } else if (nargin_ == 7) {
        /*
         * a1 = feval(f1,w1*p,b1);
         */
        mlfAssign(
          &a1,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f1, "f1"),
            mclMtimes(mclVa(w1, "w1"), mclVa(p, "p")),
            mclVa(b1, "b1"),
            NULL));
        /*
         * a2 = feval(f2,w2*a1,b2);
         */
        mlfAssign(
          a2,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f2, "f2"),
            mclMtimes(mclVa(w2, "w2"), mclVv(a1, "a1")),
            mclVa(b2, "b2"),
            NULL));
        /*
         * if nargout <= 1, a1 = a2; end
         */
        if (nargout_ <= 1) {
            mlfAssign(&a1, mclVv(*a2, "a2"));
        }
    /*
     * 
     * elseif nargin == 10
     */
    } else if (nargin_ == 10) {
        /*
         * a1 = feval(f1,w1*p,b1);
         */
        mlfAssign(
          &a1,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f1, "f1"),
            mclMtimes(mclVa(w1, "w1"), mclVa(p, "p")),
            mclVa(b1, "b1"),
            NULL));
        /*
         * a2 = feval(f2,w2*a1,b2);
         */
        mlfAssign(
          a2,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f2, "f2"),
            mclMtimes(mclVa(w2, "w2"), mclVv(a1, "a1")),
            mclVa(b2, "b2"),
            NULL));
        /*
         * a3 = feval(f3,w3*a2,b3);
         */
        mlfAssign(
          a3,
          mlfFeval(
            mclValueVarargout(),
            mclVa(f3, "f3"),
            mclMtimes(mclVa(w3, "w3"), mclVv(*a2, "a2")),
            mclVa(b3, "b3"),
            NULL));
        /*
         * if nargout <= 1, a1 = a3; end
         */
        if (nargout_ <= 1) {
            mlfAssign(&a1, mclVv(*a3, "a3"));
        }
    /*
     * end
     */
    }
    mclValidateOutput(a1, 1, nargout_, "a1", "simuff");
    mclValidateOutput(*a2, 2, nargout_, "a2", "simuff");
    mclValidateOutput(*a3, 3, nargout_, "a3", "simuff");
    mxDestroyArray(ans);
    mxDestroyArray(f3);
    mxDestroyArray(b3);
    mxDestroyArray(w3);
    mxDestroyArray(f2);
    mxDestroyArray(b2);
    mxDestroyArray(w2);
    mxDestroyArray(f1);
    mxDestroyArray(b1);
    mxDestroyArray(w1);
    mxDestroyArray(p);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return a1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?