18 using namespace shogun;
22 model(NULL), norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
29 norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
35 norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
54 SG_ERROR(
"Number of training vectors does not match number of labels\n");
58 int32_t* numc=
SG_MALLOC(int32_t, m_num_classes);
61 for (int32_t i=0; i<num_vectors; i++)
65 int32_t Nmin=num_vectors;
82 result=train_no_bias_libsvm();
90 SG_INFO(
"valid nu interval [%f ... %f]\n", nu_min, nu_max);
93 SG_ERROR(
"nu out of valid range [%f ... %f]\n", nu_min, nu_max);
95 result=train_testrule12();
103 bool CScatterSVM::train_no_bias_libsvm()
105 struct svm_node* x_space;
114 for (int32_t i=0; i<
problem.l; i++)
118 x_space[2*i].index=i;
119 x_space[2*i+1].index=-1;
122 int32_t weights_label[2]={-1,+1};
128 param.svm_type=C_SVC;
129 param.kernel_type = LINEAR;
144 param.weight_label = weights_label;
145 param.weight = weights;
149 const char* error_msg = svm_check_parameter(&
problem,&
param);
172 int32_t num_sv=
model->nSV[i];
179 for (int32_t j=0; j<num_sv; j++)
196 svm_destroy_model(
model);
210 bool CScatterSVM::train_testrule12()
212 struct svm_node* x_space;
220 for (int32_t i=0; i<
problem.l; i++)
224 x_space[2*i].index=i;
225 x_space[2*i+1].index=-1;
228 int32_t weights_label[2]={-1,+1};
234 param.svm_type=NU_MULTICLASS_SVC;
235 param.kernel_type = LINEAR;
247 param.weight_label = weights_label;
248 param.weight = weights;
252 const char* error_msg = svm_check_parameter(&
problem,&
param);
273 int32_t num_sv=
model->nSV[i];
280 for (int32_t j=0; j<num_sv; j++)
297 svm_destroy_model(
model);
309 void CScatterSVM::compute_norm_wc()
322 for (int32_t i=0; i<num_sv; i++)
325 for (int32_t j=0; j<num_sv; j++)
344 SG_ERROR(
"SVM can not proceed without kernel!\n");
352 output=
new CLabels(num_vectors);
358 for (int32_t i=0; i<num_vectors; i++)
377 for (int32_t i=0; i<num_vectors; i++)
430 outputs[j] -= v/m_num_svms;
439 if (outputs[j]>max_out)
454 if (outputs[i]>max_out)
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
virtual bool train_machine(CFeatures *data=NULL)
bool set_label(int32_t idx, float64_t label)
The class Labels models labels, i.e. class assignments of objects.
virtual bool set_normalizer(CKernelNormalizer *normalizer)
virtual int32_t get_num_vectors() const =0
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual int32_t get_num_vec_lhs()
bool create_multiclass_svm(int32_t num_classes)
int32_t get_int_label(int32_t idx)
virtual CKernelNormalizer * get_normalizer()
bool set_svm(int32_t num, CSVM *svm)
void set_bias(float64_t bias)
bool set_alpha(int32_t idx, float64_t val)
float64_t get_label(int32_t idx)
static void display_vector(const T *vector, int32_t n, const char *name="vector")
display vector (useful for debugging)
SCATTER_TYPE scatter_type
float64_t get_alpha(int32_t idx)
the scatter kernel normalizer
bool set_support_vector(int32_t idx, int32_t val)
The class Kernel Normalizer defines a function to post-process kernel values.
int32_t get_support_vector(int32_t idx)
virtual int32_t get_num_vec_rhs()
virtual CLabels * apply()
int32_t get_num_classes()
training with bias using test rule 2
The class Features is the base class of all feature objects.
training with bias using test rule 1
static T min(T a, T b)
return the minimum of two integers
static void fill_vector(T *vec, int32_t len, T value)
A generic Support Vector Machine Interface.
virtual CLabels * apply()
void set_kernel(CKernel *k)
static float32_t sqrt(float32_t x)
x^0.5
virtual CLabels * classify_one_vs_rest()
virtual bool has_features()
virtual void set_labels(CLabels *lab)
#define SG_UNSTABLE(func,...)
#define SG_MALLOC(type, len)