📄 marq.c
字号:
/*
* INCLUDE HEADERS
*/
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "mex.h"
#include "matrix2.h"
#include "nnmisc.h"
/*********************************************************************************
* *
* MARQ *
* ---- *
* *
* This is a C-version of the Matlab function marq. *
* Type 'help marq' from Matlab for information on *
* how to call this function. *
* *
* *
* Programmed by: Magnus Norgaard *
* LastEditDate : okt. 05, 1994 *
* *
*********************************************************************************/
/*********************************************************************************
* *
* G A T E W A Y R O U T I N E *
* *
*********************************************************************************/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
/*
>>>>>>>>>>>>>>>>>> VARIABLE DECLARATIONS <<<<<<<<<<<<<<<<<<<
*/
matrix *PI_vector;
matrix *NetDef, *W1, *W2, *PHI, *Y, *trparms;
double *M, lambda;
int iter;
/*
>>>>>>>>>>>>>>>> CHECK FOR PROPER NUMBER OF ARGUMENTS <<<<<<<<<<<<<<<
*/
if (nrhs<5 || nrhs>6)
{
mexErrMsgTxt("Wrong number of input arguments");
}
else if (nlhs > 5)
{
mexErrMsgTxt("Two many output arguments");
}
/*
>>>>>>>>>>>>>>>>> CONVERT INPUT ARGUMENTS TO SM FORMAT <<<<<<<<<<<<<<<<
*/
NetDef = matstring2sm(prhs[0]);
W1 = mat2sm(prhs[1]);
W2 = mat2sm(prhs[2]);
PHI = mat2sm(prhs[3]);
Y = mat2sm(prhs[4]);
if (nrhs==6)
trparms = mat2sm(prhs[5]);
else
{
trparms = mmake(1,4);
mput(trparms,0,0,500);
mput(trparms,0,1,0.0);
mput(trparms,0,2,1);
mput(trparms,0,3,0.0);
}
/*
>>>>>>>>>>>>>>>>>>>>>> CALL THE C-ROUTINE <<<<<<<<<<<<<<<<<<<<<
*/
marqc(&PI_vector, &iter, &lambda, NetDef, W1, W2, PHI, Y, trparms);
/*
>>>>>>>>>>>>>>>>>>> CREATE OUTPUT MATICES <<<<<<<<<<<<<<<<<<
*/
plhs[0] = mxCreateDoubleMatrix(getrows(W1),getcols(W1),mxREAL);
plhs[1] = mxCreateDoubleMatrix(getrows(W2),getcols(W2),mxREAL);
plhs[2] = mxCreateDoubleMatrix(getrows(PI_vector),getcols(PI_vector),mxREAL);
plhs[3] = mxCreateDoubleMatrix(1,1,mxREAL);
plhs[4] = mxCreateDoubleMatrix(1,1,mxREAL);
sm2mat(plhs[0],W1);
sm2mat(plhs[1],W2);
sm2mat(plhs[2],PI_vector);
M = mxGetPr(plhs[3]); M[0] = (double)iter;
M = mxGetPr(plhs[4]); M[0] = (double)lambda;
/*
>>>>>>>>>>>>>>>>>>>> FREE ARGUMENT MATRICES <<<<<<<<<<<<<<<<<<<<<
*/
mfree(NetDef);
mfree(PHI);
mfree(Y);
mfree(trparms);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -