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)