Xmipp  v3.23.11-Nereus
Classes | Namespaces | Macros | Enumerations | Functions | Variables
svm.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  svm_node
 
struct  svm_problem
 
struct  svm_parameter
 
struct  svm_model
 

Namespaces

 libsvm
 

Macros

#define LIBSVM_VERSION   325
 

Enumerations

enum  {
  libsvm::C_SVC, libsvm::NU_SVC, libsvm::ONE_CLASS, libsvm::EPSILON_SVR,
  libsvm::NU_SVR
}
 
enum  {
  libsvm::LINEAR, libsvm::POLY, libsvm::RBF, libsvm::SIGMOID,
  libsvm::PRECOMPUTED
}
 

Functions

struct svm_modelsvm_train (const struct svm_problem *prob, const struct svm_parameter *param)
 
void svm_cross_validation (const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target)
 
int svm_save_model (const char *model_file_name, const struct svm_model *model)
 
struct svm_modelsvm_load_model (const char *model_file_name)
 
int svm_get_svm_type (const struct svm_model *model)
 
int svm_get_nr_class (const struct svm_model *model)
 
void svm_get_labels (const struct svm_model *model, int *label)
 
void svm_get_sv_indices (const struct svm_model *model, int *sv_indices)
 
int svm_get_nr_sv (const struct svm_model *model)
 
double svm_get_svr_probability (const struct svm_model *model)
 
double svm_predict_values (const struct svm_model *model, const struct svm_node *x, double *dec_values)
 
double svm_predict (const struct svm_model *model, const struct svm_node *x)
 
double svm_predict_probability (const struct svm_model *model, const struct svm_node *x, double *prob_estimates)
 
void svm_free_model_content (struct svm_model *model_ptr)
 
void svm_free_and_destroy_model (struct svm_model **model_ptr_ptr)
 
void svm_destroy_param (struct svm_parameter *param)
 
const char * svm_check_parameter (const struct svm_problem *prob, const struct svm_parameter *param)
 
int svm_check_probability_model (const struct svm_model *model)
 
void svm_set_print_string_function (void(*print_func)(const char *))
 

Variables

int libsvm_version
 

Macro Definition Documentation

◆ LIBSVM_VERSION

#define LIBSVM_VERSION   325

Definition at line 8 of file svm.h.

Function Documentation

◆ svm_check_parameter()

const char* svm_check_parameter ( const struct svm_problem prob,
const struct svm_parameter param 
)

◆ svm_check_probability_model()

int svm_check_probability_model ( const struct svm_model model)

◆ svm_cross_validation()

void svm_cross_validation ( const struct svm_problem prob,
const struct svm_parameter param,
int  nr_fold,
double *  target 
)

◆ svm_destroy_param()

void svm_destroy_param ( struct svm_parameter param)

Definition at line 3046 of file svm.cpp.

3047 {
3048  free(param->weight_label);
3049  free(param->weight);
3050 }
int * weight_label
Definition: svm.h:47
free((char *) ob)
double * weight
Definition: svm.h:48

◆ svm_free_and_destroy_model()

void svm_free_and_destroy_model ( struct svm_model **  model_ptr_ptr)

Definition at line 3036 of file svm.cpp.

3037 {
3038  if(model_ptr_ptr != NULL && *model_ptr_ptr != NULL)
3039  {
3040  svm_free_model_content(*model_ptr_ptr);
3041  free(*model_ptr_ptr);
3042  *model_ptr_ptr = NULL;
3043  }
3044 }
void svm_free_model_content(svm_model *model_ptr)
Definition: svm.cpp:3001
free((char *) ob)

◆ svm_free_model_content()

void svm_free_model_content ( struct svm_model model_ptr)

Definition at line 3001 of file svm.cpp.

3002 {
3003  if(model_ptr->free_sv && model_ptr->l > 0 && model_ptr->SV != NULL)
3004  free((void *)(model_ptr->SV[0]));
3005  if(model_ptr->sv_coef)
3006  {
3007  for(int i=0;i<model_ptr->nr_class-1;i++)
3008  free(model_ptr->sv_coef[i]);
3009  }
3010 
3011  free(model_ptr->SV);
3012  model_ptr->SV = NULL;
3013 
3014  free(model_ptr->sv_coef);
3015  model_ptr->sv_coef = NULL;
3016 
3017  free(model_ptr->rho);
3018  model_ptr->rho = NULL;
3019 
3020  free(model_ptr->label);
3021  model_ptr->label= NULL;
3022 
3023  free(model_ptr->probA);
3024  model_ptr->probA = NULL;
3025 
3026  free(model_ptr->probB);
3027  model_ptr->probB= NULL;
3028 
3029  free(model_ptr->sv_indices);
3030  model_ptr->sv_indices = NULL;
3031 
3032  free(model_ptr->nSV);
3033  model_ptr->nSV = NULL;
3034 }
int * nSV
Definition: svm.h:73
int l
Definition: svm.h:62
struct svm_node ** SV
Definition: svm.h:63
double * probB
Definition: svm.h:67
#define i
double * probA
Definition: svm.h:66
int nr_class
Definition: svm.h:61
free((char *) ob)
int * label
Definition: svm.h:72
int * sv_indices
Definition: svm.h:68
double * rho
Definition: svm.h:65
double ** sv_coef
Definition: svm.h:64
int free_sv
Definition: svm.h:76

◆ svm_get_labels()

void svm_get_labels ( const struct svm_model model,
int *  label 
)

◆ svm_get_nr_class()

int svm_get_nr_class ( const struct svm_model model)

◆ svm_get_nr_sv()

int svm_get_nr_sv ( const struct svm_model model)

◆ svm_get_sv_indices()

void svm_get_sv_indices ( const struct svm_model model,
int *  sv_indices 
)

◆ svm_get_svm_type()

int svm_get_svm_type ( const struct svm_model model)

◆ svm_get_svr_probability()

double svm_get_svr_probability ( const struct svm_model model)

◆ svm_load_model()

struct svm_model* svm_load_model ( const char *  model_file_name)

Definition at line 2893 of file svm.cpp.

2894 {
2895  FILE *fp = fopen(model_file_name,"rb");
2896  if(fp==NULL) return NULL;
2897 
2898  char *old_locale = setlocale(LC_ALL, NULL);
2899  if (old_locale) {
2900  old_locale = strdup(old_locale);
2901  }
2902  setlocale(LC_ALL, "C");
2903 
2904  // read parameters
2905 
2906  svm_model *model = Malloc(svm_model,1);
2907  model->rho = NULL;
2908  model->probA = NULL;
2909  model->probB = NULL;
2910  model->sv_indices = NULL;
2911  model->label = NULL;
2912  model->nSV = NULL;
2913 
2914  // read header
2915  if (!read_model_header(fp, model))
2916  {
2917  fprintf(stderr, "ERROR: fscanf failed to read model\n");
2918  setlocale(LC_ALL, old_locale);
2919  free(old_locale);
2920  free(model->rho);
2921  free(model->label);
2922  free(model->nSV);
2923  free(model);
2924  return NULL;
2925  }
2926 
2927  // read sv_coef and SV
2928 
2929  int elements = 0;
2930  long pos = ftell(fp);
2931 
2932  max_line_len = 1024;
2933  line = Malloc(char,max_line_len);
2934  char *p,*endptr,*idx,*val;
2935 
2936  while(readline(fp)!=NULL)
2937  {
2938  p = strtok(line,":");
2939  while(1)
2940  {
2941  p = strtok(NULL,":");
2942  if(p == NULL)
2943  break;
2944  ++elements;
2945  }
2946  }
2947  elements += model->l;
2948 
2949  fseek(fp,pos,SEEK_SET);
2950 
2951  int m = model->nr_class - 1;
2952  int l = model->l;
2953  model->sv_coef = Malloc(double *,m);
2954  int i;
2955  for(i=0;i<m;i++)
2956  model->sv_coef[i] = Malloc(double,l);
2957  model->SV = Malloc(svm_node*,l);
2958  svm_node *x_space = NULL;
2959  if(l>0) x_space = Malloc(svm_node,elements);
2960 
2961  int j=0;
2962  for(i=0;i<l;i++)
2963  {
2964  readline(fp);
2965  model->SV[i] = &x_space[j];
2966 
2967  p = strtok(line, " \t");
2968  model->sv_coef[0][i] = strtod(p,&endptr);
2969  for(int k=1;k<m;k++)
2970  {
2971  p = strtok(NULL, " \t");
2972  model->sv_coef[k][i] = strtod(p,&endptr);
2973  }
2974 
2975  while(1)
2976  {
2977  idx = strtok(NULL, ":");
2978  val = strtok(NULL, " \t");
2979 
2980  if(val == NULL)
2981  break;
2982  x_space[j].index = (int) strtol(idx,&endptr,10);
2983  x_space[j].value = strtod(val,&endptr);
2984 
2985  ++j;
2986  }
2987  x_space[j++].index = -1;
2988  }
2989  free(line);
2990 
2991  setlocale(LC_ALL, old_locale);
2992  free(old_locale);
2993 
2994  if (ferror(fp) != 0 || fclose(fp) != 0)
2995  return NULL;
2996 
2997  model->free_sv = 1; // XXX
2998  return model;
2999 }
int * nSV
Definition: svm.h:73
double value
Definition: svm.h:19
int l
Definition: svm.h:62
struct svm_node ** SV
Definition: svm.h:63
double * probB
Definition: svm.h:67
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double * probA
Definition: svm.h:66
int nr_class
Definition: svm.h:61
Definition: svm.h:58
#define Malloc(type, n)
Definition: svm.cpp:45
free((char *) ob)
bool read_model_header(FILE *fp, svm_model *model)
Definition: svm.cpp:2779
int * label
Definition: svm.h:72
int * sv_indices
Definition: svm.h:68
#define j
int m
double * rho
Definition: svm.h:65
int index
Definition: svm.h:18
double ** sv_coef
Definition: svm.h:64
int free_sv
Definition: svm.h:76
Definition: svm.h:16
fprintf(glob_prnt.io, "\)

◆ svm_predict()

double svm_predict ( const struct svm_model model,
const struct svm_node x 
)

◆ svm_predict_probability()

double svm_predict_probability ( const struct svm_model model,
const struct svm_node x,
double *  prob_estimates 
)

◆ svm_predict_values()

double svm_predict_values ( const struct svm_model model,
const struct svm_node x,
double *  dec_values 
)

◆ svm_save_model()

int svm_save_model ( const char *  model_file_name,
const struct svm_model model 
)

◆ svm_set_print_string_function()

void svm_set_print_string_function ( void(*)(const char *)  print_func)

Definition at line 3182 of file svm.cpp.

3183 {
3184  if(print_func == NULL)
3185  svm_print_string = &print_string_stdout;
3186  else
3187  svm_print_string = print_func;
3188 }

◆ svm_train()

struct svm_model* svm_train ( const struct svm_problem prob,
const struct svm_parameter param 
)

Variable Documentation

◆ libsvm_version

int libsvm_version

Definition at line 17 of file svm.cpp.