18 :
CSVM(), solver_type(LIBSVM_C_SVC)
40 void CLibSVM::register_params()
49 struct svm_model* model =
nullptr;
51 struct svm_node* x_space;
60 SG_ERROR(
"%s::train_machine(): Number of training vectors (%d) does" 61 " not match number of labels (%d)\n",
get_name(),
68 SG_INFO(
"%d trainlabels\n", problem.l)
74 SG_ERROR(
"Number of training vectors does not match length of linear term\n")
82 problem.pv = SG_MALLOC(
float64_t, problem.l);
84 for (
int i=0; i!=problem.l; i++)
88 problem.y=SG_MALLOC(
float64_t, problem.l);
89 problem.x=SG_MALLOC(
struct svm_node*, problem.l);
90 problem.C=SG_MALLOC(
float64_t, problem.l);
92 x_space=SG_MALLOC(
struct svm_node, 2*problem.l);
94 for (int32_t i=0; i<problem.l; i++)
97 problem.x[i]=&x_space[2*i];
99 x_space[2*i+1].index=-1;
102 int32_t weights_label[2]={-1,+1};
111 param.svm_type=C_SVC;
114 param.svm_type=NU_SVC;
121 param.kernel_type = LINEAR;
134 param.weight_label = weights_label;
135 param.weight = weights;
138 const char* error_msg = svm_check_parameter(&problem, ¶m);
143 model = svm_train(&problem, ¶m);
147 ASSERT(model->nr_class==2)
148 ASSERT((model->l==0) || (model->l>0 && model->SV && model->sv_coef && model->sv_coef[0]))
150 int32_t num_sv=model->l;
159 for (int32_t i=0; i<num_sv; i++)
173 svm_destroy_model(model);
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual ELabelType get_label_type() const =0
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
virtual int32_t get_num_vectors() const =0
float64_t m_max_train_time
virtual int32_t get_num_vec_lhs()
int32_t cache_size
cache_size in MB
LIBSVM_SOLVER_TYPE solver_type
virtual float64_t * get_linear_term_array()
SGVector< float64_t > m_linear_term
void set_bias(float64_t bias)
bool set_alpha(int32_t idx, float64_t val)
void set_objective(float64_t v)
virtual bool train_machine(CFeatures *data=NULL)
bool set_support_vector(int32_t idx, int32_t val)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
A generic Support Vector Machine Interface.
Binary Labels for binary classification.
virtual const char * get_name() const
virtual bool has_features()
bool create_new_model(int32_t num)