112 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
116 SG_INFO(
"created SVMlibsvm object for oneclass\n")
118 else if (strcmp(name,
"LIBSVM_MULTICLASS")==0)
122 SG_INFO(
"created SVMlibsvm object for multiclass\n")
124 else if (strcmp(name,
"LIBSVM_NUMULTICLASS")==0)
128 SG_INFO(
"created SVMlibsvm object for multiclass\n")
131 else if (strcmp(name,
"SCATTERSVM_NO_BIAS_LIBSVM")==0)
135 SG_INFO(
"created ScatterSVM NO BIAS LIBSVM object\n")
137 else if (strcmp(name,
"SCATTERSVM_TESTRULE1")==0)
141 SG_INFO(
"created ScatterSVM TESTRULE1 object\n")
143 else if (strcmp(name,
"SCATTERSVM_TESTRULE2")==0)
147 SG_INFO(
"created ScatterSVM TESTRULE2 object\n")
149 else if (strcmp(name,
"LIBSVM_NU")==0)
153 SG_INFO(
"created SVMlibsvm object\n")
155 else if (strcmp(name,
"LIBSVM")==0)
159 SG_INFO(
"created SVMlibsvm object\n")
161 else if (strcmp(name,
"LARANK")==0)
165 SG_INFO(
"created LaRank object\n")
168 else if (strcmp(name,
"GPBTSVM")==0)
172 SG_INFO(
"created GPBT-SVM object\n")
174 else if (strcmp(name,
"MPDSVM")==0)
178 SG_INFO(
"created MPD-SVM object\n")
180 else if (strcmp(name,
"GNPPSVM")==0)
184 SG_INFO(
"created GNPP-SVM object\n")
186 else if (strcmp(name,
"GMNPSVM")==0)
190 SG_INFO(
"created GMNP-SVM object\n")
192 else if (strcmp(name,
"LIBSVR")==0)
196 SG_INFO(
"created SVRlibsvm object\n")
199 else if (strcmp(name,
"KERNELRIDGEREGRESSION")==0)
203 ui->ui_labels->get_train_labels());
207 else if (strcmp(name,
"PERCEPTRON")==0)
211 SG_INFO(
"created Perceptron object\n")
214 else if (strncmp(name,
"LIBLINEAR",9)==0)
218 if (strcmp(name,
"LIBLINEAR_L2R_LR")==0)
221 SG_INFO(
"created LibLinear l2 regularized logistic regression object\n")
223 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC_DUAL")==0)
226 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM dual object\n")
228 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC")==0)
231 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM primal object\n")
233 else if (strcmp(name,
"LIBLINEAR_L1R_L2LOSS_SVC")==0)
236 SG_INFO(
"created LibLinear l1 regularized l2 loss SVM primal object\n")
238 else if (strcmp(name,
"LIBLINEAR_L2R_L1LOSS_SVC_DUAL")==0)
241 SG_INFO(
"created LibLinear l2 regularized l1 loss dual SVM object\n")
244 SG_ERROR(
"unknown liblinear type\n")
254 else if (strcmp(name,
"LDA")==0)
258 SG_INFO(
"created LDA object\n")
262 else if (strcmp(name,
"LPM")==0)
270 SG_INFO(
"created LPM object\n")
272 else if (strcmp(name,
"LPBOOST")==0)
280 SG_INFO(
"created LPBoost object\n")
283 else if (strncmp(name,
"KNN", strlen(
"KNN"))==0)
287 SG_INFO(
"created KNN object\n")
289 else if (strncmp(name,
"KMEANS", strlen(
"KMEANS"))==0)
293 SG_INFO(
"created KMeans object\n")
295 else if (strncmp(name,
"HIERARCHICAL", strlen(
"HIERARCHICAL"))==0)
299 SG_INFO(
"created Hierarchical clustering object\n")
301 else if (strcmp(name,
"SVMLIN")==0)
308 SG_INFO(
"created SVMLin object\n")
310 else if (strncmp(name,
"WDSVMOCAS", strlen(
"WDSVMOCAS"))==0)
320 SG_INFO(
"created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d)
322 else if (strcmp(name,
"SVMOCAS")==0)
331 SG_INFO(
"created SVM Ocas(OCAS) object\n")
333 else if (strcmp(name,
"SVMSGD")==0)
338 SG_INFO(
"created SVM SGD object\n")
340 else if (strcmp(name,
"SVMBMRM")==0 || (strcmp(name,
"SVMPERF")==0))
349 SG_INFO(
"created SVM Ocas(BMRM/PERF) object\n")
351 else if (strcmp(name,
"MKL_CLASSIFICATION")==0)
356 else if (strcmp(name,
"MKL_ONECLASS")==0)
361 else if (strcmp(name,
"MKL_MULTICLASS")==0)
366 else if (strcmp(name,
"MKL_REGRESSION")==0)
373 SG_ERROR(
"Unknown classifier %s.\n", name)
387 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
389 SG_ERROR(
"No trainlabels available.\n")
391 CKernel* kernel=
ui->ui_kernel->get_kernel();
395 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
397 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
398 SG_ERROR(
"Kernel not initialized / no train features available.\n")
402 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
436 trainlabels=
ui->ui_labels->get_train_labels();
438 SG_INFO(
"Training one class mkl.\n")
439 if (!trainlabels && !oneclass)
440 SG_ERROR(
"No trainlabels available.\n")
442 CKernel* kernel=
ui->ui_kernel->get_kernel();
446 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
447 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
448 SG_ERROR(
"Kernel not initialized.\n")
452 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
491 bool result=mkl->
train();
506 trainlabels=
ui->ui_labels->get_train_labels();
508 SG_INFO(
"Training one class svm.\n")
509 if (!trainlabels && !oneclass)
510 SG_ERROR(
"No trainlabels available.\n")
512 CKernel* kernel=
ui->ui_kernel->get_kernel();
516 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
518 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
519 SG_ERROR(
"Kernel not initialized / no train features available.\n")
523 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
600 if (!
ui->ui_distance->init_distance(
"TRAIN"))
601 SG_ERROR(
"Initializing distance with train features failed.\n")
611 ((
CKMeans*) classifier)->set_max_iter(max_iter);
612 result=((
CKMeans*) classifier)->train();
622 SG_ERROR(
"Unknown clustering type %d\n", type)
630 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
639 if (!
ui->ui_distance->init_distance(
"TRAIN"))
640 SG_ERROR(
"Initializing distance with train features failed.\n")
647 SG_ERROR(
"No distance available.\n")
663 trainlabels=
ui->ui_labels->get_train_labels();
665 SG_ERROR(
"No trainlabels available.\n")
667 CKernel* kernel=
ui->ui_kernel->get_kernel();
671 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
673 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
674 SG_ERROR(
"Kernel not initialized / no train features available.\n")
678 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
685 bool result=krr->
train();
696 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
697 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
701 SG_ERROR(
"No trainfeatures available.\n")
704 SG_ERROR(
"Trainfeatures not based on DotFeatures.\n")
720 SG_ERROR(
"LDA requires train features of class SIMPLE type REAL.\n")
739 SG_ERROR(
"LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n")
751 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
752 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
757 SG_ERROR(
"No trainfeatures available.\n")
761 SG_ERROR(
"Trainfeatures are not of class STRING type BYTE.\n")
779 FILE* model_file=fopen(filename,
"r");
780 REQUIRE(model_file != NULL,
"SVM/Classifier loading failed on file %s.\n", filename);
788 SG_DEBUG(
"file successfully read.\n")
792 SG_ERROR(
"SVM/Classifier creation/loading failed on file %s.\n", filename)
797 SG_ERROR(
"Opening file %s failed.\n", filename)
802 SG_ERROR(
"Type %s of SVM/Classifier unknown.\n", type)
814 FILE* file=fopen(param,
"w");
818 printf(
"writing to file %s failed!\n", param);
821 printf(
"successfully written classifier into \"%s\" !\n", param);
829 SG_ERROR(
"create classifier first\n")
870 SG_INFO(
"Disabling max_train_time.\n")
878 SG_ERROR(
"No regression method allocated\n")
884 SG_ERROR(
"Underlying method not capable of SV-regression\n")
911 if (weight_epsilon<0)
931 if (lambda<0 || lambda>1)
941 SG_ERROR(
"1 <= mkl_block_norm <= inf\n")
1002 SG_INFO(
"Enabling shrinking optimization.\n")
1004 SG_INFO(
"Disabling shrinking optimization.\n")
1013 SG_INFO(
"Enabling batch computation.\n")
1015 SG_INFO(
"Disabling batch computation.\n")
1024 SG_INFO(
"Enabling LINADD optimization.\n")
1026 SG_INFO(
"Disabling LINADD optimization.\n")
1035 SG_INFO(
"Enabling svm bias.\n")
1037 SG_INFO(
"Disabling svm bias.\n")
1046 SG_INFO(
"Enabling mkl interleaved optimization.\n")
1048 SG_INFO(
"Disabling mkl interleaved optimization.\n")
1058 SG_INFO(
"Enabling AUC maximization.\n")
1060 SG_INFO(
"Disabling AUC maximization.\n")
1107 SG_ERROR(
"unknown classifier type\n")
1116 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1117 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1120 SG_ERROR(
"No kernelmachine available.\n")
1124 REQUIRE(
ui->ui_kernel->get_kernel(),
"No kernel set");
1125 if (
ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1127 if (
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_COMBINED
1128 && ( !trainfeatures || !testfeatures ))
1130 SG_DEBUG(
"skipping initialisation of combined kernel "
1131 "as train/test features are unavailable\n")
1136 SG_ERROR(
"No training features available.\n")
1138 SG_ERROR(
"No test features available.\n")
1140 success=
ui->ui_kernel->init_kernel(
"TEST");
1144 if (!success || !
ui->ui_kernel->is_initialized())
1145 SG_ERROR(
"Kernel not initialized.\n")
1161 SG_INFO(
"Starting kernel machine testing.\n")
1167 int32_t& brows, int32_t& bcols,
1192 return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1203 return get_linear(weights, rows, cols, bias, brows, bcols);
1213 SG_ERROR(
"unknown classifier type\n")
1228 int32_t& brows, int32_t& bcols, int32_t idx)
1244 weights=SG_MALLOC(
float64_t, rows*cols);
1246 for (int32_t i=0; i<rows; i++)
1260 int32_t& brows, int32_t& bcols)
1281 centers=SG_MALLOC(
float64_t, rows*cols);
1300 centers=SG_MALLOC(
float64_t, rows*cols);
1301 for (int32_t i=0; i<rows*cols; i++)
1308 SG_ERROR(
"internal error - unknown clustering type\n")
1316 int32_t& brows, int32_t& bcols)
1340 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1341 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1345 SG_ERROR(
"no kernelmachine available\n")
1350 SG_ERROR(
"no training features available\n")
1356 SG_ERROR(
"no test features available\n")
1360 bool success=
ui->ui_distance->init_distance(
"TEST");
1362 if (!success || !
ui->ui_distance->is_initialized())
1364 SG_ERROR(
"distance not initialized\n")
1369 ui->ui_distance->get_distance());
1370 SG_INFO(
"starting distance machine testing\n")
1377 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1381 SG_ERROR(
"no classifier available\n")
1386 SG_ERROR(
"no test features available\n")
1391 SG_ERROR(
"testfeatures not based on DotFeatures\n")
1396 SG_INFO(
"starting linear classifier testing\n")
1402 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1411 SG_ERROR(
"no test features available\n")
1417 SG_ERROR(
"testfeatures not of class STRING type BYTE\n")
1422 SG_INFO(
"starting linear classifier testing\n")
1428 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1429 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1437 if (!
ui->ui_kernel->is_initialized())
1439 SG_ERROR(
"kernel not initialized\n")
1443 if (!
ui->ui_kernel->get_kernel() ||
1444 ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1448 SG_ERROR(
"no training features available\n")
1454 SG_ERROR(
"no test features available\n")
1460 ui->ui_kernel->get_kernel());
1484 if (strncmp(solver,
"NEWTON", 6)==0)
1486 SG_INFO(
"Using NEWTON solver.\n")
1489 else if (strncmp(solver,
"DIRECT", 6)==0)
1491 SG_INFO(
"Using DIRECT solver\n")
1494 else if (strncmp(solver,
"BLOCK_NORM", 9)==0)
1496 SG_INFO(
"Using BLOCK_NORM solver\n")
1499 else if (strncmp(solver,
"ELASTICNET", 10)==0)
1501 SG_INFO(
"Using ELASTICNET solver\n")
1504 else if (strncmp(solver,
"AUTO", 4)==0)
1506 SG_INFO(
"Automagically determining solver.\n")
1510 else if (strncmp(solver,
"CPLEX", 5)==0)
1512 SG_INFO(
"USING CPLEX METHOD selected\n")
1517 else if (strncmp(solver,
"GLPK", 4)==0)
1519 SG_INFO(
"Using GLPK solver\n")
1524 SG_ERROR(
"Unknown solver type, %s (not compiled in?)\n", solver)
1533 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
1537 SG_INFO(
"created SVMlibsvm object for oneclass\n")
1539 else if (strcmp(name,
"LIBSVM_NU")==0)
1543 SG_INFO(
"created SVMlibsvm object\n")
1545 else if (strcmp(name,
"LIBSVM")==0)
1549 SG_INFO(
"created SVMlibsvm object\n")
1552 else if (strcmp(name,
"GPBTSVM")==0)
1556 SG_INFO(
"created GPBT-SVM object\n")
1558 else if (strcmp(name,
"MPDSVM")==0)
1562 SG_INFO(
"created MPD-SVM object\n")
1564 else if (strcmp(name,
"GNPPSVM")==0)
1568 SG_INFO(
"created GNPP-SVM object\n")
1570 else if (strcmp(name,
"LIBSVR")==0)
1574 SG_INFO(
"created SVRlibsvm object\n")
1578 SG_ERROR(
"Unknown SV-classifier %s.\n", name)
void set_epsilon(float64_t eps)
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
void set_shrinking_enabled(bool enable)
bool set_perceptron_parameters(float64_t lernrate, int32_t maxiter)
bool set_svm_epsilon(float64_t epsilon)
int32_t get_num_support_vectors()
void set_bias_enabled(bool enable_bias)
void set_mkl_block_norm(float64_t q)
Class KernelRidgeRegression implements Kernel Ridge Regression - a regularized least square method fo...
bool get_trained_classifier(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols, int32_t idx=-1)
CLabels * classify_linear()
void set_max_train_time(float64_t t)
double norm(double *v, double p, int n)
bool set_svm_shrinking_enabled(bool enabled)
virtual EFeatureType get_feature_type() const =0
bool train_mkl_multiclass()
bool set_svm_linadd_enabled(bool enabled)
bool train_knn(int32_t k=3)
MKLMulticlass is a class for L1-norm Multiclass MKL.
static char * skip_spaces(char *str)
SGVector< float64_t > get_merge_distances()
Class Distance, a base class for all the distances used in the Shogun toolbox.
void set_qpsize(int32_t qps)
bool set_constraint_generator(char *cg)
bool train_clustering(int32_t k=3, int32_t max_iter=1000)
void set_kernel(CKernel *k)
The class Labels models labels, i.e. class assignments of objects.
bool set_svm_mkl_parameters(float64_t weight_epsilon, float64_t C_mkl, float64_t mkl_norm)
virtual int32_t get_num_labels() const =0
void set_shrinking_enabled(bool enable)
float64_t perceptron_learnrate
bool set_do_auc_maximization(bool do_auc)
L2 regularized SVM with L2-loss using newton in the primal.
Class LPM trains a linear classifier called Linear Programming Machine, i.e. a SVM using a norm regu...
bool set_svm_nu(float64_t nu)
int32_t perceptron_maxiter
L1 regularized SVM with L2-loss using dual coordinate descent.
virtual bool load_serializable(CSerializableFile *file, const char *prefix="")
CLabels * setup_auc_maximization(CLabels *labels)
void set_mkl_norm(float64_t norm)
A generic KernelMachine interface.
Multiple Kernel Learning for one-class-classification.
Agglomerative hierarchical single linkage clustering.
Features that support dot products among other operations.
virtual int32_t get_num_vec_lhs()
class LibSVMMultiClass. Does one vs one classification.
Multiple Kernel Learning for regression.
generic kernel multiclass
Class LDA implements regularized Linear Discriminant Analysis.
A generic DistanceMachine interface.
virtual void set_mkl_norm(float64_t norm)
void set_nu(float64_t nue)
bool classify_example(int32_t idx, float64_t &result)
bool set_svm_batch_computation_enabled(bool enabled)
CLabels * classify_distancemachine()
The AUC kernel can be used to maximize the area under the receiver operator characteristic curve (AUC...
static const float64_t epsilon
void set_mkl_epsilon(float64_t eps)
void set_interleaved_optimization_enabled(bool enable)
CLabels * classify_kernelmachine()
bool new_classifier(char *name, int32_t d=6, int32_t from_d=40)
bool set_svr_tube_epsilon(float64_t tube_epsilon)
SGVector< float64_t > get_radiuses()
Class SGObject is the base class of all shogun objects.
void set_constraint_generator(CSVM *s)
void set_batch_computation_enabled(bool enable)
KMeans clustering, partitions the data into k (a-priori specified) clusters.
void set_batch_computation_enabled(bool enable)
bool set_svm_max_qpsize(int32_t max_qpsize)
void set_nu(float64_t nue)
bool set_solver(char *solver)
SGMatrix< int32_t > get_cluster_pairs()
float64_t svm_weight_epsilon
L2 regularized linear logistic regression.
bool set_mkl_block_norm(float64_t mkl_bnorm)
This class provides an interface to the LibLinear library for large- scale linear learning focusing o...
bool set_mkl_interleaved_enabled(bool enabled)
Multiple Kernel Learning for two-class-classification.
void set_qpsize(int32_t qps)
L2 regularized SVM with L2-loss using dual coordinate descent.
void set_tube_epsilon(float64_t eps)
bool set_svm_bufsize(int32_t bufsize)
float64_t get_alpha(int32_t idx)
Class KNN, an implementation of the standard k-nearest neigbor classifier.
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Multiple Kernel Learning.
bool set_svm_bias_enabled(bool enabled)
virtual EMachineType get_classifier_type()
bool get_clustering(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols)
virtual SGVector< float64_t > get_w() const
int32_t get_support_vector(int32_t idx)
bool get_svm(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols, int32_t idx=-1)
Class LPBoost trains a linear classifier called Linear Programming Machine, i.e. a SVM using a norm ...
virtual EFeatureClass get_feature_class() const =0
bool get_linear(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols)
bool train_linear(float64_t gamma=0)
Class LibSVR, performs support vector regression using LibSVM.
Class Perceptron implements the standard linear (online) perceptron.
ScatterSVM - Multiclass SVM.
virtual bool save_serializable(CSerializableFile *file, const char *prefix="")
CSVM * constraint_generator
all of classes and functions are contained in the shogun namespace
bool svm_do_auc_maximization
Class GMNPSVM implements a one vs. rest MultiClass SVM.
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
void set_linadd_enabled(bool enable)
virtual float64_t get_bias()
virtual bool train(CFeatures *data=NULL)
void set_mkl_epsilon(float64_t eps)
A generic Support Vector Machine Interface.
void set_linadd_enabled(bool enable)
void set_elasticnet_lambda(float64_t elasticnet_lambda)
the LaRank multiclass SVM machine
void set_bias_enabled(bool enable_bias)
CLabels * classify_byte_linear()
void set_epsilon(float64_t eps)
Matrix::Scalar max(Matrix m)
L2 regularized linear SVM with L1-loss using dual coordinate descent.
void set_kernel(CKernel *k)
bool has_property(EFeatureProperty p) const
float64_t svm_tube_epsilon
virtual bool has_features()
virtual void set_labels(CLabels *lab)
bool set_krr_tau(float64_t tau=1)
bool set_svm_C(float64_t C1, float64_t C2)
bool load(char *filename, char *type)
void set_solver_type(ESolverType st)
bool set_elasticnet_lambda(float64_t lambda)
bool svm_use_batch_computation
bool set_svm_qpsize(int32_t qpsize)
void set_C_mkl(float64_t C)
void set_C(float64_t c_neg, float64_t c_pos)
bool set_max_train_time(float64_t max)
void set_tube_epsilon(float64_t eps)
SGMatrix< float64_t > get_cluster_centers()
virtual CLabels * apply(CFeatures *data=NULL)