24 model(NULL), norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
31 norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
37 norm_wc(NULL), norm_wcw(NULL), rho(0), m_num_classes(0)
58 SG_ERROR(
"Number of training vectors does not match number of labels\n")
65 for (int32_t i=0; i<num_vectors; i++)
69 int32_t Nmin=num_vectors;
86 result=train_no_bias_libsvm();
94 SG_INFO(
"valid nu interval [%f ... %f]\n", nu_min, nu_max)
97 SG_ERROR(
"nu out of valid range [%f ... %f]\n", nu_min, nu_max)
99 result=train_testrule12();
107 bool CScatterSVM::train_no_bias_libsvm()
109 struct svm_node* x_space;
116 x_space=SG_MALLOC(struct svm_node, 2*
problem.l);
118 for (int32_t i=0; i<
problem.l; i++)
122 x_space[2*i].index=i;
123 x_space[2*i+1].index=-1;
126 int32_t weights_label[2]={-1,+1};
132 param.svm_type=C_SVC;
133 param.kernel_type = LINEAR;
148 param.weight_label = weights_label;
149 param.weight = weights;
153 const char* error_msg = svm_check_parameter(&
problem,&
param);
159 m_kernel->set_normalizer(prev_normalizer);
164 ASSERT((model->l==0) || (model->l>0 && model->SV && model->sv_coef && model->sv_coef))
174 for (int32_t i=0; i<m_num_classes; i++)
176 int32_t num_sv=model->nSV[i];
180 norm_wcw[i]=model->normwcw[i];
183 for (int32_t j=0; j<num_sv; j++)
197 SG_FREE(model->SV[i]);
200 svm_destroy_model(model);
214 bool CScatterSVM::train_testrule12()
216 struct svm_node* x_space;
218 SG_INFO(
"%d trainlabels\n", problem.l)
220 problem.y=SG_MALLOC(float64_t, problem.l);
221 problem.x=SG_MALLOC(struct svm_node*, problem.l);
222 x_space=SG_MALLOC(struct svm_node, 2*problem.l);
224 for (int32_t i=0; i<problem.l; i++)
227 problem.x[i]=&x_space[2*i];
228 x_space[2*i].index=i;
229 x_space[2*i+1].index=-1;
232 int32_t weights_label[2]={-1,+1};
238 param.svm_type=NU_MULTICLASS_SVC;
239 param.kernel_type = LINEAR;
251 param.weight_label = weights_label;
252 param.weight = weights;
256 const char* error_msg = svm_check_parameter(&problem,¶m);
261 model = svm_train(&problem, ¶m);
265 ASSERT((model->l==0) || (model->l>0 && model->SV && model->sv_coef && model->sv_coef))
267 ASSERT(model->nr_class==m_num_classes)
273 norm_wcw = SG_MALLOC(float64_t,
m_machines->get_num_elements());
275 for (int32_t i=0; i<m_num_classes; i++)
277 int32_t num_sv=model->nSV[i];
281 norm_wcw[i]=model->normwcw[i];
284 for (int32_t j=0; j<num_sv; j++)
298 SG_FREE(model->SV[i]);
301 svm_destroy_model(model);
313 void CScatterSVM::compute_norm_wc()
326 for (int32_t i=0; i<num_sv; i++)
329 for (int32_t j=0; j<num_sv; j++)
348 SG_ERROR(
"SVM can not proceed without kernel!\n")
363 for (int32_t i=0; i<num_vectors; i++)
380 outputs[i]=svm->
apply();
384 for (int32_t i=0; i<num_vectors; i++)
440 outputs[j]/=norm_wcw[j];
442 float64_t max_out=outputs[0];
445 if (outputs[j]>max_out)
460 if (outputs[i]>max_out)
virtual float64_t apply_one(int32_t num)
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
virtual bool train_machine(CFeatures *data=NULL)
Real Labels are real-valued labels.
virtual float64_t apply_one(int32_t num)
virtual int32_t get_num_labels() const
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
multi-class labels 0,1,...
virtual bool set_normalizer(CKernelNormalizer *normalizer)
virtual ELabelType get_label_type() const =0
CDynamicObjectArray * m_machines
float64_t kernel(int32_t idx_a, int32_t idx_b)
int32_t get_num_elements() const
virtual int32_t get_num_vec_lhs()
int32_t cache_size
cache_size in MB
bool set_label(int32_t idx, float64_t label)
Multiclass Labels for multi-class classification.
virtual CKernelNormalizer * get_normalizer()
void set_bias(float64_t bias)
CMulticlassStrategy * m_multiclass_strategy
bool set_alpha(int32_t idx, float64_t val)
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)
static void fill_vector(T *vec, int32_t len, T value)
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()
int32_t get_num_classes() const
all of classes and functions are contained in the shogun namespace
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
bool create_multiclass_svm(int32_t num_classes)
A generic Support Vector Machine Interface.
void set_kernel(CKernel *k)
multiclass one vs rest strategy used to train generic multiclass machines for K-class problems with b...
bool set_svm(int32_t num, CSVM *svm)
void display_vector(const char *name="vector", const char *prefix="") const
static float32_t sqrt(float32_t x)
virtual CLabels * classify_one_vs_rest()
virtual bool has_features()
virtual void set_labels(CLabels *lab)
#define SG_UNSTABLE(func,...)
virtual int32_t get_num_vectors() const =0
CSVM * get_svm(int32_t num)
virtual CLabels * apply(CFeatures *data=NULL)