📄 midpoint.c
字号:
/*
* MATLAB Compiler: 3.0
* Date: Sun May 13 16:47:41 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 "midpoint.h"
#include "libmatlbm.h"
#include "libmmfile.h"
#include "minmax.h"
#include "nntobsu.h"
static mxChar _array1_[21] = { 'N', 'o', 't', ' ', 'e', 'n', 'o',
'u', 'g', 'h', ' ', 'a', 'r', 'g',
'u', 'm', 'e', 'n', 't', 's', '.' };
static mxArray * _mxarray0_;
static mxArray * _mxarray2_;
static mxChar _array4_[8] = { 'm', 'i', 'd', 'p', 'o', 'i', 'n', 't' };
static mxArray * _mxarray3_;
static mxChar _array6_[51] = { 'U', 's', 'e', ' ', 'M', 'I', 'D', 'P', 'O',
'I', 'N', 'T', '(', 'S', ',', 'M', 'I', 'N',
'M', 'A', 'X', '(', 'P', ')', ')', ' ', 'i',
'n', 's', 't', 'e', 'a', 'd', ' ', 'o', 'f',
' ', 'M', 'I', 'D', 'P', 'O', 'I', 'N', 'T',
'(', 'S', ',', 'P', ')', '.' };
static mxArray * _mxarray5_;
static mxArray * _mxarray7_;
static mxChar _array9_[48] = { 'U', 's', 'e', ' ', 'B', '=', 'Z', 'E', 'R', 'O',
'S', '(', 'S', ',', '1', ')', ' ', 'i', 'n', 's',
't', 'e', 'a', 'd', ' ', 'o', 'f', ' ', '[', 'W',
',', 'B', ']', '=', 'M', 'I', 'D', 'P', 'O', 'I',
'N', 'T', '(', '.', '.', '.', ')', '.' };
static mxArray * _mxarray8_;
void InitializeModule_midpoint(void) {
_mxarray0_ = mclInitializeString(21, _array1_);
_mxarray2_ = mclInitializeDouble(2.0);
_mxarray3_ = mclInitializeString(8, _array4_);
_mxarray5_ = mclInitializeString(51, _array6_);
_mxarray7_ = mclInitializeDouble(1.0);
_mxarray8_ = mclInitializeString(48, _array9_);
}
void TerminateModule_midpoint(void) {
mxDestroyArray(_mxarray8_);
mxDestroyArray(_mxarray7_);
mxDestroyArray(_mxarray5_);
mxDestroyArray(_mxarray3_);
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Mmidpoint(mxArray * * b,
int nargout_,
mxArray * s,
mxArray * pr);
_mexLocalFunctionTable _local_function_table_midpoint
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfNMidpoint" contains the nargout interface for the
* "midpoint" M-function from file "d:\matlab6p5\toolbox\nnet\nnet\midpoint.m"
* (lines 1-66). This interface is only produced if the M-function uses the
* special variable "nargout". The nargout interface allows the number of
* requested outputs to be specified via the nargout argument, as opposed to
* the normal interface which dynamically calculates the number of outputs
* based on the number of non-NULL inputs it receives. This function processes
* any input arguments and passes them to the implementation version of the
* function, appearing above.
*/
mxArray * mlfNMidpoint(int nargout, mxArray * * b, mxArray * s, mxArray * pr) {
mxArray * w = NULL;
mxArray * b__ = NULL;
mlfEnterNewContext(1, 2, b, s, pr);
w = Mmidpoint(&b__, nargout, s, pr);
mlfRestorePreviousContext(1, 2, b, s, pr);
if (b != NULL) {
mclCopyOutputArg(b, b__);
} else {
mxDestroyArray(b__);
}
return mlfReturnValue(w);
}
/*
* The function "mlfMidpoint" contains the normal interface for the "midpoint"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\midpoint.m" (lines
* 1-66). This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
mxArray * mlfMidpoint(mxArray * * b, mxArray * s, mxArray * pr) {
int nargout = 1;
mxArray * w = NULL;
mxArray * b__ = NULL;
mlfEnterNewContext(1, 2, b, s, pr);
if (b != NULL) {
++nargout;
}
w = Mmidpoint(&b__, nargout, s, pr);
mlfRestorePreviousContext(1, 2, b, s, pr);
if (b != NULL) {
mclCopyOutputArg(b, b__);
} else {
mxDestroyArray(b__);
}
return mlfReturnValue(w);
}
/*
* The function "mlfVMidpoint" contains the void interface for the "midpoint"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\midpoint.m" (lines
* 1-66). The void interface is only produced if the M-function uses the
* special variable "nargout", and has at least one output. The void interface
* function specifies zero output arguments to the implementation version of
* the function, and in the event that the implementation version still returns
* an output (which, in MATLAB, would be assigned to the "ans" variable), it
* deallocates the output. This function processes any input arguments and
* passes them to the implementation version of the function, appearing above.
*/
void mlfVMidpoint(mxArray * s, mxArray * pr) {
mxArray * w = NULL;
mxArray * b = NULL;
mlfEnterNewContext(0, 2, s, pr);
w = Mmidpoint(&b, 0, s, pr);
mlfRestorePreviousContext(0, 2, s, pr);
mxDestroyArray(w);
mxDestroyArray(b);
}
/*
* The function "mlxMidpoint" contains the feval interface for the "midpoint"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\midpoint.m" (lines
* 1-66). The feval function calls the implementation version of midpoint
* through this function. This function processes any input arguments and
* passes them to the implementation version of the function, appearing above.
*/
void mlxMidpoint(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[2];
mxArray * mplhs[2];
int i;
if (nlhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: midpoint Line: 1 Column:"
" 1 The function \"midpoint\" was called with m"
"ore than the declared number of outputs (2)."),
NULL);
}
if (nrhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: midpoint Line: 1 Column:"
" 1 The function \"midpoint\" was called with m"
"ore than the declared number of inputs (2)."),
NULL);
}
for (i = 0; i < 2; ++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] = Mmidpoint(&mplhs[1], nlhs, mprhs[0], mprhs[1]);
mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0];
for (i = 1; i < 2 && i < nlhs; ++i) {
plhs[i] = mplhs[i];
}
for (; i < 2; ++i) {
mxDestroyArray(mplhs[i]);
}
}
/*
* The function "Mmidpoint" is the implementation version of the "midpoint"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnet\midpoint.m" (lines
* 1-66). 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 [w,b] = midpoint(s,pr)
*/
static mxArray * Mmidpoint(mxArray * * b,
int nargout_,
mxArray * s,
mxArray * pr) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_midpoint);
int nargin_ = mclNargin(2, s, pr, NULL);
mxArray * w = NULL;
mxArray * ans = NULL;
mclCopyArray(&s);
mclCopyArray(&pr);
/*
* %MIDPOINT Midpoint weight initialization function.
* %
* % Syntax
* %
* % W = midpoint(S,PR)
* %
* % Description
* %
* % MIDPOINT is a weight initialization function that
* % sets weight (row) vectors to the center of the
* % input ranges.
* %
* % MIDPOINT(S,PR) takes two arguments,
* % S - Number of rows (neurons).
* % PR - Rx2 matrix of input value ranges = [Pmin Pmax].
* % and returns an SxR matrix with rows set to (Pmin+Pmax)'/2.
* %
* % Examples
* %
* % Here initial weight values are calculated for a 5 neuron
* % layer with input elements ranging over [0 1] and [-2 2].
* %
* % W = midpoint(5,[0 1; -2 2])
* %
* % Network Use
* %
* % You can create a standard network that uses MIDPOINT to initialize
* % weights by calling NEWC.
* %
* % To prepare the weights and the bias of layer i of a custom network
* % to initialize with MIDPOINT:
* % 1) Set NET.initFcn to 'initlay'.
* % (NET.initParam will automatically become INITLAY's default parameters.)
* % 2) Set NET.layers{i}.initFcn to 'initwb'.
* % 3) Set each NET.inputWeights{i,j}.initFcn to 'midpoint'.
* % Set each NET.layerWeights{i,j}.initFcn to 'midpoint';
* %
* % To initialize the network call INIT.
* %
* % See NEWC for initialization examples.
* %
* % See also INITWB, INITLAY, INIT.
*
* % Mark Beale, 12-15-93
* % Revised 11-31-97, MB
* % Copyright 1992-2002 The MathWorks, Inc.
* % $Revision: 1.11 $ $Date: 2002/03/25 16:52:36 $
*
* if nargin < 2, error('Not enough arguments.'); end
*/
if (nargin_ < 2) {
mlfError(_mxarray0_, NULL);
}
/*
*
* % **[ NNT2 Support ]**
* if size(pr,2) > 2
*/
if (mclGtBool(
mlfSize(mclValueVarargout(), mclVa(pr, "pr"), _mxarray2_),
_mxarray2_)) {
/*
* nntobsu('midpoint','Use MIDPOINT(S,MINMAX(P)) instead of MIDPOINT(S,P).')
*/
mlfNntobsu(_mxarray3_, _mxarray5_, NULL);
/*
* pr = minmax(pr);
*/
mlfAssign(&pr, mlfMinmax(mclVa(pr, "pr")));
/*
* end
*/
}
/*
*
* w = mean(pr,2)';
*/
mlfAssign(&w, mlfCtranspose(mlfMean(mclVa(pr, "pr"), _mxarray2_)));
/*
* w = w(ones(1,s),:);
*/
mlfAssign(
&w,
mclArrayRef2(
mclVv(w, "w"),
mlfOnes(_mxarray7_, mclVa(s, "s"), NULL),
mlfCreateColonIndex()));
/*
*
* % **[ NNT2 Support ]**
* if nargout == 2
*/
if (nargout_ == 2) {
/*
* nntobsu('midpoint','Use B=ZEROS(S,1) instead of [W,B]=MIDPOINT(...).')
*/
mlfNntobsu(_mxarray3_, _mxarray8_, NULL);
/*
* b = zeros(s,1);
*/
mlfAssign(b, mlfZeros(mclVa(s, "s"), _mxarray7_, NULL));
/*
* end
*/
}
mclValidateOutput(w, 1, nargout_, "w", "midpoint");
mclValidateOutput(*b, 2, nargout_, "b", "midpoint");
mxDestroyArray(ans);
mxDestroyArray(pr);
mxDestroyArray(s);
mclSetCurrentLocalFunctionTable(save_local_function_table_);
return w;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -