24 norm_wc(NULL), norm_wc_len(0), norm_wcw(NULL), norm_wcw_len(0), rho(0), m_num_classes(0)
47 void CScatterSVM::register_params()
67 SG_ERROR(
"Number of training vectors does not match number of labels\n")
74 for (int32_t i=0; i<num_vectors; i++)
78 int32_t Nmin=num_vectors;
95 result=train_no_bias_libsvm();
103 SG_INFO(
"valid nu interval [%f ... %f]\n", nu_min, nu_max)
106 SG_ERROR(
"nu out of valid range [%f ... %f]\n", nu_min, nu_max)
108 result=train_testrule12();
116 bool CScatterSVM::train_no_bias_libsvm()
120 struct svm_model* model =
nullptr;
122 struct svm_node* x_space;
125 SG_INFO(
"%d trainlabels\n", problem.l)
127 problem.y=SG_MALLOC(
float64_t, problem.l);
128 problem.x=SG_MALLOC(
struct svm_node*, problem.l);
129 x_space=SG_MALLOC(
struct svm_node, 2*problem.l);
131 for (int32_t i=0; i<problem.l; i++)
134 problem.x[i]=&x_space[2*i];
135 x_space[2*i].index=i;
136 x_space[2*i+1].index=-1;
139 int32_t weights_label[2]={-1,+1};
145 param.svm_type=C_SVC;
146 param.kernel_type = LINEAR;
161 param.weight_label = weights_label;
162 param.weight = weights;
166 const char* error_msg = svm_check_parameter(&problem,¶m);
171 model = svm_train(&problem, ¶m);
177 ASSERT((model->l==0) || (model->l>0 && model->SV && model->sv_coef && model->sv_coef))
190 int32_t num_sv=model->nSV[i];
197 for (int32_t j=0; j<num_sv; j++)
211 SG_FREE(model->SV[i]);
214 svm_destroy_model(model);
228 bool CScatterSVM::train_testrule12()
232 struct svm_model* model =
nullptr;
234 struct svm_node* x_space;
236 SG_INFO(
"%d trainlabels\n", problem.l)
238 problem.y=SG_MALLOC(
float64_t, problem.l);
239 problem.x=SG_MALLOC(
struct svm_node*, problem.l);
240 x_space=SG_MALLOC(
struct svm_node, 2*problem.l);
242 for (int32_t i=0; i<problem.l; i++)
245 problem.x[i]=&x_space[2*i];
246 x_space[2*i].index=i;
247 x_space[2*i+1].index=-1;
250 int32_t weights_label[2]={-1,+1};
256 param.svm_type=NU_MULTICLASS_SVC;
257 param.kernel_type = LINEAR;
269 param.weight_label = weights_label;
270 param.weight = weights;
274 const char* error_msg = svm_check_parameter(&problem,¶m);
279 model = svm_train(&problem, ¶m);
283 ASSERT((model->l==0) || (model->l>0 && model->SV && model->sv_coef && model->sv_coef))
296 int32_t num_sv=model->nSV[i];
303 for (int32_t j=0; j<num_sv; j++)
317 SG_FREE(model->SV[i]);
320 svm_destroy_model(model);
332 void CScatterSVM::compute_norm_wc()
346 for (int32_t i=0; i<num_sv; i++)
349 for (int32_t j=0; j<num_sv; j++)
368 SG_ERROR(
"SVM can not proceed without kernel!\n")
383 for (int32_t i=0; i<num_vectors; i++)
400 outputs[i]=svm->
apply();
404 for (int32_t i=0; i<num_vectors; i++)
465 if (outputs[j]>max_out)
480 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)
int32_t get_num_classes() const
virtual ELabelType get_label_type() const =0
Real Labels are real-valued labels.
virtual float64_t apply_one(int32_t num)
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)
CDynamicObjectArray * m_machines
virtual int32_t get_num_vectors() const =0
virtual int32_t get_num_labels() const
float64_t kernel(int32_t idx_a, int32_t idx_b)
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)
int32_t get_num_elements() const
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()
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
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)
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,...)
CSVM * get_svm(int32_t num)
void display_vector(const char *name="vector", const char *prefix="") const
virtual CLabels * apply(CFeatures *data=NULL)