资源简介
SVM分类器,可在行人检测时用来分类训练样本,在MATLAB中直接试用。
代码片段和文件信息
#include
#include
#include
#include
#include
#include “svm.h“
struct svm_node *x;
int max_nr_attr = 64;
struct svm_model* model;
int predict_probability=0;
static char *line = NULL;
static int max_line_len;
static char* readline(FILE *input)
{
int len;
if(fgets(linemax_line_leninput) == NULL)
return NULL;
while(strrchr(line‘\n‘) == NULL)
{
max_line_len *= 2;
line = (char *) realloc(linemax_line_len);
len = (int) strlen(line);
if(fgets(line+lenmax_line_len-leninput) == NULL)
break;
}
return line;
}
void exit_input_error(int line_num)
{
fprintf(stderr“Wrong input format at line %d\n“ line_num);
exit(1);
}
void predict(FILE *input FILE *output)
{
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;
int j;
if(predict_probability)
{
if (svm_type==NU_SVR || svm_type==EPSILON_SVR)
printf(“Prob. model for test data: target value = predicted value + z\nz: Laplace distribution e^(-|z|/sigma)/(2sigma)sigma=%g\n“svm_get_svr_probability(model));
else
{
int *labels=(int *) malloc(nr_class*sizeof(int));
svm_get_labels(modellabels);
prob_estimates = (double *) malloc(nr_class*sizeof(double));
fprintf(output“labels“);
for(j=0;j fprintf(output“ %d“labels[j]);
fprintf(output“\n“);
free(labels);
}
}
max_line_len = 1024;
line = (char *)malloc(max_line_len*sizeof(char));
while(readline(input) != NULL)
{
int i = 0;
double target_label predict_label;
char *idx *val *label *endptr;
int inst_max_index = -1; // strtol gives 0 if wrong format and precomputed kernel has start from 0
label = strtok(line“ \t\n“);
if(label == NULL) // empty line
exit_input_error(total+1);
target_label = strtod(label&endptr);
if(endptr == label || *endptr != ‘\0‘)
exit_input_error(total+1);
while(1)
{
if(i>=max_nr_attr-1) // need one more for index = -1
{
max_nr_attr *= 2;
x = (struct svm_node *) realloc(xmax_nr_attr*sizeof(struct svm_node));
}
idx = strtok(NULL“:“);
val = strtok(NULL“ \t“);
if(val == NULL)
break;
errno = 0;
x[i].index = (int) strtol(idx&endptr10);
if(endptr == idx || errno != 0 || *endptr != ‘\0‘ || x[i].index <= inst_max_index)
exit_input_error(total+1);
else
inst_max_index = x[i].index;
errno = 0;
x[i].value = strtod(val&endptr);
if(endptr == val || errno != 0 || (*endptr != ‘\0‘ && !isspace(*endptr)))
exit_input_error(total+1);
++i;
}
x[i].index = -1;
if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC))
{
predict_label = svm_predict_probability(modelxprob_estimates);
fprintf(output“%g“predict_label);
for(j=0;j fprintf(output“ %g“prob_estimates[j]);
fprintf(output“\n“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1497 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\COPYRIGHT
文件 68901 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\FAQ.html
文件 27670 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\heart_scale
文件 528 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\Makefile
文件 1087 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\Makefile.win
文件 26720 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\README
文件 5381 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm-predict.c
文件 7042 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm-scale.c
文件 8891 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm-train.c
文件 62509 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm.cpp
文件 62509 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm.cpp.bak
文件 434 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm.def
文件 3129 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\svm.h
文件 49854 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm.jar
文件 624 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\Makefile
文件 4267 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\svm_predict.java
文件 8944 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\svm_scale.java
文件 11483 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\svm_toy.java
文件 8268 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\svm_train.java
文件 81 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\test_ap
文件 61931 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm.java
文件 61280 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm.m4
文件 734 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm_model.java
文件 115 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm_node.java
文件 1288 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm_parameter.java
文件 87 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm_print_interface.java
文件 136 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\java\libsvm\svm_problem.java
文件 28904 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\matlab\heart_scale.mat
文件 3988 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\matlab\libsvmread.c
文件 20480 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\matlab\libsvmread.mexw32
文件 2123 2020-09-27 14:58 libsvm\libsvm3.1\libsvm-3.1-[FarutoUltimate3.1Mcode]\matlab\libsvmwrite.c
............此处省略126个文件信息
评论
共有 条评论