⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compet.c

📁 nnToolKit 神经网络工具包是基于 MATLAB 神经网络工具箱自行开发的一组神经网络算法函数库
💻 C
📖 第 1 页 / 共 2 页
字号:
    mxArray * a = NULL;
    mxArray * indn = NULL;
    mxArray * maxn = NULL;
    mxArray * Q = NULL;
    mxArray * S = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&n);
    mclCopyArray(&b);
    /*
     * %COMPET Competitive transfer function.
     * %  
     * %  Syntax
     * %
     * %    A = compet(N)
     * %    info = compet(code)
     * %
     * %  Description
     * %  
     * %    COMPET is a transfer function.  Transfer functions
     * %    calculate a layer's output from its net input.
     * %  
     * %    COMPET(N) takes one input argument,
     * %      N - SxQ matrix of net input (column) vectors.
     * %    and returns output vectors with 1 where each net input
     * %    vector has its maximum value, and 0 elsewhere.
     * %  
     * %    COMPET(code) returns information about this function.
     * %    These codes are defined:
     * %      'deriv'  - Name of derivative function.
     * %      'name'   - Full name.
     * %      'output' - Output range.
     * %      'active' - Active input range.
     * %
     * %    COMPET does not have a derivative function.
     * %  
     * %  Examples
     * %
     * %    Here we define a net input vector N, calculate the output,
     * %    and plot both with bar graphs.
     * %
     * %      n = [0; 1; -0.5; 0.5];
     * %      a = compet(n);
     * %      subplot(2,1,1), bar(n), ylabel('n')
     * %      subplot(2,1,2), bar(a), ylabel('a')
     * %
     * %  Network Use
     * %
     * %    You can create a standard network that uses COMPET
     * %    by calling NEWC or NEWPNN.
     * %
     * %    To change a network so a layer uses COMPET set
     * %    NET.layers{i,j}.transferFcn to 'compet'.
     * %
     * %    In either case, call SIM to simulate the network with COMPET.
     * %    See NEWC or NEWPNN for simulation examples.
     * %
     * %  See also SIM, SOFTMAX.
     * 
     * % Mark Beale, 1-31-92
     * % Revised 12-15-93, MB
     * % Revised 11-31-97, MB
     * % Copyright 1992-2002 The MathWorks, Inc.
     * % $Revision: 1.10 $  $Date: 2002/03/25 16:52:37 $
     * 
     * if nargin < 1,error('Not enough arguments.'); end
     */
    if (nargin_ < 1) {
        mlfError(_mxarray0_, NULL);
    }
    /*
     * 
     * % FUNCTION INFO
     * if isstr(n)
     */
    if (mlfTobool(mlfIsstr(mclVa(n, "n")))) {
        /*
         * switch (n)
         */
        mxArray * v_ = mclInitialize(mclVa(n, "n"));
        if (mclSwitchCompare(v_, _mxarray2_)) {
            /*
             * case 'deriv',
             * a = '';
             */
            mlfAssign(&a, _mxarray4_);
        /*
         * case 'name',
         */
        } else if (mclSwitchCompare(v_, _mxarray5_)) {
            /*
             * a = 'Competitive';
             */
            mlfAssign(&a, _mxarray7_);
        /*
         * case 'output',
         */
        } else if (mclSwitchCompare(v_, _mxarray9_)) {
            /*
             * a = [0 1];
             */
            mlfAssign(&a, _mxarray11_);
        /*
         * case 'active',
         */
        } else if (mclSwitchCompare(v_, _mxarray13_)) {
            /*
             * a = [-inf inf];
             */
            mlfAssign(&a, _mxarray15_);
        /*
         * case 'type',
         */
        } else if (mclSwitchCompare(v_, _mxarray17_)) {
            /*
             * a = 2;
             */
            mlfAssign(&a, _mxarray19_);
        /*
         * 
         * % **[ NNT2 Support ]**
         * case 'delta',
         */
        } else if (mclSwitchCompare(v_, _mxarray20_)) {
            /*
             * a = 'none';
             */
            mlfAssign(&a, _mxarray22_);
            /*
             * nntobsu('compet','Use COMPET(''deriv'') instead of COMPET(''delta'').')
             */
            mlfNntobsu(_mxarray24_, _mxarray26_, NULL);
        /*
         * case 'init',
         */
        } else if (mclSwitchCompare(v_, _mxarray28_)) {
            /*
             * a = 'midpoint';
             */
            mlfAssign(&a, _mxarray30_);
            /*
             * nntobsu('compet','Use network propreties to obtain initialization info.')
             */
            mlfNntobsu(_mxarray24_, _mxarray32_, NULL);
        /*
         * 
         * otherwise
         */
        } else {
            /*
             * error('Unrecognized code.')
             */
            mlfError(_mxarray34_, NULL);
        /*
         * end
         */
        }
        mxDestroyArray(v_);
        /*
         * return
         */
        goto return_;
    /*
     * end
     */
    }
    /*
     * 
     * % CALCULATION
     * 
     * % **[ NNT2 Support ]**
     * if nargin == 2  
     */
    if (nargin_ == 2) {
        /*
         * nntobsu('compet','Use COMPET(NETSUM(Z,B)) instead of COMPET(Z,B).')
         */
        mlfNntobsu(_mxarray24_, _mxarray36_, NULL);
        /*
         * n = n + b(:,ones(1,size(n,2)));
         */
        mlfAssign(
          &n,
          mclPlus(
            mclVa(n, "n"),
            mclArrayRef2(
              mclVa(b, "b"),
              mlfCreateColonIndex(),
              mlfOnes(
                _mxarray38_,
                mlfSize(mclValueVarargout(), mclVa(n, "n"), _mxarray19_),
                NULL))));
    /*
     * end
     */
    }
    /*
     * 
     * [S,Q] = size(n);
     */
    mlfSize(mlfVarargout(&S, &Q, NULL), mclVa(n, "n"), NULL);
    /*
     * [maxn,indn] = max(n,[],1);
     */
    mlfAssign(&maxn, mlfMax(&indn, mclVa(n, "n"), _mxarray39_, _mxarray38_));
    /*
     * a = sparse(indn,1:Q,ones(1,Q),S,Q);
     */
    mlfAssign(
      &a,
      mlfSparse(
        mclVv(indn, "indn"),
        mlfColon(_mxarray38_, mclVv(Q, "Q"), NULL),
        mlfOnes(_mxarray38_, mclVv(Q, "Q"), NULL),
        mclVv(S, "S"),
        mclVv(Q, "Q"),
        NULL));
    return_:
    mclValidateOutput(a, 1, nargout_, "a", "compet");
    mxDestroyArray(ans);
    mxDestroyArray(S);
    mxDestroyArray(Q);
    mxDestroyArray(maxn);
    mxDestroyArray(indn);
    mxDestroyArray(b);
    mxDestroyArray(n);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return a;
}

⌨️ 快捷键说明

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