📄 tlm1.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 "tlm1.h"
#include "learnlm.h"
#include "libmatlbm.h"
#include "libmmfile.h"
#include "nncpyd.h"
#include "nncpyi.h"
#include "nndef.h"
#include "nntobsf.h"
#include "ploterr.h"
#include "plotfa.h"
#include "simuff.h"
#include "sumsqr.h"
static mxChar _array1_[4] = { 't', 'l', 'm', '1' };
static mxArray * _mxarray0_;
static mxChar _array3_[54] = { 'U', 's', 'e', ' ', 'N', 'N', 'T', '2', 'F',
'F', ' ', 'a', 'n', 'd', ' ', 'T', 'R', 'A',
'I', 'N', ' ', 't', 'o', ' ', 'u', 'p', 'd',
'a', 't', 'e', ' ', 'a', 'n', 'd', ' ', 't',
'r', 'a', 'i', 'n', ' ', 'y', 'o', 'u', 'r',
' ', 'n', 'e', 't', 'w', 'o', 'r', 'k', '.' };
static mxArray * _mxarray2_;
static mxChar _array5_[21] = { 'N', 'o', 't', ' ', 'e', 'n', 'o',
'u', 'g', 'h', ' ', 'a', 'r', 'g',
'u', 'm', 'e', 'n', 't', 's', '.' };
static mxArray * _mxarray4_;
static mxArray * _mxarray6_;
static double _array8_[8] = { 25.0, 1000.0, .02, .0001, .001, 10.0, .1, 1e+10 };
static mxArray * _mxarray7_;
static mxChar _array10_[5] = { 'd', 'e', 'l', 't', 'a' };
static mxArray * _mxarray9_;
static mxArray * _mxarray11_;
static mxChar _array13_[46] = { 'T', 'R', 'A', 'I', 'N', 'L', 'M', ':',
' ', '%', '%', 'g', '/', '%', 'g', ' ',
'e', 'p', 'o', 'c', 'h', 's', ',', ' ',
'm', 'u', ' ', '=', ' ', '%', '%', 'g',
',', ' ', 'S', 'S', 'E', ' ', '=', ' ',
'%', '%', 'g', '.', 0x005c, 'n' };
static mxArray * _mxarray12_;
static mxArray * _mxarray14_;
static mxArray * _mxarray15_;
static mxChar _array17_[1] = { 'm' };
static mxArray * _mxarray16_;
static mxChar _array19_[1] = { ' ' };
static mxArray * _mxarray18_;
static mxChar _array21_[58] = { 'T', 'R', 'A', 'I', 'N', 'L', 'M', ':', ' ',
'E', 'r', 'r', 'o', 'r', ' ', 'g', 'r', 'a',
'd', 'i', 'e', 'n', 't', ' ', 'i', 's', ' ',
't', 'o', 'o', ' ', 's', 'm', 'a', 'l', 'l',
' ', 't', 'o', ' ', 'c', 'o', 'n', 't', 'i',
'n', 'u', 'e', ' ', 'l', 'e', 'a', 'r', 'n',
'i', 'n', 'g', '.' };
static mxArray * _mxarray20_;
static mxChar _array23_[52] = { 'T', 'R', 'A', 'I', 'N', 'L', 'M', ':', ' ',
'N', 'e', 't', 'w', 'o', 'r', 'k', ' ', 'e',
'r', 'r', 'o', 'r', ' ', 'd', 'i', 'd', ' ',
'n', 'o', 't', ' ', 'r', 'e', 'a', 'c', 'h',
' ', 't', 'h', 'e', ' ', 'e', 'r', 'r', 'o',
'r', ' ', 'g', 'o', 'a', 'l', '.' };
static mxArray * _mxarray22_;
static mxChar _array25_[53] = { ' ', ' ', 'F', 'u', 'r', 't', 'h', 'e', 'r',
' ', 't', 'r', 'a', 'i', 'n', 'i', 'n', 'g',
' ', 'm', 'a', 'y', ' ', 'b', 'e', ' ', 'n',
'e', 'c', 'e', 's', 's', 'a', 'r', 'y', ',',
' ', 'o', 'r', ' ', 't', 'r', 'y', ' ', 'd',
'i', 'f', 'f', 'e', 'r', 'e', 'n', 't' };
static mxArray * _mxarray24_;
static mxChar _array27_[55] = { ' ', ' ', 'i', 'n', 'i', 't', 'i', 'a',
'l', ' ', 'w', 'e', 'i', 'g', 'h', 't',
's', ' ', 'a', 'n', 'd', ' ', 'b', 'i',
'a', 's', 'e', 's', ' ', 'a', 'n', 'd',
'/', 'o', 'r', ' ', 'm', 'o', 'r', 'e',
' ', 'h', 'i', 'd', 'd', 'e', 'n', ' ',
'l', 'a', 'y', 'e', 'r', 's', '.' };
static mxArray * _mxarray26_;
void InitializeModule_tlm1(void) {
_mxarray0_ = mclInitializeString(4, _array1_);
_mxarray2_ = mclInitializeString(54, _array3_);
_mxarray4_ = mclInitializeString(21, _array5_);
_mxarray6_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
_mxarray7_ = mclInitializeDoubleVector(1, 8, _array8_);
_mxarray9_ = mclInitializeString(5, _array10_);
_mxarray11_ = mclInitializeDouble(1.0);
_mxarray12_ = mclInitializeString(46, _array13_);
_mxarray14_ = mclInitializeDouble(0.0);
_mxarray15_ = mclInitializeDouble(6.0);
_mxarray16_ = mclInitializeString(1, _array17_);
_mxarray18_ = mclInitializeString(1, _array19_);
_mxarray20_ = mclInitializeString(58, _array21_);
_mxarray22_ = mclInitializeString(52, _array23_);
_mxarray24_ = mclInitializeString(53, _array25_);
_mxarray26_ = mclInitializeString(55, _array27_);
}
void TerminateModule_tlm1(void) {
mxDestroyArray(_mxarray26_);
mxDestroyArray(_mxarray24_);
mxDestroyArray(_mxarray22_);
mxDestroyArray(_mxarray20_);
mxDestroyArray(_mxarray18_);
mxDestroyArray(_mxarray16_);
mxDestroyArray(_mxarray15_);
mxDestroyArray(_mxarray14_);
mxDestroyArray(_mxarray12_);
mxDestroyArray(_mxarray11_);
mxDestroyArray(_mxarray9_);
mxDestroyArray(_mxarray7_);
mxDestroyArray(_mxarray6_);
mxDestroyArray(_mxarray4_);
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Mtlm1(mxArray * * b1,
mxArray * * i,
mxArray * * tr,
int nargout_,
mxArray * w1_in,
mxArray * b1_in,
mxArray * f1,
mxArray * p,
mxArray * t,
mxArray * tp);
_mexLocalFunctionTable _local_function_table_tlm1
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfTlm1" contains the normal interface for the "tlm1"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnobsolete\tlm1.m" (lines
* 1-163). This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
mxArray * mlfTlm1(mxArray * * b1,
mxArray * * i,
mxArray * * tr,
mxArray * w1_in,
mxArray * b1_in,
mxArray * f1,
mxArray * p,
mxArray * t,
mxArray * tp) {
int nargout = 1;
mxArray * w1 = NULL;
mxArray * b1__ = NULL;
mxArray * i__ = NULL;
mxArray * tr__ = NULL;
mlfEnterNewContext(3, 6, b1, i, tr, w1_in, b1_in, f1, p, t, tp);
if (b1 != NULL) {
++nargout;
}
if (i != NULL) {
++nargout;
}
if (tr != NULL) {
++nargout;
}
w1 = Mtlm1(&b1__, &i__, &tr__, nargout, w1_in, b1_in, f1, p, t, tp);
mlfRestorePreviousContext(3, 6, b1, i, tr, w1_in, b1_in, f1, p, t, tp);
if (b1 != NULL) {
mclCopyOutputArg(b1, b1__);
} else {
mxDestroyArray(b1__);
}
if (i != NULL) {
mclCopyOutputArg(i, i__);
} else {
mxDestroyArray(i__);
}
if (tr != NULL) {
mclCopyOutputArg(tr, tr__);
} else {
mxDestroyArray(tr__);
}
return mlfReturnValue(w1);
}
/*
* The function "mlxTlm1" contains the feval interface for the "tlm1"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnobsolete\tlm1.m" (lines
* 1-163). The feval function calls the implementation version of tlm1 through
* this function. This function processes any input arguments and passes them
* to the implementation version of the function, appearing above.
*/
void mlxTlm1(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[6];
mxArray * mplhs[4];
int i;
if (nlhs > 4) {
mlfError(
mxCreateString(
"Run-time Error: File: tlm1 Line: 1 Column: 1 The function \"tlm1\""
" was called with more than the declared number of outputs (4)."),
NULL);
}
if (nrhs > 6) {
mlfError(
mxCreateString(
"Run-time Error: File: tlm1 Line: 1 Column: 1 The function \"tlm1"
"\" was called with more than the declared number of inputs (6)."),
NULL);
}
for (i = 0; i < 4; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 6 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 6; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(
0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
mplhs[0]
= Mtlm1(
&mplhs[1],
&mplhs[2],
&mplhs[3],
nlhs,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5]);
mlfRestorePreviousContext(
0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
plhs[0] = mplhs[0];
for (i = 1; i < 4 && i < nlhs; ++i) {
plhs[i] = mplhs[i];
}
for (; i < 4; ++i) {
mxDestroyArray(mplhs[i]);
}
}
/*
* The function "Mtlm1" is the implementation version of the "tlm1" M-function
* from file "d:\matlab6p5\toolbox\nnet\nnobsolete\tlm1.m" (lines 1-163). 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 [w1,b1,i,tr] = tlm1(w1,b1,f1,p,t,tp)
*/
static mxArray * Mtlm1(mxArray * * b1,
mxArray * * i,
mxArray * * tr,
int nargout_,
mxArray * w1_in,
mxArray * b1_in,
mxArray * f1,
mxArray * p,
mxArray * t,
mxArray * tp) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_tlm1);
int nargin_ = mclNargin(6, w1_in, b1_in, f1, p, t, tp, NULL);
mxArray * w1 = NULL;
mxArray * new_SSE = NULL;
mxArray * new_e = NULL;
mxArray * new_b1 = NULL;
mxArray * new_w1 = NULL;
mxArray * dx = NULL;
mxArray * jj = NULL;
mxArray * grad = NULL;
mxArray * je = NULL;
mxArray * j = NULL;
mxArray * j1 = NULL;
mxArray * ext_d1 = NULL;
mxArray * d1 = NULL;
mxArray * mu = NULL;
mxArray * h = NULL;
mxArray * message = NULL;
mxArray * plottype = NULL;
mxArray * SSE = NULL;
mxArray * e = NULL;
mxArray * a1 = NULL;
mxArray * ext_p = NULL;
mxArray * db1 = NULL;
mxArray * dw1 = NULL;
mxArray * ii = NULL;
mxArray * b1_ind = NULL;
mxArray * w1_ind = NULL;
mxArray * r = NULL;
mxArray * s1 = NULL;
mxArray * df1 = NULL;
mxArray * mu_max = NULL;
mxArray * mu_dec = NULL;
mxArray * mu_inc = NULL;
mxArray * mu_init = NULL;
mxArray * grad_min = NULL;
mxArray * eg = NULL;
mxArray * me = NULL;
mxArray * df = NULL;
mxArray * ans = NULL;
mclCopyInputArg(&w1, w1_in);
mclCopyInputArg(b1, b1_in);
mclCopyArray(&f1);
mclCopyArray(&p);
mclCopyArray(&t);
mclCopyArray(&tp);
/*
* %TLM1 Train 1-layer feed-forward network w/Levenberg-Marquardt.
* %
* % This function is obselete.
* % Use NNT2FF and TRAIN to update and train your network.
*
* nntobsf('tlm1','Use NNT2FF and TRAIN to update and train your network.')
*/
mlfNntobsf(_mxarray0_, _mxarray2_, NULL);
/*
*
* % [W,B,TE,TR] = TLM1(W,B,'F1',P,T)
* % W - Weight matrix.
* % B - Bias vector.
* % F - Transfer function (string).
* % P - RxQ matrix of input vectors.
* % T - S1xQ matrix of target vectors.
* % TP - Training parameters (optional).
* % Returns:
* % Wi - new weights.
* % Bi - new biases.
* % TE - the actual number of epochs trained.
* % TR - training record: [row of errors]
* %
* % Training parameters are:
* % TP(1) - Epochs between updating display, default = 25.
* % TP(2) - Maximum number of epochs to train, default = 1000.
* % TP(3) - Sum-squared error goal, default = 0.02.
* % TP(4) - Minimum gradient, default = 0.0001.
* % TP(5) - Initial value for MU, default = 0.001.
* % TP(6) - Multiplier for increasing MU, default = 10.
* % TP(7) - Multiplier for decreasing MU, default = 0.1.
* % TP(8) - Maximum value for MU, default = 1e10.
* % Missing parameters and NaN's are replaced with defaults.
*
* % Mark Beale, 12-15-93
* % Copyright 1992-2002 The MathWorks, Inc.
* % $Revision: 1.11 $ $Date: 2002/03/25 16:54:22 $
*
* if nargin < 5,error('Not enough arguments.'),end
*/
if (nargin_ < 5) {
mlfError(_mxarray4_, NULL);
}
/*
*
* % TRAINING PARAMETERS
* if nargin == 5, tp = []; end
*/
if (nargin_ == 5) {
mlfAssign(&tp, _mxarray6_);
}
/*
* tp = nndef(tp,[25 1000 0.02 0.0001 0.001 10 0.1 1e10]);
*/
mlfAssign(&tp, mlfNndef(mclVa(tp, "tp"), _mxarray7_));
/*
* df = tp(1);
*/
mlfAssign(&df, mclIntArrayRef1(mclVa(tp, "tp"), 1));
/*
* me = tp(2);
*/
mlfAssign(&me, mclIntArrayRef1(mclVa(tp, "tp"), 2));
/*
* eg = tp(3);
*/
mlfAssign(&eg, mclIntArrayRef1(mclVa(tp, "tp"), 3));
/*
* grad_min = tp(4);
*/
mlfAssign(&grad_min, mclIntArrayRef1(mclVa(tp, "tp"), 4));
/*
* mu_init = tp(5);
*/
mlfAssign(&mu_init, mclIntArrayRef1(mclVa(tp, "tp"), 5));
/*
* mu_inc = tp(6);
*/
mlfAssign(&mu_inc, mclIntArrayRef1(mclVa(tp, "tp"), 6));
/*
* mu_dec = tp(7);
*/
mlfAssign(&mu_dec, mclIntArrayRef1(mclVa(tp, "tp"), 7));
/*
* mu_max = tp(8);
*/
mlfAssign(&mu_max, mclIntArrayRef1(mclVa(tp, "tp"), 8));
/*
* df1 = feval(f1,'delta');
*/
mlfAssign(
&df1, mlfFeval(mclValueVarargout(), mclVa(f1, "f1"), _mxarray9_, NULL));
/*
*
* % DEFINE SIZES
* [s1,r] = size(w1);
*/
mlfSize(mlfVarargout(&s1, &r, NULL), mclVa(w1, "w1"), NULL);
/*
* w1_ind = [1:(s1*r)];
*/
mlfAssign(
&w1_ind,
mlfColon(_mxarray11_, mclMtimes(mclVv(s1, "s1"), mclVv(r, "r")), NULL));
/*
* b1_ind = [1:s1] + w1_ind(length(w1_ind));
*/
mlfAssign(
&b1_ind,
mclPlus(
mlfColon(_mxarray11_, mclVv(s1, "s1"), NULL),
mclIntArrayRef1(
mclVv(w1_ind, "w1_ind"), mclLengthInt(mclVv(w1_ind, "w1_ind")))));
/*
* ii = eye(b1_ind(length(b1_ind)));
*/
mlfAssign(
&ii,
mlfEye(
mclIntArrayRef1(
mclVv(b1_ind, "b1_ind"), mclLengthInt(mclVv(b1_ind, "b1_ind"))),
NULL));
/*
* dw1 = w1; db1 = b1;
*/
mlfAssign(&dw1, mclVa(w1, "w1"));
mlfAssign(&db1, mclVa(*b1, "b1"));
/*
* ext_p = nncpyi(p,s1);
*/
mlfAssign(&ext_p, mlfNncpyi(mclVa(p, "p"), mclVv(s1, "s1")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -