📄 calcjejj.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 "calcjejj.h"
#include "calcjx.h"
#include "libmatlbm.h"
#include "libmmfile.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
static mxArray * _mxarray2_;
static mxArray * _mxarray3_;
static mxArray * _mxarray4_;
void InitializeModule_calcjejj(void) {
_mxarray0_ = mclInitializeDouble(1.0);
_mxarray1_ = mclInitializeDouble(2.0);
_mxarray2_ = mclInitializeDouble(0.0);
_mxarray3_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
_mxarray4_ = mclInitializeDouble(6.0);
}
void TerminateModule_calcjejj(void) {
mxDestroyArray(_mxarray4_);
mxDestroyArray(_mxarray3_);
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray1_);
mxDestroyArray(_mxarray0_);
}
static mxArray * mlfCalcjejj_batchdiv(mxArray * b,
mxArray * QD,
mxArray * Qstart,
mxArray * Qstop);
static void mlxCalcjejj_batchdiv(int nlhs,
mxArray * plhs[],
int nrhs,
mxArray * prhs[]);
static mxArray * Mcalcjejj(mxArray * * JJ,
mxArray * * normJE,
int nargout_,
mxArray * net,
mxArray * Pd,
mxArray * Zb,
mxArray * Zi,
mxArray * Zl,
mxArray * N,
mxArray * Ac,
mxArray * En,
mxArray * Q,
mxArray * TS,
mxArray * MR);
static mxArray * Mcalcjejj_batchdiv(int nargout_,
mxArray * b,
mxArray * QD,
mxArray * Qstart,
mxArray * Qstop);
static mexFunctionTableEntry local_function_table_[1]
= { { "batchdiv", mlxCalcjejj_batchdiv, 4, 1, NULL } };
_mexLocalFunctionTable _local_function_table_calcjejj
= { 1, local_function_table_ };
/*
* The function "mlfCalcjejj" contains the normal interface for the "calcjejj"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnutils\calcjejj.m" (lines
* 1-155). This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
mxArray * mlfCalcjejj(mxArray * * JJ,
mxArray * * normJE,
mxArray * net,
mxArray * Pd,
mxArray * Zb,
mxArray * Zi,
mxArray * Zl,
mxArray * N,
mxArray * Ac,
mxArray * En,
mxArray * Q,
mxArray * TS,
mxArray * MR) {
int nargout = 1;
mxArray * JE = NULL;
mxArray * JJ__ = NULL;
mxArray * normJE__ = NULL;
mlfEnterNewContext(
2, 11, JJ, normJE, net, Pd, Zb, Zi, Zl, N, Ac, En, Q, TS, MR);
if (JJ != NULL) {
++nargout;
}
if (normJE != NULL) {
++nargout;
}
JE
= Mcalcjejj(
&JJ__,
&normJE__,
nargout,
net,
Pd,
Zb,
Zi,
Zl,
N,
Ac,
En,
Q,
TS,
MR);
mlfRestorePreviousContext(
2, 11, JJ, normJE, net, Pd, Zb, Zi, Zl, N, Ac, En, Q, TS, MR);
if (JJ != NULL) {
mclCopyOutputArg(JJ, JJ__);
} else {
mxDestroyArray(JJ__);
}
if (normJE != NULL) {
mclCopyOutputArg(normJE, normJE__);
} else {
mxDestroyArray(normJE__);
}
return mlfReturnValue(JE);
}
/*
* The function "mlxCalcjejj" contains the feval interface for the "calcjejj"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnutils\calcjejj.m" (lines
* 1-155). The feval function calls the implementation version of calcjejj
* through this function. This function processes any input arguments and
* passes them to the implementation version of the function, appearing above.
*/
void mlxCalcjejj(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[11];
mxArray * mplhs[3];
int i;
if (nlhs > 3) {
mlfError(
mxCreateString(
"Run-time Error: File: calcjejj Line: 1 Column:"
" 1 The function \"calcjejj\" was called with m"
"ore than the declared number of outputs (3)."),
NULL);
}
if (nrhs > 11) {
mlfError(
mxCreateString(
"Run-time Error: File: calcjejj Line: 1 Column:"
" 1 The function \"calcjejj\" was called with m"
"ore than the declared number of inputs (11)."),
NULL);
}
for (i = 0; i < 3; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 11 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 11; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(
0,
11,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5],
mprhs[6],
mprhs[7],
mprhs[8],
mprhs[9],
mprhs[10]);
mplhs[0]
= Mcalcjejj(
&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],
mprhs[10]);
mlfRestorePreviousContext(
0,
11,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5],
mprhs[6],
mprhs[7],
mprhs[8],
mprhs[9],
mprhs[10]);
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 "mlfCalcjejj_batchdiv" contains the normal interface for the
* "calcjejj/batchdiv" M-function from file
* "d:\matlab6p5\toolbox\nnet\nnutils\calcjejj.m" (lines 155-172). This
* function processes any input arguments and passes them to the implementation
* version of the function, appearing above.
*/
static mxArray * mlfCalcjejj_batchdiv(mxArray * b,
mxArray * QD,
mxArray * Qstart,
mxArray * Qstop) {
int nargout = 1;
mxArray * b_div = NULL;
mlfEnterNewContext(0, 4, b, QD, Qstart, Qstop);
b_div = Mcalcjejj_batchdiv(nargout, b, QD, Qstart, Qstop);
mlfRestorePreviousContext(0, 4, b, QD, Qstart, Qstop);
return mlfReturnValue(b_div);
}
/*
* The function "mlxCalcjejj_batchdiv" contains the feval interface for the
* "calcjejj/batchdiv" M-function from file
* "d:\matlab6p5\toolbox\nnet\nnutils\calcjejj.m" (lines 155-172). The feval
* function calls the implementation version of calcjejj/batchdiv through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
static void mlxCalcjejj_batchdiv(int nlhs,
mxArray * plhs[],
int nrhs,
mxArray * prhs[]) {
mxArray * mprhs[4];
mxArray * mplhs[1];
int i;
if (nlhs > 1) {
mlfError(
mxCreateString(
"Run-time Error: File: calcjejj/batchdiv Line: 155 Col"
"umn: 1 The function \"calcjejj/batchdiv\" was called "
"with more than the declared number of outputs (1)."),
NULL);
}
if (nrhs > 4) {
mlfError(
mxCreateString(
"Run-time Error: File: calcjejj/batchdiv Line: 155 Col"
"umn: 1 The function \"calcjejj/batchdiv\" was called "
"with more than the declared number of inputs (4)."),
NULL);
}
for (i = 0; i < 1; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 4 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 4; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
mplhs[0] = Mcalcjejj_batchdiv(nlhs, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
mlfRestorePreviousContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
plhs[0] = mplhs[0];
}
/*
* The function "Mcalcjejj" is the implementation version of the "calcjejj"
* M-function from file "d:\matlab6p5\toolbox\nnet\nnutils\calcjejj.m" (lines
* 1-155). 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 [JE,JJ,normJE] = calcjejj(net,Pd,Zb,Zi,Zl,N,Ac,En,Q,TS,MR)
*/
static mxArray * Mcalcjejj(mxArray * * JJ,
mxArray * * normJE,
int nargout_,
mxArray * net,
mxArray * Pd,
mxArray * Zb,
mxArray * Zi,
mxArray * Zl,
mxArray * N,
mxArray * Ac,
mxArray * En,
mxArray * Q,
mxArray * TS,
mxArray * MR) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_calcjejj);
mxArray * JE = NULL;
mxArray * q = NULL;
mxArray * Q2 = NULL;
mxArray * Qstart = NULL;
mxArray * Qstop = NULL;
mxArray * Jx = NULL;
mxArray * Ex = NULL;
mxArray * Em = NULL;
mclCopyArray(&net);
mclCopyArray(&Pd);
mclCopyArray(&Zb);
mclCopyArray(&Zi);
mclCopyArray(&Zl);
mclCopyArray(&N);
mclCopyArray(&Ac);
mclCopyArray(&En);
mclCopyArray(&Q);
mclCopyArray(&TS);
mclCopyArray(&MR);
/*
* %CALCJEJJ Calculate Jacobian performance vector.
* %
* % Syntax
* %
* % [je,jj,normje] = calcjejj(net,Pd,BZ,IWZ,LWZ,N,Ac,El,Q,TS,MR)
* %
* % Description
* %
* % This function calculates two values (related to the Jacobian
* % of a network) required to calculate the network's Hessian,
* % in a memory efficient way.
* %
* % Two values needed to calculate the Hessian of a network are
* % J*E (Jacobian times errors) and J'J (Jacobian squared).
* % However the Jacobian J can take up a lot of memory.
* %
* % This function calculates J*E and J'J by dividing up training
* % vectors into groups, calculating partial Jacobians Ji and
* % its associated values Ji*Ei and Ji'Ji, then summing the
* % partial values into the full J*E and J'J values.
* %
* % This allows the J*E and J'J values to be calculated with a
* % series of smaller Ji matrices, instead of a larger J matrix.
* %
* % [je,jj,normgX] = CALCJEJJ(NET,PD,BZ,IWZ,LWZ,N,Ac,El,Q,TS,MR) takes,
* % NET - Neural network.
* % PD - Delayed inputs.
* % BZ - Concurrent biases.
* % IWZ - Weighted inputs.
* % LWZ - Weighted layer outputs.
* % N - Net inputs.
* % Ac - Combined layer outputs.
* % El - Layer errors.
* % Q - Concurrent size.
* % TS - Time steps.
* % MR - Memory reduction factor.
* % and returns,
* % je - Jacobian times errors.
* % jj - Jacobian transposed time the Jacobian.
* % normgx - Magnitute of the gradient.
* %
* % Examples
* %
* % Here we create a linear network with a single input element
* % ranging from 0 to 1, two neurons, and a tap delay on the
* % input with taps at 0, 2, and 4 timesteps. The network is
* % also given a recurrent connection from layer 1 to itself with
* % tap delays of [1 2].
* %
* % net = newlin([0 1],2);
* % net.layerConnect(1,1) = 1;
* % net.layerWeights{1,1}.delays = [1 2];
* %
* % Here is a single (Q = 1) input sequence P with 5 timesteps (TS = 5),
* % and the 4 initial input delay conditions Pi, combined inputs Pc,
* % and delayed inputs Pd.
* %
* % P = {0 0.1 0.3 0.6 0.4};
* % Pi = {0.2 0.3 0.4 0.1};
* % Pc = [Pi P];
* % Pd = calcpd(net,5,1,Pc);
* %
* % Here the two initial layer delay conditions for each of the
* % two neurons, and the layer targets for the two neurons over
* % five timesteps are defined.
* %
* % Ai = {[0.5; 0.1] [0.6; 0.5]};
* % Tl = {[0.1;0.2] [0.3;0.1], [0.5;0.6] [0.8;0.9], [0.5;0.1]};
* %
* % Here the network's weight and bias values are extracted, and
* % the network's performance and other signals are calculated.
* %
* % [perf,El,Ac,N,BZ,IWZ,LWZ] = calcperf(net,X,Pd,Tl,Ai,1,5);
* %
* % Finally we can use CALCGX to calculate the Jacobian times error,
* % Jacobian squared, and the norm of the Jocobian times error using
* % a memory reduction of 2.
* %
* % [je,jj,normje] = calcjejj(net,Pd,BZ,IWZ,LWZ,N,Ac,El,1,5,2);
* %
* % The results should be the same whatever the memory reduction
* % used. Here a memory reduction of 3 is used.
* %
* % [je,jj,normje] = calcjejj(net,Pd,BZ,IWZ,LWZ,N,Ac,El,1,5,3);
* %
* % See also CALCJX, CALCJEJJ.
*
* % Mark Beale, 11-31-97
* % Mark Beale, Updated help, 5-25-98
* % Copyright 1992-2002 The MathWorks, Inc.
* % $Revision: 1.9 $ $Date: 2002/03/25 16:54:54 $
*
* % Inputs
* %
* % Pd - NlxNixTS cell array PD{i,j,ts} - DijxQ matrix or []
* % Zb - Nlx1 cell array Zb{i} - SixQ matrix or []
* % Zi - NlxNixTS cell array Zi{i,j,ts} - SixQ matrix or []
* % Zl - NlxNlxTS cell array Zl{i,j,ts} - SixQ matrix or []
* % N - NlxTS cell array N{i} - SixQ matrix
* % Ac - Nlx(LD+TS) cell array Ac{i,LD+ts} - SixQ matrix
* % En - NlxTS cell array E{i,ts} - SixQ matrix or []
* %
* % Locals
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -