資源簡介
svmpredic.c svmtrain.c svmpredict.mexw64 svmtrain.mexw64

代碼片段和文件信息
#include?
#include?
#include?
#include?“../svm.h“
#include?“mex.h“
#include?“svm_model_matlab.h“
#ifdef?MX_API_VER
#if?MX_API_VER?0x07030000
typedef?int?mwIndex;
#endif
#endif
#define?CMD_LEN?2048
int?print_null(const?char?*s...)?{}
int?(*info)(const?char?*fmt...)?=?&mexPrintf;
void?read_sparse_instance(const?mxArray?*prhs?int?index?struct?svm_node?*x)
{
int?i?j?low?high;
mwIndex?*ir?*jc;
double?*samples;
ir?=?mxGetIr(prhs);
jc?=?mxGetJc(prhs);
samples?=?mxGetPr(prhs);
//?each?column?is?one?instance
j?=?0;
low?=?(int)jc[index]?high?=?(int)jc[index+1];
for(i=low;i {
x[j].index?=?(int)ir[i]?+?1;
x[j].value?=?samples[i];
j++;
}
x[j].index?=?-1;
}
static?void?fake_answer(mxArray?*plhs[])
{
plhs[0]?=?mxCreateDoubleMatrix(0?0?mxREAL);
plhs[1]?=?mxCreateDoubleMatrix(0?0?mxREAL);
plhs[2]?=?mxCreateDoubleMatrix(0?0?mxREAL);
}
void?predict(mxArray?*plhs[]?const?mxArray?*prhs[]?struct?svm_model?*model?const?int?predict_probability)
{
int?label_vector_row_num?label_vector_col_num;
int?feature_number?testing_instance_number;
int?instance_index;
double?*ptr_instance?*ptr_label?*ptr_predict_label;?
double?*ptr_prob_estimates?*ptr_dec_values?*ptr;
struct?svm_node?*x;
mxArray?*pplhs[1];?//?transposed?instance?sparse?matrix
int?correct?=?0;
int?total?=?0;
double?error?=?0;
double?sump?=?0?sumt?=?0?sumpp?=?0?sumtt?=?0?sumpt?=?0;
int?svm_type=svm_get_svm_type(model);
int?nr_class=svm_get_nr_class(model);
double?*prob_estimates=NULL;
//?prhs[1]?=?testing?instance?matrix
feature_number?=?(int)mxGetN(prhs[1]);
testing_instance_number?=?(int)mxGetM(prhs[1]);
label_vector_row_num?=?(int)mxGetM(prhs[0]);
label_vector_col_num?=?(int)mxGetN(prhs[0]);
if(label_vector_row_num!=testing_instance_number)
{
mexPrintf(“Length?of?label?vector?does?not?match?#?of?instances.\n“);
fake_answer(plhs);
return;
}
if(label_vector_col_num!=1)
{
mexPrintf(“label?(1st?argument)?should?be?a?vector?(#?of?column?is?1).\n“);
fake_answer(plhs);
return;
}
ptr_instance?=?mxGetPr(prhs[1]);
ptr_label????=?mxGetPr(prhs[0]);
//?transpose?instance?matrix
if(mxIsSparse(prhs[1]))
{
if(model->param.kernel_type?==?PRECOMPUTED)
{
//?precomputed?kernel?requires?dense?matrix?so?we?make?one
mxArray?*rhs[1]?*lhs[1];
rhs[0]?=?mxDuplicateArray(prhs[1]);
if(mexCallMATLAB(1?lhs?1?rhs?“full“))
{
mexPrintf(“Error:?cannot?full?testing?instance?matrix\n“);
fake_answer(plhs);
return;
}
ptr_instance?=?mxGetPr(lhs[0]);
mxDestroyArray(rhs[0]);
}
else
{
mxArray?*pprhs[1];
pprhs[0]?=?mxDuplicateArray(prhs[1]);
if(mexCallMATLAB(1?pplhs?1?pprhs?“transpose“))
{
mexPrintf(“Error:?cannot?transpose?testing?instance?matrix\n“);
fake_answer(plhs);
return;
}
}
}
if(predict_probability)
{
if(svm_type==NU_SVR?||?svm_type==EPSILON_SVR)
info(“Prob.?model?for?test?data:?target?value?=?predicted?value?+?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9472??2012-07-25?14:12??svmpredict.c
?????文件??????24064??2014-10-30?17:12??svmpredict.mexw64
?????文件??????11458??2012-07-15?19:12??svmtrain.c
?????文件??????62976??2014-10-30?17:12??svmtrain.mexw64
-----------?---------??----------?-----??----
???????????????107970????????????????????4
評論
共有 條評論