📄 logsig.c
字号:
/*
* MATLAB Compiler: 3.0
* Date: Sun May 13 16:47:40 2007
* Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
* "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
* "array_indexing:on" "-O" "optimize_conditionals:on" "-M" "-silentsetup" "-d"
* "d:/MATLAB6p5/work/nnToolKit/src" "-B" "csglcom:nnToolKit,nnToolKit,2.0"
* "-B" "sgl" "-m" "-W" "main" "-L" "C" "-t" "-T" "link:exe" "-h"
* "libmmfile.mlib" "-W" "mainhg" "libmwsglm.mlib" "-t" "-W"
* "comhg:nnToolKit,nnToolKit,2.0" "-T" "link:lib" "-h" "libmmfile.mlib" "-i"
* "-i" "D:/MATLAB6p5/work/nnToolKit/lmnet/LmSimu.m"
* "D:/MATLAB6p5/work/nnToolKit/lmnet/LmTrain.m"
* "D:/MATLAB6p5/work/nnToolKit/sofm/SofmSimu.m"
* "D:/MATLAB6p5/work/nnToolKit/sofm/SofmTrain.m"
*/
#include "logsig.h"
#include "libmatlbm.h"
#include "nntobsu.h"
static mxChar _array1_[22] = { 'N', 'o', 't', 'e', ' ', 'e', 'n', 'o',
'u', 'g', 'h', ' ', 'a', 'r', 'g', 'u',
'm', 'e', 'n', 't', 's', '.' };
static mxArray * _mxarray0_;
static mxChar _array3_[5] = { 'd', 'e', 'r', 'i', 'v' };
static mxArray * _mxarray2_;
static mxChar _array5_[7] = { 'd', 'l', 'o', 'g', 's', 'i', 'g' };
static mxArray * _mxarray4_;
static mxChar _array7_[4] = { 'n', 'a', 'm', 'e' };
static mxArray * _mxarray6_;
static mxChar _array9_[11] = { 'L', 'o', 'g', ' ', 'S', 'i',
'g', 'm', 'o', 'i', 'd' };
static mxArray * _mxarray8_;
static mxChar _array11_[6] = { 'o', 'u', 't', 'p', 'u', 't' };
static mxArray * _mxarray10_;
static double _array13_[2] = { 0.0, 1.0 };
static mxArray * _mxarray12_;
static mxChar _array15_[6] = { 'a', 'c', 't', 'i', 'v', 'e' };
static mxArray * _mxarray14_;
static double _array17_[2] = { -4.0, 4.0 };
static mxArray * _mxarray16_;
static mxChar _array19_[4] = { 't', 'y', 'p', 'e' };
static mxArray * _mxarray18_;
static mxArray * _mxarray20_;
static mxChar _array22_[5] = { 'd', 'e', 'l', 't', 'a' };
static mxArray * _mxarray21_;
static mxChar _array24_[8] = { 'd', 'e', 'l', 't', 'a', 'l', 'o', 'g' };
static mxArray * _mxarray23_;
static mxChar _array26_[6] = { 'l', 'o', 'g', 's', 'i', 'g' };
static mxArray * _mxarray25_;
static mxChar _array28_[47] = { 'U', 's', 'e', ' ', 'L', 'O', 'G', 'S',
'I', 'G', '(', 0x0027, 'd', 'e', 'r', 'i',
'v', 0x0027, ')', ' ', 'i', 'n', 's', 't',
'e', 'a', 'd', ' ', 'o', 'f', ' ', 'L',
'O', 'G', 'S', 'I', 'G', '(', 0x0027, 'd',
'e', 'l', 't', 'a', 0x0027, ')', '.' };
static mxArray * _mxarray27_;
static mxChar _array30_[4] = { 'i', 'n', 'i', 't' };
static mxArray * _mxarray29_;
static mxChar _array32_[5] = { 'n', 'w', 'l', 'o', 'g' };
static mxArray * _mxarray31_;
static mxChar _array34_[53] = { 'U', 's', 'e', ' ', 'n', 'e', 't', 'w', 'o',
'r', 'k', ' ', 'p', 'r', 'o', 'p', 'r', 'e',
't', 'i', 'e', 's', ' ', 't', 'o', ' ', 'o',
'b', 't', 'a', 'i', 'n', ' ', 'i', 'n', 'i',
't', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i',
'o', 'n', ' ', 'i', 'n', 'f', 'o', '.' };
static mxArray * _mxarray33_;
static mxChar _array36_[18] = { 'U', 'n', 'r', 'e', 'c', 'o', 'g', 'n', 'i',
'z', 'e', 'd', ' ', 'c', 'o', 'd', 'e', '.' };
static mxArray * _mxarray35_;
static mxArray * _mxarray37_;
static mxChar _array39_[47] = { 'U', 's', 'e', ' ', 'L', 'O', 'G', 'S',
'I', 'G', '(', 'N', 'E', 'T', 'S', 'U',
'M', '(', 'Z', ',', 'B', ')', ')', ' ',
'i', 'n', 's', 't', 'e', 'a', 'd', ' ',
'o', 'f', ' ', 'L', 'O', 'G', 'S', 'I',
'G', '(', 'Z', ',', 'B', ')', '.' };
static mxArray * _mxarray38_;
void InitializeModule_logsig(void) {
_mxarray0_ = mclInitializeString(22, _array1_);
_mxarray2_ = mclInitializeString(5, _array3_);
_mxarray4_ = mclInitializeString(7, _array5_);
_mxarray6_ = mclInitializeString(4, _array7_);
_mxarray8_ = mclInitializeString(11, _array9_);
_mxarray10_ = mclInitializeString(6, _array11_);
_mxarray12_ = mclInitializeDoubleVector(1, 2, _array13_);
_mxarray14_ = mclInitializeString(6, _array15_);
_mxarray16_ = mclInitializeDoubleVector(1, 2, _array17_);
_mxarray18_ = mclInitializeString(4, _array19_);
_mxarray20_ = mclInitializeDouble(1.0);
_mxarray21_ = mclInitializeString(5, _array22_);
_mxarray23_ = mclInitializeString(8, _array24_);
_mxarray25_ = mclInitializeString(6, _array26_);
_mxarray27_ = mclInitializeString(47, _array28_);
_mxarray29_ = mclInitializeString(4, _array30_);
_mxarray31_ = mclInitializeString(5, _array32_);
_mxarray33_ = mclInitializeString(53, _array34_);
_mxarray35_ = mclInitializeString(18, _array36_);
_mxarray37_ = mclInitializeDouble(2.0);
_mxarray38_ = mclInitializeString(47, _array39_);
}
void TerminateModule_logsig(void) {
mxDestroyArray(_mxarray38_);
mxDestroyArray(_mxarray37_);
mxDestroyArray(_mxarray35_);
mxDestroyArray(_mxarray33_);
mxDestroyArray(_mxarray31_);
mxDestroyArray(_mxarray29_);
mxDestroyArray(_mxarray27_);
mxDestroyArray(_mxarray25_);
mxDestroyArray(_mxarray23_);
mxDestroyArray(_mxarray21_);
mxDestroyArray(_mxarray20_);
mxDestroyArray(_mxarray18_);
mxDestroyArray(_mxarray16_);
mxDestroyArray(_mxarray14_);
mxDestroyArray(_mxarray12_);
mxDestroyArray(_mxarray10_);
mxDestroyArray(_mxarray8_);
mxDestroyArray(_mxarray6_);
mxDestroyArray(_mxarray4_);
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Mlogsig(int nargout_, mxArray * n, mxArray * b);
_mexLocalFunctionTable _local_function_table_logsig
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfLogsig" contains the normal interface for the "logsig"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\logsig.m" (lines 1-95).
* This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
mxArray * mlfLogsig(mxArray * n, mxArray * b) {
int nargout = 1;
mxArray * a = NULL;
mlfEnterNewContext(0, 2, n, b);
a = Mlogsig(nargout, n, b);
mlfRestorePreviousContext(0, 2, n, b);
return mlfReturnValue(a);
}
/*
* The function "mlxLogsig" contains the feval interface for the "logsig"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\logsig.m" (lines 1-95).
* The feval function calls the implementation version of logsig through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
void mlxLogsig(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[2];
mxArray * mplhs[1];
int i;
if (nlhs > 1) {
mlfError(
mxCreateString(
"Run-time Error: File: logsig Line: 1 Column: "
"1 The function \"logsig\" was called with mor"
"e than the declared number of outputs (1)."),
NULL);
}
if (nrhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: logsig Line: 1 Column: "
"1 The function \"logsig\" was called with mor"
"e than the declared number of inputs (2)."),
NULL);
}
for (i = 0; i < 1; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 2 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 2; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
mplhs[0] = Mlogsig(nlhs, mprhs[0], mprhs[1]);
mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0];
}
/*
* The function "Mlogsig" is the implementation version of the "logsig"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\logsig.m" (lines 1-95).
* 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 a = logsig(n,b)
*/
static mxArray * Mlogsig(int nargout_, mxArray * n, mxArray * b) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_logsig);
int nargin_ = mclNargin(2, n, b, NULL);
mxArray * a = NULL;
mxArray * i = NULL;
mxArray * ans = NULL;
mclCopyArray(&n);
mclCopyArray(&b);
/*
* %LOGSIG Logarithmic sigmoid transfer function.
* %
* % Syntax
* %
* % A = logsig(N)
* % info = logsig(code)
* %
* % Description
* %
* % LOGSIG is a transfer function. Transfer functions
* % calculate a layer's output from its net input.
* %
* % LOGSIG(N) takes one input,
* % N - SxQ matrix of net input (column) vectors.
* % and returns each element of N squashed between 0 and 1.
* %
* % LOGSIG(CODE) returns useful information for each CODE string:
* % 'deriv' - Returns name of derivative function.
* % 'name' - Returns full name.
* % 'output' - Returns output range.
* % 'active' - Returns active input range.
* %
* % Examples
* %
* % Here is code for creating a plot of the LOGSIG transfer function.
* %
* % n = -5:0.1:5;
* % a = logsig(n);
* % plot(n,a)
* %
* % Network Use
* %
* % You can create a standard network that uses LOGSIG
* % by calling NEWFF or NEWCF.
* %
* % To change a network so a layer uses LOGSIG set
* % NET.layers{i}.transferFcn to 'logsig'.
* %
* % In either case, call SIM to simulate the network with PURELIN.
* % See NEWFF or NEWCF for simulation examples.
* %
* % Algorithm
* %
* % logsig(n) = 1 / (1 + exp(-n))
* %
* % See also SIM, DLOGSIG, TANSIG.
*
* % Mark Beale, 1-31-92
* % Revised 12-15-93, MB
* % Revised 11-31-97, MB
* % Copyright 1992-2002 The MathWorks, Inc.
* % $Revision: 1.11 $ $Date: 2002/03/25 16:53:16 $
*
* if nargin < 1, error('Note 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 = 'dlogsig';
*/
mlfAssign(&a, _mxarray4_);
/*
* case 'name'
*/
} else if (mclSwitchCompare(v_, _mxarray6_)) {
/*
* a = 'Log Sigmoid';
*/
mlfAssign(&a, _mxarray8_);
/*
* case 'output'
*/
} else if (mclSwitchCompare(v_, _mxarray10_)) {
/*
* a = [0 1];
*/
mlfAssign(&a, _mxarray12_);
/*
* case 'active'
*/
} else if (mclSwitchCompare(v_, _mxarray14_)) {
/*
* a = [-4 +4];
*/
mlfAssign(&a, _mxarray16_);
/*
* case 'type'
*/
} else if (mclSwitchCompare(v_, _mxarray18_)) {
/*
* a = 1;
*/
mlfAssign(&a, _mxarray20_);
/*
*
* % **[ NNT2 Support ]**
* case 'delta'
*/
} else if (mclSwitchCompare(v_, _mxarray21_)) {
/*
* a = 'deltalog';
*/
mlfAssign(&a, _mxarray23_);
/*
* nntobsu('logsig','Use LOGSIG(''deriv'') instead of LOGSIG(''delta'').')
*/
mlfNntobsu(_mxarray25_, _mxarray27_, NULL);
/*
* case 'init'
*/
} else if (mclSwitchCompare(v_, _mxarray29_)) {
/*
* a = 'nwlog';
*/
mlfAssign(&a, _mxarray31_);
/*
* nntobsu('logsig','Use network propreties to obtain initialization info.')
*/
mlfNntobsu(_mxarray25_, _mxarray33_, NULL);
/*
*
* otherwise, error('Unrecognized code.')
*/
} else {
mlfError(_mxarray35_, NULL);
/*
* end
*/
}
mxDestroyArray(v_);
/*
* return
*/
goto return_;
/*
* end
*/
}
/*
*
* % CALCULATION
*
* % **[ NNT2 Support ]**
* if nargin == 2
*/
if (nargin_ == 2) {
/*
* n=n+b(:,ones(1,size(n,2)));
*/
mlfAssign(
&n,
mclPlus(
mclVa(n, "n"),
mclArrayRef2(
mclVa(b, "b"),
mlfCreateColonIndex(),
mlfOnes(
_mxarray20_,
mlfSize(mclValueVarargout(), mclVa(n, "n"), _mxarray37_),
NULL))));
/*
* nntobsu('logsig','Use LOGSIG(NETSUM(Z,B)) instead of LOGSIG(Z,B).')
*/
mlfNntobsu(_mxarray25_, _mxarray38_, NULL);
/*
* end
*/
}
/*
*
* a = 1 ./ (1 + exp(-n));
*/
mlfAssign(
&a,
mclRdivide(
_mxarray20_, mclPlus(_mxarray20_, mlfExp(mclUminus(mclVa(n, "n"))))));
/*
* i = find(~finite(a));
*/
mlfAssign(&i, mlfFind(NULL, NULL, mclNot(mlfFinite(mclVv(a, "a")))));
/*
* a(i) = sign(n(i));
*/
mclArrayAssign1(
&a, mlfSign(mclArrayRef1(mclVa(n, "n"), mclVv(i, "i"))), mclVv(i, "i"));
return_:
mclValidateOutput(a, 1, nargout_, "a", "logsig");
mxDestroyArray(ans);
mxDestroyArray(i);
mxDestroyArray(b);
mxDestroyArray(n);
mclSetCurrentLocalFunctionTable(save_local_function_table_);
return a;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -