?? fsals_svmtest.c
字號:
#include "mex.h"
#include "math.h"
double gradmin,*oldalpha,*gradvec,*svii;
int samplesnum,testsamplesnum,dim;
// Kernel evaluation
double kernel(double kernelparam,int p,int q, double *psamples1,double *psamples2)
{
double temp=0,aaa;
int i,count1,count2;
count1 = p*dim;
count2 = q*dim;
for (i=0;i<dim;i++)
{
aaa = *(psamples1 + i + count1) - *(psamples2 + i + count2);
temp += aaa*aaa;
}
return exp(-temp*kernelparam);
}
// Interface
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *ptestsamples,*psamples,*plabels,*alpha,*result;
double kernelparam,bias;
int i,j;
char ktype[10];
ptestsamples= mxGetPr(prhs[0]);
psamples = mxGetPr(prhs[1]);
plabels = mxGetPr(prhs[2]);
mxGetString( prhs[3], ktype, 10 );
kernelparam = mxGetScalar(prhs[4]);
alpha = mxGetPr(prhs[5]);
bias = mxGetScalar(prhs[6]);
testsamplesnum = mxGetN(prhs[0]);
dim = mxGetM(prhs[0]);
samplesnum = mxGetN(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(testsamplesnum,1,mxREAL);
result = mxGetPr(plhs[0]);
for (i=0;i<testsamplesnum;i++)
{
result[i] = bias;
}
for(i=0;i<testsamplesnum;i++)
{
for (j=0;j<samplesnum;j++)
{
result[i] = result[i] + alpha[j]*kernel(kernelparam,j,i,psamples,ptestsamples);
}
}
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -