Xmipp  v3.23.11-Nereus
Classes | Macros | Typedefs | Functions | Variables
svm.cpp File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <locale.h>
#include "svm.h"
Include dependency graph for svm.cpp:

Go to the source code of this file.

Classes

class  Cache
 
class  QMatrix
 
class  Kernel
 
class  Solver
 
struct  Solver::SolutionInfo
 
class  Solver_NU
 
class  SVC_Q
 
class  ONE_CLASS_Q
 
class  SVR_Q
 
struct  decision_function
 

Macros

#define INF   HUGE_VAL
 
#define TAU   1e-12
 
#define Malloc(type, n)   (type *)malloc((n)*sizeof(type))
 
#define FSCANF(_stream, _format, _var)   do{ if (fscanf(_stream, _format, _var) != 1) return false; }while(0)
 

Typedefs

typedef float Qfloat
 
typedef signed char schar
 

Functions

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

Variables

int libsvm_version = LIBSVM_VERSION
 

Macro Definition Documentation

◆ FSCANF

#define FSCANF (   _stream,
  _format,
  _var 
)    do{ if (fscanf(_stream, _format, _var) != 1) return false; }while(0)

Definition at line 2778 of file svm.cpp.

◆ INF

#define INF   HUGE_VAL

Definition at line 43 of file svm.cpp.

◆ Malloc

#define Malloc (   type,
  n 
)    (type *)malloc((n)*sizeof(type))

Definition at line 45 of file svm.cpp.

◆ TAU

#define TAU   1e-12

Definition at line 44 of file svm.cpp.

Typedef Documentation

◆ Qfloat

typedef float Qfloat

Definition at line 18 of file svm.cpp.

◆ schar

typedef signed char schar

Definition at line 19 of file svm.cpp.

Function Documentation

◆ read_model_header()

bool read_model_header ( FILE *  fp,
svm_model model 
)

Definition at line 2779 of file svm.cpp.

2780 {
2781  svm_parameter& param = model->param;
2782  // parameters for training only won't be assigned, but arrays are assigned as NULL for safety
2783  param.nr_weight = 0;
2784  param.weight_label = NULL;
2785  param.weight = NULL;
2786 
2787  char cmd[81];
2788  while(1)
2789  {
2790  FSCANF(fp,"%80s",cmd);
2791 
2792  if(strcmp(cmd,"svm_type")==0)
2793  {
2794  FSCANF(fp,"%80s",cmd);
2795  int i;
2796  for(i=0;svm_type_table[i];i++)
2797  {
2798  if(strcmp(svm_type_table[i],cmd)==0)
2799  {
2800  param.svm_type=i;
2801  break;
2802  }
2803  }
2804  if(svm_type_table[i] == NULL)
2805  {
2806  fprintf(stderr,"unknown svm type.\n");
2807  return false;
2808  }
2809  }
2810  else if(strcmp(cmd,"kernel_type")==0)
2811  {
2812  FSCANF(fp,"%80s",cmd);
2813  int i;
2814  for(i=0;kernel_type_table[i];i++)
2815  {
2816  if(strcmp(kernel_type_table[i],cmd)==0)
2817  {
2818  param.kernel_type=i;
2819  break;
2820  }
2821  }
2822  if(kernel_type_table[i] == NULL)
2823  {
2824  fprintf(stderr,"unknown kernel function.\n");
2825  return false;
2826  }
2827  }
2828  else if(strcmp(cmd,"degree")==0)
2829  FSCANF(fp,"%d",&param.degree);
2830  else if(strcmp(cmd,"gamma")==0)
2831  FSCANF(fp,"%lf",&param.gamma);
2832  else if(strcmp(cmd,"coef0")==0)
2833  FSCANF(fp,"%lf",&param.coef0);
2834  else if(strcmp(cmd,"nr_class")==0)
2835  FSCANF(fp,"%d",&model->nr_class);
2836  else if(strcmp(cmd,"total_sv")==0)
2837  FSCANF(fp,"%d",&model->l);
2838  else if(strcmp(cmd,"rho")==0)
2839  {
2840  int n = model->nr_class * (model->nr_class-1)/2;
2841  model->rho = Malloc(double,n);
2842  for(int i=0;i<n;i++)
2843  FSCANF(fp,"%lf",&model->rho[i]);
2844  }
2845  else if(strcmp(cmd,"label")==0)
2846  {
2847  int n = model->nr_class;
2848  model->label = Malloc(int,n);
2849  for(int i=0;i<n;i++)
2850  FSCANF(fp,"%d",&model->label[i]);
2851  }
2852  else if(strcmp(cmd,"probA")==0)
2853  {
2854  int n = model->nr_class * (model->nr_class-1)/2;
2855  model->probA = Malloc(double,n);
2856  for(int i=0;i<n;i++)
2857  FSCANF(fp,"%lf",&model->probA[i]);
2858  }
2859  else if(strcmp(cmd,"probB")==0)
2860  {
2861  int n = model->nr_class * (model->nr_class-1)/2;
2862  model->probB = Malloc(double,n);
2863  for(int i=0;i<n;i++)
2864  FSCANF(fp,"%lf",&model->probB[i]);
2865  }
2866  else if(strcmp(cmd,"nr_sv")==0)
2867  {
2868  int n = model->nr_class;
2869  model->nSV = Malloc(int,n);
2870  for(int i=0;i<n;i++)
2871  FSCANF(fp,"%d",&model->nSV[i]);
2872  }
2873  else if(strcmp(cmd,"SV")==0)
2874  {
2875  while(1)
2876  {
2877  int c = getc(fp);
2878  if(c==EOF || c=='\n') break;
2879  }
2880  break;
2881  }
2882  else
2883  {
2884  fprintf(stderr,"unknown text in model file: [%s]\n",cmd);
2885  return false;
2886  }
2887  }
2888 
2889  return true;
2890 
2891 }
int * nSV
Definition: svm.h:73
#define FSCANF(_stream, _format, _var)
Definition: svm.cpp:2778
doublereal * c
int l
Definition: svm.h:62
int nr_weight
Definition: svm.h:46
double * probB
Definition: svm.h:67
int * weight_label
Definition: svm.h:47
#define i
double * probA
Definition: svm.h:66
int nr_class
Definition: svm.h:61
#define Malloc(type, n)
Definition: svm.cpp:45
int * label
Definition: svm.h:72
struct svm_parameter param
Definition: svm.h:60
double * rho
Definition: svm.h:65
struct _parameter * param
int degree
Definition: svm.h:38
fprintf(glob_prnt.io, "\)
double gamma
Definition: svm.h:39
double * weight
Definition: svm.h:48
int svm_type
Definition: svm.h:36
double coef0
Definition: svm.h:40
int * n
int kernel_type
Definition: svm.h:37

◆ svm_check_parameter()

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

Definition at line 3052 of file svm.cpp.

3053 {
3054  // svm_type
3055 
3056  int svm_type = param->svm_type;
3057  if(svm_type != C_SVC &&
3058  svm_type != NU_SVC &&
3059  svm_type != ONE_CLASS &&
3060  svm_type != EPSILON_SVR &&
3061  svm_type != NU_SVR)
3062  return "unknown svm type";
3063 
3064  // kernel_type, degree
3065 
3066  int kernel_type = param->kernel_type;
3067  if(kernel_type != LINEAR &&
3068  kernel_type != POLY &&
3069  kernel_type != RBF &&
3070  kernel_type != SIGMOID &&
3071  kernel_type != PRECOMPUTED)
3072  return "unknown kernel type";
3073 
3074  if((kernel_type == POLY || kernel_type == RBF || kernel_type == SIGMOID) &&
3075  param->gamma < 0)
3076  return "gamma < 0";
3077 
3078  if(kernel_type == POLY && param->degree < 0)
3079  return "degree of polynomial kernel < 0";
3080 
3081  // cache_size,eps,C,nu,p,shrinking
3082 
3083  if(param->cache_size <= 0)
3084  return "cache_size <= 0";
3085 
3086  if(param->eps <= 0)
3087  return "eps <= 0";
3088 
3089  if(svm_type == C_SVC ||
3090  svm_type == EPSILON_SVR ||
3091  svm_type == NU_SVR)
3092  if(param->C <= 0)
3093  return "C <= 0";
3094 
3095  if(svm_type == NU_SVC ||
3096  svm_type == ONE_CLASS ||
3097  svm_type == NU_SVR)
3098  if(param->nu <= 0 || param->nu > 1)
3099  return "nu <= 0 or nu > 1";
3100 
3101  if(svm_type == EPSILON_SVR)
3102  if(param->p < 0)
3103  return "p < 0";
3104 
3105  if(param->shrinking != 0 &&
3106  param->shrinking != 1)
3107  return "shrinking != 0 and shrinking != 1";
3108 
3109  if(param->probability != 0 &&
3110  param->probability != 1)
3111  return "probability != 0 and probability != 1";
3112 
3113  if(param->probability == 1 &&
3114  svm_type == ONE_CLASS)
3115  return "one-class SVM probability output not supported yet";
3116 
3117 
3118  // check whether nu-svc is feasible
3119 
3120  if(svm_type == NU_SVC)
3121  {
3122  int l = prob->l;
3123  int max_nr_class = 16;
3124  int nr_class = 0;
3125  int *label = Malloc(int,max_nr_class);
3126  int *count = Malloc(int,max_nr_class);
3127 
3128  int i;
3129  for(i=0;i<l;i++)
3130  {
3131  int this_label = (int)prob->y[i];
3132  int j;
3133  for(j=0;j<nr_class;j++)
3134  if(this_label == label[j])
3135  {
3136  ++count[j];
3137  break;
3138  }
3139  if(j == nr_class)
3140  {
3141  if(nr_class == max_nr_class)
3142  {
3143  max_nr_class *= 2;
3144  label = (int *)realloc(label,max_nr_class*sizeof(int));
3145  count = (int *)realloc(count,max_nr_class*sizeof(int));
3146  }
3147  label[nr_class] = this_label;
3148  count[nr_class] = 1;
3149  ++nr_class;
3150  }
3151  }
3152 
3153  for(i=0;i<nr_class;i++)
3154  {
3155  int n1 = count[i];
3156  for(int j=i+1;j<nr_class;j++)
3157  {
3158  int n2 = count[j];
3159  if(param->nu*(n1+n2)/2 > min(n1,n2))
3160  {
3161  free(label);
3162  free(count);
3163  return "specified nu is infeasible";
3164  }
3165  }
3166  }
3167  free(label);
3168  free(count);
3169  }
3170 
3171  return NULL;
3172 }
void min(Image< double > &op1, const Image< double > &op2)
#define i
double p
Definition: svm.h:50
double cache_size
Definition: svm.h:43
#define Malloc(type, n)
Definition: svm.cpp:45
double eps
Definition: svm.h:44
free((char *) ob)
int shrinking
Definition: svm.h:51
#define j
int probability
Definition: svm.h:52
int degree
Definition: svm.h:38
double * y
Definition: svm.h:25
double gamma
Definition: svm.h:39
int l
Definition: svm.h:24
double C
Definition: svm.h:45
int svm_type
Definition: svm.h:36
double nu
Definition: svm.h:49
int kernel_type
Definition: svm.h:37

◆ svm_check_probability_model()

int svm_check_probability_model ( const svm_model model)

Definition at line 3174 of file svm.cpp.

3175 {
3176  return ((model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) &&
3177  model->probA!=NULL && model->probB!=NULL) ||
3178  ((model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) &&
3179  model->probA!=NULL);
3180 }
double * probB
Definition: svm.h:67
double * probA
Definition: svm.h:66
struct svm_parameter param
Definition: svm.h:60
int svm_type
Definition: svm.h:36

◆ svm_cross_validation()

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

Definition at line 2345 of file svm.cpp.

2346 {
2347  int i;
2348  int *fold_start;
2349  int l = prob->l;
2350  int *perm = Malloc(int,l);
2351  int nr_class;
2352  if (nr_fold > l)
2353  {
2354  nr_fold = l;
2355  fprintf(stderr,"WARNING: # folds > # data. Will use # folds = # data instead (i.e., leave-one-out cross validation)\n");
2356  }
2357  fold_start = Malloc(int,nr_fold+1);
2358  // stratified cv may not give leave-one-out rate
2359  // Each class to l folds -> some folds may have zero elements
2360  if((param->svm_type == C_SVC ||
2361  param->svm_type == NU_SVC) && nr_fold < l)
2362  {
2363  int *start = NULL;
2364  int *label = NULL;
2365  int *count = NULL;
2366  svm_group_classes(prob,&nr_class,&label,&start,&count,perm);
2367 
2368  // random shuffle and then data grouped by fold using the array perm
2369  int *fold_count = Malloc(int,nr_fold);
2370  int c;
2371  int *index = Malloc(int,l);
2372  for(i=0;i<l;i++)
2373  index[i]=perm[i];
2374  for (c=0; c<nr_class; c++)
2375  for(i=0;i<count[c];i++)
2376  {
2377  int j = i+rand()%(count[c]-i);
2378  swap(index[start[c]+j],index[start[c]+i]);
2379  }
2380  for(i=0;i<nr_fold;i++)
2381  {
2382  fold_count[i] = 0;
2383  for (c=0; c<nr_class;c++)
2384  fold_count[i]+=(i+1)*count[c]/nr_fold-i*count[c]/nr_fold;
2385  }
2386  fold_start[0]=0;
2387  for (i=1;i<=nr_fold;i++)
2388  fold_start[i] = fold_start[i-1]+fold_count[i-1];
2389  for (c=0; c<nr_class;c++)
2390  for(i=0;i<nr_fold;i++)
2391  {
2392  int begin = start[c]+i*count[c]/nr_fold;
2393  int end = start[c]+(i+1)*count[c]/nr_fold;
2394  for(int j=begin;j<end;j++)
2395  {
2396  perm[fold_start[i]] = index[j];
2397  fold_start[i]++;
2398  }
2399  }
2400  fold_start[0]=0;
2401  for (i=1;i<=nr_fold;i++)
2402  fold_start[i] = fold_start[i-1]+fold_count[i-1];
2403  free(start);
2404  free(label);
2405  free(count);
2406  free(index);
2407  free(fold_count);
2408  }
2409  else
2410  {
2411  for(i=0;i<l;i++) perm[i]=i;
2412  for(i=0;i<l;i++)
2413  {
2414  int j = i+rand()%(l-i);
2415  swap(perm[i],perm[j]);
2416  }
2417  for(i=0;i<=nr_fold;i++)
2418  fold_start[i]=i*l/nr_fold;
2419  }
2420 
2421  for(i=0;i<nr_fold;i++)
2422  {
2423  int begin = fold_start[i];
2424  int end = fold_start[i+1];
2425  int j,k;
2426  struct svm_problem subprob;
2427 
2428  subprob.l = l-(end-begin);
2429  subprob.x = Malloc(struct svm_node*,subprob.l);
2430  subprob.y = Malloc(double,subprob.l);
2431 
2432  k=0;
2433  for(j=0;j<begin;j++)
2434  {
2435  subprob.x[k] = prob->x[perm[j]];
2436  subprob.y[k] = prob->y[perm[j]];
2437  ++k;
2438  }
2439  for(j=end;j<l;j++)
2440  {
2441  subprob.x[k] = prob->x[perm[j]];
2442  subprob.y[k] = prob->y[perm[j]];
2443  ++k;
2444  }
2445  struct svm_model *submodel = svm_train(&subprob,param);
2446  if(param->probability &&
2447  (param->svm_type == C_SVC || param->svm_type == NU_SVC))
2448  {
2449  double *prob_estimates=Malloc(double,svm_get_nr_class(submodel));
2450  for(j=begin;j<end;j++)
2451  target[perm[j]] = svm_predict_probability(submodel,prob->x[perm[j]],prob_estimates);
2452  free(prob_estimates);
2453  }
2454  else
2455  for(j=begin;j<end;j++)
2456  target[perm[j]] = svm_predict(submodel,prob->x[perm[j]]);
2457  svm_free_and_destroy_model(&submodel);
2458  free(subprob.x);
2459  free(subprob.y);
2460  }
2461  free(fold_start);
2462  free(perm);
2463 }
int svm_get_nr_class(const svm_model *model)
Definition: svm.cpp:2471
doublereal * c
double svm_predict_probability(const svm_model *model, const svm_node *x, double *prob_estimates)
Definition: svm.cpp:2598
svm_model * svm_train(const svm_problem *prob, const svm_parameter *param)
Definition: svm.cpp:2098
void svm_free_and_destroy_model(svm_model **model_ptr_ptr)
Definition: svm.cpp:3036
#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
Definition: svm.h:58
viol index
#define Malloc(type, n)
Definition: svm.cpp:45
free((char *) ob)
struct svm_node ** x
Definition: svm.h:26
#define j
double svm_predict(const svm_model *model, const svm_node *x)
Definition: svm.cpp:2583
int probability
Definition: svm.h:52
Definition: svm.h:16
double * y
Definition: svm.h:25
fprintf(glob_prnt.io, "\)
int l
Definition: svm.h:24
int svm_type
Definition: svm.h:36

◆ svm_destroy_param()

void svm_destroy_param ( 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 ( 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 ( 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 svm_model model,
int *  label 
)

Definition at line 2476 of file svm.cpp.

2477 {
2478  if (model->label != NULL)
2479  for(int i=0;i<model->nr_class;i++)
2480  label[i] = model->label[i];
2481 }
#define i
int nr_class
Definition: svm.h:61
int * label
Definition: svm.h:72

◆ svm_get_nr_class()

int svm_get_nr_class ( const svm_model model)

Definition at line 2471 of file svm.cpp.

2472 {
2473  return model->nr_class;
2474 }
int nr_class
Definition: svm.h:61

◆ svm_get_nr_sv()

int svm_get_nr_sv ( const svm_model model)

Definition at line 2490 of file svm.cpp.

2491 {
2492  return model->l;
2493 }
int l
Definition: svm.h:62

◆ svm_get_sv_indices()

void svm_get_sv_indices ( const svm_model model,
int *  indices 
)

Definition at line 2483 of file svm.cpp.

2484 {
2485  if (model->sv_indices != NULL)
2486  for(int i=0;i<model->l;i++)
2487  indices[i] = model->sv_indices[i];
2488 }
int l
Definition: svm.h:62
#define i
int * sv_indices
Definition: svm.h:68

◆ svm_get_svm_type()

int svm_get_svm_type ( const svm_model model)

Definition at line 2466 of file svm.cpp.

2467 {
2468  return model->param.svm_type;
2469 }
struct svm_parameter param
Definition: svm.h:60
int svm_type
Definition: svm.h:36

◆ svm_get_svr_probability()

double svm_get_svr_probability ( const svm_model model)

Definition at line 2495 of file svm.cpp.

2496 {
2497  if ((model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) &&
2498  model->probA!=NULL)
2499  return model->probA[0];
2500  else
2501  {
2502  fprintf(stderr,"Model doesn't contain information for SVR probability inference\n");
2503  return 0;
2504  }
2505 }
double * probA
Definition: svm.h:66
struct svm_parameter param
Definition: svm.h:60
fprintf(glob_prnt.io, "\)
int svm_type
Definition: svm.h:36

◆ svm_load_model()

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 svm_model model,
const svm_node x 
)

Definition at line 2583 of file svm.cpp.

2584 {
2585  int nr_class = model->nr_class;
2586  double *dec_values;
2587  if(model->param.svm_type == ONE_CLASS ||
2588  model->param.svm_type == EPSILON_SVR ||
2589  model->param.svm_type == NU_SVR)
2590  dec_values = Malloc(double, 1);
2591  else
2592  dec_values = Malloc(double, nr_class*(nr_class-1)/2);
2593  double pred_result = svm_predict_values(model, x, dec_values);
2594  free(dec_values);
2595  return pred_result;
2596 }
int nr_class
Definition: svm.h:61
#define Malloc(type, n)
Definition: svm.cpp:45
free((char *) ob)
struct svm_parameter param
Definition: svm.h:60
double svm_predict_values(const svm_model *model, const svm_node *x, double *dec_values)
Definition: svm.cpp:2507
int svm_type
Definition: svm.h:36

◆ svm_predict_probability()

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

Definition at line 2598 of file svm.cpp.

2600 {
2601  if ((model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) &&
2602  model->probA!=NULL && model->probB!=NULL)
2603  {
2604  int i;
2605  int nr_class = model->nr_class;
2606  double *dec_values = Malloc(double, nr_class*(nr_class-1)/2);
2607  svm_predict_values(model, x, dec_values);
2608 
2609  double min_prob=1e-7;
2610  double **pairwise_prob=Malloc(double *,nr_class);
2611  for(i=0;i<nr_class;i++)
2612  pairwise_prob[i]=Malloc(double,nr_class);
2613  int k=0;
2614  for(i=0;i<nr_class;i++)
2615  for(int j=i+1;j<nr_class;j++)
2616  {
2617  pairwise_prob[i][j]=min(max(sigmoid_predict(dec_values[k],model->probA[k],model->probB[k]),min_prob),1-min_prob);
2618  pairwise_prob[j][i]=1-pairwise_prob[i][j];
2619  k++;
2620  }
2621  if (nr_class == 2)
2622  {
2623  prob_estimates[0] = pairwise_prob[0][1];
2624  prob_estimates[1] = pairwise_prob[1][0];
2625  }
2626  else
2627  multiclass_probability(nr_class,pairwise_prob,prob_estimates);
2628 
2629  int prob_max_idx = 0;
2630  for(i=1;i<nr_class;i++)
2631  if(prob_estimates[i] > prob_estimates[prob_max_idx])
2632  prob_max_idx = i;
2633  for(i=0;i<nr_class;i++)
2634  free(pairwise_prob[i]);
2635  free(dec_values);
2636  free(pairwise_prob);
2637  return model->label[prob_max_idx];
2638  }
2639  else
2640  return svm_predict(model, x);
2641 }
void min(Image< double > &op1, const Image< double > &op2)
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
#define Malloc(type, n)
Definition: svm.cpp:45
void max(Image< double > &op1, const Image< double > &op2)
free((char *) ob)
int * label
Definition: svm.h:72
struct svm_parameter param
Definition: svm.h:60
#define j
double svm_predict_values(const svm_model *model, const svm_node *x, double *dec_values)
Definition: svm.cpp:2507
double svm_predict(const svm_model *model, const svm_node *x)
Definition: svm.cpp:2583
int svm_type
Definition: svm.h:36

◆ svm_predict_values()

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

Definition at line 2507 of file svm.cpp.

2508 {
2509  int i;
2510  if(model->param.svm_type == ONE_CLASS ||
2511  model->param.svm_type == EPSILON_SVR ||
2512  model->param.svm_type == NU_SVR)
2513  {
2514  double *sv_coef = model->sv_coef[0];
2515  double sum = 0;
2516  for(i=0;i<model->l;i++)
2517  sum += sv_coef[i] * Kernel::k_function(x,model->SV[i],model->param);
2518  sum -= model->rho[0];
2519  *dec_values = sum;
2520 
2521  if(model->param.svm_type == ONE_CLASS)
2522  return (sum>0)?1:-1;
2523  else
2524  return sum;
2525  }
2526  else
2527  {
2528  int nr_class = model->nr_class;
2529  int l = model->l;
2530 
2531  double *kvalue = Malloc(double,l);
2532  for(i=0;i<l;i++)
2533  kvalue[i] = Kernel::k_function(x,model->SV[i],model->param);
2534 
2535  int *start = Malloc(int,nr_class);
2536  start[0] = 0;
2537  for(i=1;i<nr_class;i++)
2538  start[i] = start[i-1]+model->nSV[i-1];
2539 
2540  int *vote = Malloc(int,nr_class);
2541  for(i=0;i<nr_class;i++)
2542  vote[i] = 0;
2543 
2544  int p=0;
2545  for(i=0;i<nr_class;i++)
2546  for(int j=i+1;j<nr_class;j++)
2547  {
2548  double sum = 0;
2549  int si = start[i];
2550  int sj = start[j];
2551  int ci = model->nSV[i];
2552  int cj = model->nSV[j];
2553 
2554  int k;
2555  double *coef1 = model->sv_coef[j-1];
2556  double *coef2 = model->sv_coef[i];
2557  for(k=0;k<ci;k++)
2558  sum += coef1[si+k] * kvalue[si+k];
2559  for(k=0;k<cj;k++)
2560  sum += coef2[sj+k] * kvalue[sj+k];
2561  sum -= model->rho[p];
2562  dec_values[p] = sum;
2563 
2564  if(dec_values[p] > 0)
2565  ++vote[i];
2566  else
2567  ++vote[j];
2568  p++;
2569  }
2570 
2571  int vote_max_idx = 0;
2572  for(i=1;i<nr_class;i++)
2573  if(vote[i] > vote[vote_max_idx])
2574  vote_max_idx = i;
2575 
2576  free(kvalue);
2577  free(start);
2578  free(vote);
2579  return model->label[vote_max_idx];
2580  }
2581 }
int * nSV
Definition: svm.h:73
int l
Definition: svm.h:62
struct svm_node ** SV
Definition: svm.h:63
#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
int nr_class
Definition: svm.h:61
#define Malloc(type, n)
Definition: svm.cpp:45
free((char *) ob)
int * label
Definition: svm.h:72
struct svm_parameter param
Definition: svm.h:60
#define j
double * rho
Definition: svm.h:65
double ** sv_coef
Definition: svm.h:64
static double k_function(const svm_node *x, const svm_node *y, const svm_parameter &param)
Definition: svm.cpp:322
int svm_type
Definition: svm.h:36

◆ svm_save_model()

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

Definition at line 2653 of file svm.cpp.

2654 {
2655  FILE *fp = fopen(model_file_name,"w");
2656  if(fp==NULL) return -1;
2657 
2658  char *old_locale = setlocale(LC_ALL, NULL);
2659  if (old_locale) {
2660  old_locale = strdup(old_locale);
2661  }
2662  setlocale(LC_ALL, "C");
2663 
2664  const svm_parameter& param = model->param;
2665 
2666  fprintf(fp,"svm_type %s\n", svm_type_table[param.svm_type]);
2667  fprintf(fp,"kernel_type %s\n", kernel_type_table[param.kernel_type]);
2668 
2669  if(param.kernel_type == POLY)
2670  fprintf(fp,"degree %d\n", param.degree);
2671 
2672  if(param.kernel_type == POLY || param.kernel_type == RBF || param.kernel_type == SIGMOID)
2673  fprintf(fp,"gamma %.17g\n", param.gamma);
2674 
2675  if(param.kernel_type == POLY || param.kernel_type == SIGMOID)
2676  fprintf(fp,"coef0 %.17g\n", param.coef0);
2677 
2678  int nr_class = model->nr_class;
2679  int l = model->l;
2680  fprintf(fp, "nr_class %d\n", nr_class);
2681  fprintf(fp, "total_sv %d\n",l);
2682 
2683  {
2684  fprintf(fp, "rho");
2685  for(int i=0;i<nr_class*(nr_class-1)/2;i++)
2686  fprintf(fp," %.17g",model->rho[i]);
2687  fprintf(fp, "\n");
2688  }
2689 
2690  if(model->label)
2691  {
2692  fprintf(fp, "label");
2693  for(int i=0;i<nr_class;i++)
2694  fprintf(fp," %d",model->label[i]);
2695  fprintf(fp, "\n");
2696  }
2697 
2698  if(model->probA) // regression has probA only
2699  {
2700  fprintf(fp, "probA");
2701  for(int i=0;i<nr_class*(nr_class-1)/2;i++)
2702  fprintf(fp," %.17g",model->probA[i]);
2703  fprintf(fp, "\n");
2704  }
2705  if(model->probB)
2706  {
2707  fprintf(fp, "probB");
2708  for(int i=0;i<nr_class*(nr_class-1)/2;i++)
2709  fprintf(fp," %.17g",model->probB[i]);
2710  fprintf(fp, "\n");
2711  }
2712 
2713  if(model->nSV)
2714  {
2715  fprintf(fp, "nr_sv");
2716  for(int i=0;i<nr_class;i++)
2717  fprintf(fp," %d",model->nSV[i]);
2718  fprintf(fp, "\n");
2719  }
2720 
2721  fprintf(fp, "SV\n");
2722  const double * const *sv_coef = model->sv_coef;
2723  const svm_node * const *SV = model->SV;
2724 
2725  for(int i=0;i<l;i++)
2726  {
2727  for(int j=0;j<nr_class-1;j++)
2728  fprintf(fp, "%.17g ",sv_coef[j][i]);
2729 
2730  const svm_node *p = SV[i];
2731 
2732  if(param.kernel_type == PRECOMPUTED)
2733  fprintf(fp,"0:%d ",(int)(p->value));
2734  else
2735  while(p->index != -1)
2736  {
2737  fprintf(fp,"%d:%.8g ",p->index,p->value);
2738  p++;
2739  }
2740  fprintf(fp, "\n");
2741  }
2742 
2743  setlocale(LC_ALL, old_locale);
2744  free(old_locale);
2745 
2746  if (ferror(fp) != 0 || fclose(fp) != 0) return -1;
2747  else return 0;
2748 }
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
double * probA
Definition: svm.h:66
int nr_class
Definition: svm.h:61
free((char *) ob)
int * label
Definition: svm.h:72
struct svm_parameter param
Definition: svm.h:60
#define j
double * rho
Definition: svm.h:65
int index
Definition: svm.h:18
struct _parameter * param
double ** sv_coef
Definition: svm.h:64
int degree
Definition: svm.h:38
Definition: svm.h:16
fprintf(glob_prnt.io, "\)
double gamma
Definition: svm.h:39
int svm_type
Definition: svm.h:36
double coef0
Definition: svm.h:40
int kernel_type
Definition: svm.h:37

◆ 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()

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

Definition at line 2098 of file svm.cpp.

2099 {
2100  svm_model *model = Malloc(svm_model,1);
2101  model->param = *param;
2102  model->free_sv = 0; // XXX
2103 
2104  if(param->svm_type == ONE_CLASS ||
2105  param->svm_type == EPSILON_SVR ||
2106  param->svm_type == NU_SVR)
2107  {
2108  // regression or one-class-svm
2109  model->nr_class = 2;
2110  model->label = NULL;
2111  model->nSV = NULL;
2112  model->probA = NULL; model->probB = NULL;
2113  model->sv_coef = Malloc(double *,1);
2114 
2115  if(param->probability &&
2116  (param->svm_type == EPSILON_SVR ||
2117  param->svm_type == NU_SVR))
2118  {
2119  model->probA = Malloc(double,1);
2120  model->probA[0] = svm_svr_probability(prob,param);
2121  }
2122 
2123  decision_function f = svm_train_one(prob,param,0,0);
2124  model->rho = Malloc(double,1);
2125  model->rho[0] = f.rho;
2126 
2127  int nSV = 0;
2128  int i;
2129  for(i=0;i<prob->l;i++)
2130  if(fabs(f.alpha[i]) > 0) ++nSV;
2131  model->l = nSV;
2132  model->SV = Malloc(svm_node *,nSV);
2133  model->sv_coef[0] = Malloc(double,nSV);
2134  model->sv_indices = Malloc(int,nSV);
2135  int j = 0;
2136  for(i=0;i<prob->l;i++)
2137  if(fabs(f.alpha[i]) > 0)
2138  {
2139  model->SV[j] = prob->x[i];
2140  model->sv_coef[0][j] = f.alpha[i];
2141  model->sv_indices[j] = i+1;
2142  ++j;
2143  }
2144 
2145  free(f.alpha);
2146  }
2147  else
2148  {
2149  // classification
2150  int l = prob->l;
2151  int nr_class;
2152  int *label = NULL;
2153  int *start = NULL;
2154  int *count = NULL;
2155  int *perm = Malloc(int,l);
2156 
2157  // group training data of the same class
2158  svm_group_classes(prob,&nr_class,&label,&start,&count,perm);
2159  if(nr_class == 1)
2160  info("WARNING: training data in only one class. See README for details.\n");
2161 
2162  svm_node **x = Malloc(svm_node *,l);
2163  int i;
2164  for(i=0;i<l;i++)
2165  x[i] = prob->x[perm[i]];
2166 
2167  // calculate weighted C
2168 
2169  double *weighted_C = Malloc(double, nr_class);
2170  for(i=0;i<nr_class;i++)
2171  weighted_C[i] = param->C;
2172  for(i=0;i<param->nr_weight;i++)
2173  {
2174  int j;
2175  for(j=0;j<nr_class;j++)
2176  if(param->weight_label[i] == label[j])
2177  break;
2178  if(j == nr_class)
2179  fprintf(stderr,"WARNING: class label %d specified in weight is not found\n", param->weight_label[i]);
2180  else
2181  weighted_C[j] *= param->weight[i];
2182  }
2183 
2184  // train k*(k-1)/2 models
2185 
2186  bool *nonzero = Malloc(bool,l);
2187  for(i=0;i<l;i++)
2188  nonzero[i] = false;
2189  decision_function *f = Malloc(decision_function,nr_class*(nr_class-1)/2);
2190 
2191  double *probA=NULL,*probB=NULL;
2192  if (param->probability)
2193  {
2194  probA=Malloc(double,nr_class*(nr_class-1)/2);
2195  probB=Malloc(double,nr_class*(nr_class-1)/2);
2196  }
2197 
2198  int p = 0;
2199  for(i=0;i<nr_class;i++)
2200  for(int j=i+1;j<nr_class;j++)
2201  {
2202  svm_problem sub_prob;
2203  int si = start[i], sj = start[j];
2204  int ci = count[i], cj = count[j];
2205  sub_prob.l = ci+cj;
2206  sub_prob.x = Malloc(svm_node *,sub_prob.l);
2207  sub_prob.y = Malloc(double,sub_prob.l);
2208  int k;
2209  for(k=0;k<ci;k++)
2210  {
2211  sub_prob.x[k] = x[si+k];
2212  sub_prob.y[k] = +1;
2213  }
2214  for(k=0;k<cj;k++)
2215  {
2216  sub_prob.x[ci+k] = x[sj+k];
2217  sub_prob.y[ci+k] = -1;
2218  }
2219 
2220  if(param->probability)
2221  svm_binary_svc_probability(&sub_prob,param,weighted_C[i],weighted_C[j],probA[p],probB[p]);
2222 
2223  f[p] = svm_train_one(&sub_prob,param,weighted_C[i],weighted_C[j]);
2224  for(k=0;k<ci;k++)
2225  if(!nonzero[si+k] && fabs(f[p].alpha[k]) > 0)
2226  nonzero[si+k] = true;
2227  for(k=0;k<cj;k++)
2228  if(!nonzero[sj+k] && fabs(f[p].alpha[ci+k]) > 0)
2229  nonzero[sj+k] = true;
2230  free(sub_prob.x);
2231  free(sub_prob.y);
2232  ++p;
2233  }
2234 
2235  // build output
2236 
2237  model->nr_class = nr_class;
2238 
2239  model->label = Malloc(int,nr_class);
2240  for(i=0;i<nr_class;i++)
2241  model->label[i] = label[i];
2242 
2243  model->rho = Malloc(double,nr_class*(nr_class-1)/2);
2244  for(i=0;i<nr_class*(nr_class-1)/2;i++)
2245  model->rho[i] = f[i].rho;
2246 
2247  if(param->probability)
2248  {
2249  model->probA = Malloc(double,nr_class*(nr_class-1)/2);
2250  model->probB = Malloc(double,nr_class*(nr_class-1)/2);
2251  for(i=0;i<nr_class*(nr_class-1)/2;i++)
2252  {
2253  model->probA[i] = probA[i];
2254  model->probB[i] = probB[i];
2255  }
2256  }
2257  else
2258  {
2259  model->probA=NULL;
2260  model->probB=NULL;
2261  }
2262 
2263  int total_sv = 0;
2264  int *nz_count = Malloc(int,nr_class);
2265  model->nSV = Malloc(int,nr_class);
2266  for(i=0;i<nr_class;i++)
2267  {
2268  int nSV = 0;
2269  for(int j=0;j<count[i];j++)
2270  if(nonzero[start[i]+j])
2271  {
2272  ++nSV;
2273  ++total_sv;
2274  }
2275  model->nSV[i] = nSV;
2276  nz_count[i] = nSV;
2277  }
2278 
2279  info("Total nSV = %d\n",total_sv);
2280 
2281  model->l = total_sv;
2282  model->SV = Malloc(svm_node *,total_sv);
2283  model->sv_indices = Malloc(int,total_sv);
2284  p = 0;
2285  for(i=0;i<l;i++)
2286  if(nonzero[i])
2287  {
2288  model->SV[p] = x[i];
2289  model->sv_indices[p++] = perm[i] + 1;
2290  }
2291 
2292  int *nz_start = Malloc(int,nr_class);
2293  nz_start[0] = 0;
2294  for(i=1;i<nr_class;i++)
2295  nz_start[i] = nz_start[i-1]+nz_count[i-1];
2296 
2297  model->sv_coef = Malloc(double *,nr_class-1);
2298  for(i=0;i<nr_class-1;i++)
2299  model->sv_coef[i] = Malloc(double,total_sv);
2300 
2301  p = 0;
2302  for(i=0;i<nr_class;i++)
2303  for(int j=i+1;j<nr_class;j++)
2304  {
2305  // classifier (i,j): coefficients with
2306  // i are in sv_coef[j-1][nz_start[i]...],
2307  // j are in sv_coef[i][nz_start[j]...]
2308 
2309  int si = start[i];
2310  int sj = start[j];
2311  int ci = count[i];
2312  int cj = count[j];
2313 
2314  int q = nz_start[i];
2315  int k;
2316  for(k=0;k<ci;k++)
2317  if(nonzero[si+k])
2318  model->sv_coef[j-1][q++] = f[p].alpha[k];
2319  q = nz_start[j];
2320  for(k=0;k<cj;k++)
2321  if(nonzero[sj+k])
2322  model->sv_coef[i][q++] = f[p].alpha[ci+k];
2323  ++p;
2324  }
2325 
2326  free(label);
2327  free(probA);
2328  free(probB);
2329  free(count);
2330  free(perm);
2331  free(start);
2332  free(x);
2333  free(weighted_C);
2334  free(nonzero);
2335  for(i=0;i<nr_class*(nr_class-1)/2;i++)
2336  free(f[i].alpha);
2337  free(f);
2338  free(nz_count);
2339  free(nz_start);
2340  }
2341  return model;
2342 }
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
int * weight_label
Definition: svm.h:47
double * alpha
Definition: svm.cpp:1649
doublereal * x
#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
double * f
#define Malloc(type, n)
Definition: svm.cpp:45
free((char *) ob)
struct svm_node ** x
Definition: svm.h:26
int * label
Definition: svm.h:72
struct svm_parameter param
Definition: svm.h:60
int * sv_indices
Definition: svm.h:68
#define j
double * rho
Definition: svm.h:65
struct _parameter * param
double ** sv_coef
Definition: svm.h:64
int probability
Definition: svm.h:52
int free_sv
Definition: svm.h:76
Definition: svm.h:16
double * y
Definition: svm.h:25
fprintf(glob_prnt.io, "\)
int l
Definition: svm.h:24
double * weight
Definition: svm.h:48
double C
Definition: svm.h:45
int svm_type
Definition: svm.h:36

Variable Documentation

◆ libsvm_version

int libsvm_version = LIBSVM_VERSION

Definition at line 17 of file svm.cpp.