5 #define X(i,j) x[j*n+i]
6 #define Y(i,j) y[j*n+i]
9 void sumsq(
double* xsq,
double* x,
int n,
int m) {
19 xsq[j] +=
X(i,j)*
X(i,j);
21 sprintf(temp,
"j(m)=%d(%d), i(n)=%d(%d), x=%.12f\n", j, m, i, n,
X(i,j));
28 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[] ) {
29 double *x, *y, *res, gamma, hlp;
70 gamma = mxGetScalar(mxGetProperty(prhs[0], 0,
"Gamma"));
73 sprintf(temp,
"Gamma=%.12f\n", gamma);
82 plhs[0] = mxCreateDoubleMatrix(m, m, mxREAL);
83 res = mxGetPr(plhs[0]);
86 sprintf(temp,
"Call with one parameter!\n");
95 for (i = 1; i < m; i++) {
96 for (j = 0; j < i; j++) {
98 for (l = 0; l < n; l++) {
100 sprintf(temp,
"ScaP i=%d, j=%d, l=%d, x=%.12f\n", i, j, l,
X(l,i));
103 hlp +=
X(l,i)*
X(l,j);
106 sprintf(temp,
"xsq[i]=%.12f, xsq[j]=%.12f, x*y=%.12f\n", xsq[i], xsq[j], hlp);
109 res[i+j*m] = exp(-(xsq[i]+xsq[j]-2*hlp)/gamma);
111 res[j+i*m] = res[i+j*m];
120 sprintf(temp,
"Call with two parameters!\n");
123 if (n != mxGetM(prhs[2]))
124 mexErrMsgTxt(
"GaussKernel.evaluate (mex): Array dimensions must match");
127 y = mxGetPr(prhs[2]);
129 plhs[0] = mxCreateDoubleMatrix(m, k, mxREAL);
130 res = mxGetPr(plhs[0]);
134 for (i = 0; i < m; i++) {
135 for (j = 0; j <
k; j++) {
138 for (l = 0; l < n; l++) {
140 sprintf(temp,
"ScaP i=%d, j=%d, l=%d, x=%.12f, y=%.12f\n", i, j, l,
X(l,i),
Y(l,i));
143 hlp +=
X(l,i)*
Y(l,j);
146 sprintf(temp,
"xsq=%.12f, ysq=%.12f, x*y=%.12f\n", xsq[i], ysq[j], hlp);
149 res[i+j*m] = exp(-(xsq[i]+ysq[j]-2*hlp)/gamma);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void sumsq(double *xsq, double *x, int n, int m)