资源简介
台湾大学林智仁开发的libsvm的matlab最新版libsvm-3.21
代码片段和文件信息
#include
#include
#include
#include
#include
#include “svm.h“
int print_null(const char *s...) {return 0;}
static int (*info)(const char *fmt...) = &printf;
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)
info(“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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-12-14 13:46 libsvm-master\
文件 1497 2015-12-14 13:46 libsvm-master\COPYRIGHT
文件 83089 2015-12-14 13:46 libsvm-master\FAQ.html
文件 732 2015-12-14 13:46 libsvm-master\Makefile
文件 1136 2015-12-14 13:46 libsvm-master\Makefile.win
文件 28679 2015-12-14 13:46 libsvm-master\README
文件 27670 2015-12-14 13:46 libsvm-master\heart_scale
目录 0 2015-12-14 13:46 libsvm-master\java\
文件 624 2015-12-14 13:46 libsvm-master\java\Makefile
文件 51947 2015-12-14 13:46 libsvm-master\java\libsvm.jar
目录 0 2015-12-14 13:46 libsvm-master\java\libsvm\
文件 63839 2015-12-14 13:46 libsvm-master\java\libsvm\svm.java
文件 63132 2015-12-14 13:46 libsvm-master\java\libsvm\svm.m4
文件 868 2015-12-14 13:46 libsvm-master\java\libsvm\svm_model.java
文件 115 2015-12-14 13:46 libsvm-master\java\libsvm\svm_node.java
文件 1288 2015-12-14 13:46 libsvm-master\java\libsvm\svm_parameter.java
文件 87 2015-12-14 13:46 libsvm-master\java\libsvm\svm_print_interface.java
文件 136 2015-12-14 13:46 libsvm-master\java\libsvm\svm_problem.java
文件 4950 2015-12-14 13:46 libsvm-master\java\svm_predict.java
文件 8944 2015-12-14 13:46 libsvm-master\java\svm_scale.java
文件 12269 2015-12-14 13:46 libsvm-master\java\svm_toy.java
文件 8355 2015-12-14 13:46 libsvm-master\java\svm_train.java
文件 81 2015-12-14 13:46 libsvm-master\java\test_ap
目录 0 2015-12-14 13:46 libsvm-master\matlab\
文件 1240 2015-12-14 13:46 libsvm-master\matlab\Makefile
文件 9826 2015-12-14 13:46 libsvm-master\matlab\README
文件 4063 2015-12-14 13:46 libsvm-master\matlab\libsvmread.c
文件 2341 2015-12-14 13:46 libsvm-master\matlab\libsvmwrite.c
文件 888 2015-12-14 13:46 libsvm-master\matlab\make.m
文件 8205 2015-12-14 13:46 libsvm-master\matlab\svm_model_matlab.c
文件 201 2015-12-14 13:46 libsvm-master\matlab\svm_model_matlab.h
............此处省略43个文件信息
- 上一篇:循环普的 估计fam
- 下一篇:跳频通信原理介绍.zip
评论
共有 条评论