16 #include <shogun/lib/external/pr_loqo.h>
48 #if defined(HAVE_CMDLINE)
49 #define USAGE(method) "", ""
50 #define USAGE_I(method, in) "", " " in ""
51 #define USAGE_O(method, out) "" out " = ", ""
52 #define USAGE_IO(method, in, out) "" out " = ", " " in ""
53 #define USAGE_COMMA " "
56 #define USAGE(method) "sg('", "')"
57 #define USAGE_I(method, in) "sg('", "', " in ")"
58 #define USAGE_O(method, out) "[" out "] <- sg('", "')"
59 #define USAGE_IO(method, in, out) "[" out "] <- sg('", "', " in ")"
60 #define USAGE_COMMA ", "
63 #define USAGE(method) "sg('", "')"
64 #define USAGE_I(method, in) "sg('", "', " in ")"
65 #define USAGE_O(method, out) "[" out "]=sg('", "')"
66 #define USAGE_IO(method, in, out) "[" out "]=sg('", "', " in ")"
67 #define USAGE_COMMA ", "
73 {
"Features", NULL, NULL, NULL },
77 (&CSGInterface::cmd_pr_loqo),
79 "'Var1', Var1, 'Var2', Var2",
"results")
81 #endif //USE_GPL_SHOGUN
84 (&CSGInterface::cmd_load_features),
90 (&CSGInterface::cmd_save_features),
95 (&CSGInterface::cmd_clean_features),
100 (&CSGInterface::cmd_get_features),
105 (&CSGInterface::cmd_add_features),
111 (&CSGInterface::cmd_add_multiple_features),
117 (&CSGInterface::cmd_add_dotfeatures),
123 (&CSGInterface::cmd_set_features),
135 (&CSGInterface::cmd_set_reference_features),
140 (&CSGInterface::cmd_del_last_features),
145 (&CSGInterface::cmd_convert),
158 (&CSGInterface::cmd_reshape),
165 (&CSGInterface::cmd_load_labels),
171 (&CSGInterface::cmd_set_labels),
177 (&CSGInterface::cmd_get_labels),
182 {
"Kernel", NULL, NULL },
185 (&CSGInterface::cmd_set_kernel_normalization),
191 (&CSGInterface::cmd_set_kernel),
196 (&CSGInterface::cmd_add_kernel),
201 (&CSGInterface::cmd_del_last_kernel),
206 (&CSGInterface::cmd_init_kernel),
211 (&CSGInterface::cmd_clean_kernel),
216 (&CSGInterface::cmd_save_kernel),
221 (&CSGInterface::cmd_get_kernel_matrix),
226 (&CSGInterface::cmd_set_WD_position_weights),
231 (&CSGInterface::cmd_get_subkernel_weights),
236 (&CSGInterface::cmd_set_subkernel_weights),
241 (&CSGInterface::cmd_set_subkernel_weights_combined),
246 (&CSGInterface::cmd_get_dotfeature_weights_combined),
251 (&CSGInterface::cmd_set_dotfeature_weights_combined),
256 (&CSGInterface::cmd_set_last_subkernel_weights),
261 (&CSGInterface::cmd_get_WD_position_weights),
266 (&CSGInterface::cmd_get_last_subkernel_weights),
271 (&CSGInterface::cmd_compute_by_subkernels),
276 (&CSGInterface::cmd_init_kernel_optimization),
281 (&CSGInterface::cmd_get_kernel_optimization),
286 (&CSGInterface::cmd_delete_kernel_optimization),
291 (&CSGInterface::cmd_use_diagonal_speedup),
296 (&CSGInterface::cmd_set_kernel_optimization_type),
301 (&CSGInterface::cmd_set_solver),
306 (&CSGInterface::cmd_set_constraint_generator),
308 "|SVMLIGHT|LIGHT|SVMLIGHT_ONECLASS|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM"
313 (&CSGInterface::cmd_set_prior_probs),
318 (&CSGInterface::cmd_set_prior_probs_from_labels),
324 (&CSGInterface::cmd_resize_kernel_cache),
327 #endif //USE_SVMLIGHT
330 {
"Distance", NULL, NULL },
333 (&CSGInterface::cmd_set_distance),
338 (&CSGInterface::cmd_init_distance),
343 (&CSGInterface::cmd_get_distance_matrix),
348 {
"Classifier", NULL, NULL },
351 (&CSGInterface::cmd_classify),
356 (&CSGInterface::cmd_classify),
361 (&CSGInterface::cmd_classify_example),
366 (&CSGInterface::cmd_classify_example),
371 (&CSGInterface::cmd_get_classifier),
376 (&CSGInterface::cmd_get_classifier),
381 (&CSGInterface::cmd_new_classifier),
383 "|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM"
384 "|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF"
385 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA"
390 (&CSGInterface::cmd_new_classifier),
392 "|LIBSVM|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM"
393 "|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF"
394 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA"
399 (&CSGInterface::cmd_new_classifier),
404 (&CSGInterface::cmd_new_classifier),
409 (&CSGInterface::cmd_load_classifier),
414 (&CSGInterface::cmd_save_classifier),
419 (&CSGInterface::cmd_get_num_svms),
424 (&CSGInterface::cmd_get_svm),
429 (&CSGInterface::cmd_set_svm),
434 (&CSGInterface::cmd_set_linear_classifier),
439 (&CSGInterface::cmd_get_svm_objective),
444 (&CSGInterface::cmd_compute_svm_primal_objective),
449 (&CSGInterface::cmd_compute_svm_dual_objective),
454 (&CSGInterface::cmd_compute_svm_primal_objective),
459 (&CSGInterface::cmd_compute_mkl_dual_objective),
464 (&CSGInterface::cmd_compute_relative_mkl_duality_gap),
469 (&CSGInterface::cmd_compute_absolute_mkl_duality_gap),
474 (&CSGInterface::cmd_do_auc_maximization),
479 (&CSGInterface::cmd_set_perceptron_parameters),
484 (&CSGInterface::cmd_train_classifier),
489 (&CSGInterface::cmd_train_classifier),
494 (&CSGInterface::cmd_train_classifier),
499 (&CSGInterface::cmd_train_classifier),
504 (&CSGInterface::cmd_set_svm_qpsize),
509 (&CSGInterface::cmd_set_svm_max_qpsize),
514 (&CSGInterface::cmd_set_svm_bufsize),
519 (&CSGInterface::cmd_set_svm_C),
524 (&CSGInterface::cmd_set_svm_epsilon),
529 (&CSGInterface::cmd_set_svr_tube_epsilon),
534 (&CSGInterface::cmd_set_svm_nu),
539 (&CSGInterface::cmd_set_svm_mkl_parameters),
544 (&CSGInterface::cmd_set_elasticnet_lambda),
549 (&CSGInterface::cmd_set_mkl_block_norm),
554 (&CSGInterface::cmd_set_max_train_time),
559 (&CSGInterface::cmd_set_svm_shrinking_enabled),
564 (&CSGInterface::cmd_set_svm_batch_computation_enabled),
569 (&CSGInterface::cmd_set_svm_linadd_enabled),
574 (&CSGInterface::cmd_set_svm_bias_enabled),
579 (&CSGInterface::cmd_set_mkl_interleaved_enabled),
584 (&CSGInterface::cmd_set_krr_tau),
589 {
"Preprocessors", NULL, NULL },
592 (&CSGInterface::cmd_add_preproc),
597 (&CSGInterface::cmd_del_preproc),
602 (&CSGInterface::cmd_attach_preproc),
607 (&CSGInterface::cmd_clean_preproc),
611 {
"Converters", NULL, NULL },
614 (&CSGInterface::cmd_set_converter),
619 (&CSGInterface::cmd_apply_converter),
624 (&CSGInterface::cmd_embed),
629 {
"HMM", NULL, NULL },
632 (&CSGInterface::cmd_new_hmm),
637 (&CSGInterface::cmd_load_hmm),
642 (&CSGInterface::cmd_save_hmm),
647 (&CSGInterface::cmd_get_hmm),
652 (&CSGInterface::cmd_append_hmm),
657 (&CSGInterface::cmd_append_model),
662 (&CSGInterface::cmd_set_hmm),
667 (&CSGInterface::cmd_set_hmm_as),
672 (&CSGInterface::cmd_set_chop),
677 (&CSGInterface::cmd_set_pseudo),
682 (&CSGInterface::cmd_load_definitions),
687 (&CSGInterface::cmd_hmm_classify),
692 (&CSGInterface::cmd_one_class_linear_hmm_classify),
697 (&CSGInterface::cmd_one_class_hmm_classify),
702 (&CSGInterface::cmd_one_class_hmm_classify_example),
707 (&CSGInterface::cmd_hmm_classify_example),
712 (&CSGInterface::cmd_output_hmm),
717 (&CSGInterface::cmd_output_hmm_defined),
722 (&CSGInterface::cmd_hmm_likelihood),
727 (&CSGInterface::cmd_likelihood),
732 (&CSGInterface::cmd_save_likelihood),
737 (&CSGInterface::cmd_get_viterbi_path),
742 (&CSGInterface::cmd_viterbi_train_defined),
747 (&CSGInterface::cmd_viterbi_train),
752 (&CSGInterface::cmd_baum_welch_train),
757 (&CSGInterface::cmd_baum_welch_train_defined),
762 (&CSGInterface::cmd_baum_welch_trans_train),
767 (&CSGInterface::cmd_linear_train),
772 (&CSGInterface::cmd_save_path),
777 (&CSGInterface::cmd_convergence_criteria),
782 (&CSGInterface::cmd_normalize),
787 (&CSGInterface::cmd_add_states),
792 (&CSGInterface::cmd_permutation_entropy),
797 (&CSGInterface::cmd_relative_entropy),
802 (&CSGInterface::cmd_entropy),
807 (&CSGInterface::cmd_set_feature_matrix),
812 (&CSGInterface::cmd_set_feature_matrix_sparse),
817 (&CSGInterface::cmd_new_plugin_estimator),
822 (&CSGInterface::cmd_train_estimator),
827 (&CSGInterface::cmd_plugin_estimate_classify_example),
832 (&CSGInterface::cmd_plugin_estimate_classify),
837 (&CSGInterface::cmd_set_plugin_estimate),
842 (&CSGInterface::cmd_get_plugin_estimate),
845 {
"Signals", NULL, NULL },
848 (&CSGInterface::cmd_signals_set_model),
853 (&CSGInterface::cmd_signals_set_positions),
858 (&CSGInterface::cmd_signals_set_labels),
863 (&CSGInterface::cmd_signals_set_split),
868 (&CSGInterface::cmd_signals_set_train_mask),
873 (&CSGInterface::cmd_signals_add_feature),
878 (&CSGInterface::cmd_signals_add_kernel),
883 (&CSGInterface::cmd_signals_run),
886 {
"Structure", NULL, NULL },
889 (&CSGInterface::cmd_best_path),
894 (&CSGInterface::cmd_best_path_2struct),
906 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
910 (&CSGInterface::cmd_set_plif_struct),
923 (&CSGInterface::cmd_get_plif_struct),
936 (&CSGInterface::cmd_precompute_subkernels),
941 (&CSGInterface::cmd_precompute_content_svms),
948 (&CSGInterface::cmd_get_lin_feat),
953 (&CSGInterface::cmd_set_lin_feat),
958 (&CSGInterface::cmd_init_dyn_prog),
963 (&CSGInterface::cmd_clean_up_dyn_prog),
968 (&CSGInterface::cmd_init_intron_list),
975 (&CSGInterface::cmd_precompute_tiling_features),
982 (&CSGInterface::cmd_long_transition_settings),
990 (&CSGInterface::cmd_set_model),
999 (&CSGInterface::cmd_best_path_trans),
1006 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
1010 (&CSGInterface::cmd_best_path_trans_deriv),
1027 USAGE_COMMA
"q_deriv"
1028 USAGE_COMMA
"cmd_deriv"
1029 USAGE_COMMA
"penalties_deriv"
1030 USAGE_COMMA
"my_scores"
1031 USAGE_COMMA
"my_loss")
1034 {
"POIM", NULL, NULL },
1037 (&CSGInterface::cmd_compute_POIM_WD),
1042 (&CSGInterface::cmd_get_SPEC_consensus),
1047 (&CSGInterface::cmd_get_SPEC_scoring),
1052 (&CSGInterface::cmd_get_WD_consensus),
1057 (&CSGInterface::cmd_get_WD_scoring),
1062 {
"Utility", NULL, NULL },
1065 (&CSGInterface::cmd_crc),
1070 (&CSGInterface::cmd_system),
1075 (&CSGInterface::cmd_exit),
1080 (&CSGInterface::cmd_exit),
1085 (&CSGInterface::cmd_exec),
1090 (&CSGInterface::cmd_set_output),
1095 (&CSGInterface::cmd_set_threshold),
1100 (&CSGInterface::cmd_init_random),
1105 (&CSGInterface::cmd_set_num_threads),
1110 (&CSGInterface::cmd_translate_string),
1112 "string, order, start",
"translation")
1116 (&CSGInterface::cmd_clear),
1121 (&CSGInterface::cmd_tic),
1126 (&CSGInterface::cmd_toc),
1131 (&CSGInterface::cmd_print),
1136 (&CSGInterface::cmd_echo),
1141 (&CSGInterface::cmd_loglevel),
1146 (&CSGInterface::cmd_syntax_highlight),
1151 (&CSGInterface::cmd_progress),
1156 (&CSGInterface::cmd_get_version),
1161 (&CSGInterface::cmd_help),
1166 (&CSGInterface::cmd_whos),
1171 (&CSGInterface::cmd_send_command),
1176 (&CSGInterface::cmd_run_python),
1178 "'Var1', Var1, 'Var2', Var2,..., python_function",
"results")
1182 (&CSGInterface::cmd_run_octave),
1184 "'Var1', Var1, 'Var2', Var2,..., octave_function",
"results")
1188 (&CSGInterface::cmd_run_r),
1190 "'Var1', Var1, 'Var2', Var2,..., r_function",
"results")
1196 CSGInterface::CSGInterface(
bool print_copyright)
1212 if (print_copyright)
1214 version->print_version();
1215 SG_PRINT(
"( seeding random number generator with %u (seed size %d))\n",
1218 SG_PRINT(
"initializing log-table (size=%i*%i*%i=%2.1fMB) ... ) ",
1229 CSGInterface::~CSGInterface()
1231 delete ui_classifier;
1233 delete ui_pluginestimate;
1239 delete ui_structure;
1243 delete ui_converter;
1249 void CSGInterface::reset()
1255 m_legacy_strptr=NULL;
1260 void CSGInterface::translate_arg(CSGInterface* source, CSGInterface* target)
1262 switch (source->get_argument_type())
1265 target->set_int(source->get_int());
1268 target->set_real(source->get_real());
1271 target->set_bool(source->get_bool());
1277 source->get_vector(v, len);
1278 target->set_vector(v, len);
1286 source->get_vector(v, len);
1287 target->set_vector(v, len);
1295 source->get_vector(v, len);
1296 target->set_vector(v, len);
1304 source->get_vector(v, len);
1305 target->set_vector(v, len);
1313 source->get_vector(v, len);
1314 target->set_vector(v, len);
1318 case VECTOR_SHORTREAL:
1322 source->get_vector(v, len);
1323 target->set_vector(v, len);
1331 source->get_vector(v, len);
1332 target->set_vector(v, len);
1340 source->get_vector(v, len);
1341 target->set_vector(v, len);
1349 int32_t max_str_len=0;
1351 source->get_string_list(strs, num_str, max_str_len);
1352 target->set_string_list(strs, num_str);
1359 int32_t max_str_len=0;
1361 source->get_string_list(strs, num_str,max_str_len);
1362 target->set_string_list(strs, num_str);
1369 int32_t max_str_len=0;
1371 source->get_string_list(strs, num_str,max_str_len);
1372 target->set_string_list(strs, num_str);
1379 int32_t max_str_len=0;
1381 source->get_string_list(strs, num_str, max_str_len);
1382 target->set_string_list(strs, num_str);
1389 int32_t max_str_len=0;
1391 source->get_string_list(strs, num_str, max_str_len);
1392 target->set_string_list(strs, num_str);
1400 int32_t* fmatrix=NULL;
1401 source->get_matrix(fmatrix, num_feat, num_vec);
1402 target->set_matrix(fmatrix, num_feat, num_vec);
1411 source->get_matrix(fmatrix, num_feat, num_vec);
1412 target->set_matrix(fmatrix, num_feat, num_vec);
1420 int16_t* fmatrix=NULL;
1421 source->get_matrix(fmatrix, num_feat, num_vec);
1422 target->set_matrix(fmatrix, num_feat, num_vec);
1426 case DENSE_SHORTREAL:
1431 source->get_matrix(fmatrix, num_feat, num_vec);
1432 target->set_matrix(fmatrix, num_feat, num_vec);
1440 uint16_t* fmatrix=NULL;
1441 source->get_matrix(fmatrix, num_feat, num_vec);
1442 target->set_matrix(fmatrix, num_feat, num_vec);
1529 source->get_sparse_matrix(fmatrix, num_feat, num_vec);
1531 for (int32_t i=0; i<num_vec; i++)
1532 nnz+=fmatrix[i].num_feat_entries;
1533 target->set_sparse_matrix(fmatrix, num_feat, num_vec, nnz);
1550 bool CSGInterface::cmd_load_features()
1552 if (m_nrhs<8 || !create_return_values(0))
1556 char* filename=get_str_from_str_or_direct(len);
1557 char* fclass=get_str_from_str_or_direct(len);
1558 char* type=get_str_from_str_or_direct(len);
1559 char* target=get_str_from_str_or_direct(len);
1560 int32_t size=get_int_from_int_or_str();
1561 int32_t comp_features=get_int_from_int_or_str();
1563 bool success=ui_features->load(
1564 filename, fclass, type, target, size, comp_features);
1573 bool CSGInterface::cmd_save_features()
1575 if (m_nrhs<5 || !create_return_values(0))
1579 char* filename=get_str_from_str_or_direct(len);
1580 char* type=get_str_from_str_or_direct(len);
1581 char* target=get_str_from_str_or_direct(len);
1583 bool success=ui_features->save(filename, type, target);
1591 bool CSGInterface::cmd_clean_features()
1593 if (m_nrhs<2 || !create_return_values(0))
1597 char* target=get_str_from_str_or_direct(len);
1599 bool success=ui_features->clean(target);
1605 bool CSGInterface::cmd_get_features()
1607 if (m_nrhs!=2 || !create_return_values(1))
1611 char* target=get_string(tlen);
1614 if (strmatch(target,
"TRAIN"))
1615 feat=ui_features->get_train_features();
1616 else if (strmatch(target,
"TEST"))
1617 feat=ui_features->get_test_features();
1621 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
1639 set_matrix(fmatrix, num_feat, num_vec);
1646 set_matrix(fmatrix, num_feat, num_vec);
1653 set_matrix(fmatrix, num_feat, num_vec);
1660 set_matrix(fmatrix, num_feat, num_vec);
1667 set_matrix(fmatrix, num_feat, num_vec);
1674 set_matrix(fmatrix, num_feat, num_vec);
1681 set_matrix(fmatrix, num_feat, num_vec);
1698 get_num_nonzero_entries();
1715 int32_t max_str_len=0;
1721 set_string_list(fmatrix, num_str);
1728 set_string_list(fmatrix, num_str);
1735 set_string_list(fmatrix, num_str);
1764 bool CSGInterface::cmd_add_features()
1766 if (m_nrhs<3 || !create_return_values(0))
1769 return do_set_features(
true,
false);
1772 bool CSGInterface::cmd_add_multiple_features()
1774 if ((m_nrhs!=4 && m_nrhs<5) || !create_return_values(0))
1777 int32_t repetitions=get_int();
1781 return do_set_features(
true,
false, repetitions);
1784 bool CSGInterface::cmd_add_dotfeatures()
1786 if (m_nrhs<3 || !create_return_values(0))
1789 return do_set_features(
true,
true);
1792 bool CSGInterface::cmd_set_features()
1794 if (m_nrhs<3 || !create_return_values(0))
1797 return do_set_features(
false,
false);
1800 bool CSGInterface::do_set_features(
bool add,
bool check_dot, int32_t repetitions)
1803 char* target=get_string(tlen);
1804 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
1807 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
1814 switch (get_argument_type())
1819 get_sparse_matrix(fmatrix, num_feat, num_vec);
1828 get_matrix(fmatrix, num_feat, num_vec);
1842 int32_t* fmatrix=NULL;
1843 get_matrix(fmatrix, num_feat, num_vec);
1853 int16_t* fmatrix=NULL;
1854 get_matrix(fmatrix, num_feat, num_vec);
1864 uint16_t* fmatrix=NULL;
1865 get_matrix(fmatrix, num_feat, num_vec);
1873 case DENSE_SHORTREAL:
1876 get_matrix(fmatrix, num_feat, num_vec);
1887 SG_ERROR(
"Please specify alphabet!\n")
1890 int32_t max_str_len=0;
1892 get_string_list(fmatrix, num_str, max_str_len);
1894 int32_t alphabet_len=0;
1895 char* alphabet_str=get_string(alphabet_len);
1898 if (strmatch(alphabet_str,
"DNABINFILE"))
1900 SG_FREE(alphabet_str);
1902 ASSERT(fmatrix[0].
string)
1912 SG_ERROR(
"Couldn't load DNA features from file.\n")
1919 bool convert_to_word=
false;
1920 bool convert_to_ulong=
false;
1922 if (strmatch(alphabet_str,
"DNAWORD"))
1925 convert_to_word=
true;
1927 else if (strmatch(alphabet_str,
"DNAULONG"))
1930 convert_to_ulong=
true;
1933 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1936 SG_FREE(alphabet_str);
1944 SG_ERROR(
"Couldnt set byte string features.\n")
1949 if (convert_to_word || convert_to_ulong)
1950 convert_to_bitembedding(feat, convert_to_word, convert_to_ulong);
1953 obtain_from_single_string(feat);
1960 SG_ERROR(
"Please specify alphabet!\n")
1963 int32_t max_str_len=0;
1965 get_string_list(fmatrix, num_str, max_str_len);
1967 int32_t alphabet_len=0;
1968 char* alphabet_str=get_string(alphabet_len);
1971 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1972 SG_FREE(alphabet_str);
1979 SG_ERROR(
"Couldnt set byte string features.\n")
1986 SG_ERROR(
"Wrong argument type %d.\n", get_argument_type())
1992 SG_ERROR(
"Feature type not supported by DOT Features\n")
1995 if (strmatch(target,
"TRAIN"))
1998 ui_features->set_train_features(feat);
2001 for (int32_t i=0; i<repetitions; i++)
2002 ui_features->add_train_dotfeatures((
CDotFeatures*) feat);
2006 for (int32_t i=0; i<repetitions; i++)
2007 ui_features->add_train_features(feat);
2013 ui_features->set_test_features(feat);
2016 for (int32_t i=0; i<repetitions; i++)
2017 ui_features->add_test_dotfeatures((
CDotFeatures*) feat);
2021 for (int32_t i=0; i<repetitions; i++)
2022 ui_features->add_test_features(feat);
2031 bool CSGInterface::cmd_set_reference_features()
2033 if (m_nrhs<3 || !create_return_values(0))
2037 char* target=get_str_from_str_or_direct(len);
2039 bool success=ui_features->set_reference_features(target);
2045 bool CSGInterface::cmd_del_last_features()
2047 if (m_nrhs<2 || !create_return_values(0))
2051 char* target=get_str_from_str_or_direct(len);
2052 bool success=ui_features->del_last_feature_obj(target);
2058 bool CSGInterface::cmd_convert()
2060 if (m_nrhs<5 || !create_return_values(0))
2064 char* target=get_str_from_str_or_direct(len);
2065 CFeatures* features=ui_features->get_convert_features(target);
2069 SG_ERROR(
"No \"%s\" features available.\n", target)
2072 char* from_class=get_str_from_str_or_direct(len);
2073 char* from_type=get_str_from_str_or_direct(len);
2074 char* to_class=get_str_from_str_or_direct(len);
2075 char* to_type=get_str_from_str_or_direct(len);
2078 if (strmatch(from_class,
"SIMPLE"))
2080 if (strmatch(from_type,
"REAL"))
2082 if (strmatch(to_class,
"SPARSE") &&
2083 strmatch(to_type,
"REAL"))
2085 result=ui_features->convert_simple_real_to_sparse_real(
2092 else if (strmatch(from_type,
"CHAR"))
2094 if (strmatch(to_class,
"STRING") &&
2095 strmatch(to_type,
"CHAR"))
2097 result=ui_features->convert_simple_char_to_string_char(
2100 else if (strmatch(to_class,
"SIMPLE"))
2102 if (strmatch(to_type,
"ALIGN") && m_nrhs==8)
2104 float64_t gap_cost=get_real_from_real_or_str();
2105 result=ui_features->convert_simple_char_to_simple_align(
2115 else if (strmatch(from_type,
"WORD"))
2117 if (strmatch(to_class,
"SIMPLE") &&
2118 strmatch(to_type,
"SALZBERG"))
2120 result=ui_features->convert_simple_word_to_simple_salzberg(
2131 else if (strmatch(from_class,
"SPARSE"))
2133 if (strmatch(from_type,
"REAL"))
2135 if (strmatch(to_class,
"SIMPLE") &&
2136 strmatch(to_type,
"REAL"))
2138 result=ui_features->convert_sparse_real_to_simple_real(
2148 else if (strmatch(from_class,
"STRING"))
2150 if (strmatch(from_type,
"CHAR"))
2152 if (strmatch(to_class,
"STRING"))
2161 order=get_int_from_int_or_str();
2165 start=get_int_from_int_or_str();
2169 gap=get_int_from_int_or_str();
2173 char* rev_str=get_str_from_str_or_direct(len);
2183 if (strmatch(to_type,
"BYTE"))
2185 result=ui_features->convert_string_char_to_string_generic<char,uint8_t>(
2189 else if (strmatch(to_type,
"WORD"))
2191 result=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2195 else if (strmatch(to_type,
"ULONG"))
2197 result=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2208 else if (strmatch(from_type,
"BYTE"))
2210 if (strmatch(to_class,
"STRING"))
2219 order=get_int_from_int_or_str();
2223 start=get_int_from_int_or_str();
2227 gap=get_int_from_int_or_str();
2231 char* rev_str=get_str_from_str_or_direct(len);
2241 if (strmatch(to_type,
"WORD"))
2243 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint16_t>(
2247 else if (strmatch(to_type,
"ULONG"))
2249 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint64_t>(
2260 else if (strmatch(from_type,
"WORD"))
2262 if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"TOP"))
2264 result=ui_features->convert_string_word_to_simple_top(
2267 else if (strmatch(to_class,
"SPEC") && strmatch(to_type,
"WORD") && m_nrhs==7)
2269 bool use_norm=get_bool();
2277 else if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"FK"))
2279 result=ui_features->convert_string_word_to_simple_fk(
2288 if (result && ui_features->set_convert_features(result, target))
2289 SG_INFO(
"Conversion was successful.\n")
2294 SG_FREE(from_class);
2298 return (result!=NULL);
2301 void CSGInterface::convert_to_bitembedding(
CFeatures* &features,
bool convert_to_word,
bool convert_to_ulong)
2315 if (convert_to_word)
2317 SG_INFO(
"Converting into word-bitembedding\n")
2318 features=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2322 if (convert_to_ulong)
2324 SG_INFO(
"Converting into ulong-bitembedding\n")
2325 features=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2330 void CSGInterface::obtain_from_single_string(
CFeatures* features)
2336 char* str=get_string(len);
2339 if (strmatch(str,
"from_position_list"))
2341 obtain_from_position_list(features);
2343 else if (strmatch(str,
"slide_window"))
2345 obtain_by_sliding_window(features);
2351 bool CSGInterface::obtain_from_position_list(
CFeatures* features)
2353 int32_t winsize=get_int();
2355 int32_t* shifts=NULL;
2356 int32_t num_shift=0;
2357 get_vector(shifts, num_shift);
2363 SG_DEBUG(
"winsize: %d num_shifts: %d skip: %d\n", winsize, num_shift, skip)
2367 for (int32_t i=0; i<num_shift; i++)
2379 obtain_by_position_list(winsize, &positions, skip)>0);
2385 obtain_by_position_list(winsize, &positions, skip)>0);
2391 obtain_by_position_list(winsize, &positions, skip)>0);
2397 obtain_by_position_list(winsize, &positions, skip)>0);
2401 SG_ERROR(
"Unsupported string features type.\n")
2407 bool CSGInterface::obtain_by_sliding_window(
CFeatures* features)
2409 int32_t winsize=get_int();
2410 int32_t shift=get_int();
2432 SG_SERROR(
"Unsupported string features type.\n")
2439 bool CSGInterface::cmd_reshape()
2441 if (m_nrhs<4 || !create_return_values(0))
2445 char* target=get_str_from_str_or_direct(len);
2446 int32_t num_feat=get_int_from_int_or_str();
2447 int32_t num_vec=get_int_from_int_or_str();
2449 bool success=ui_features->reshape(target, num_feat, num_vec);
2455 bool CSGInterface::cmd_load_labels()
2457 if (m_nrhs<4 || !create_return_values(0))
2461 char* filename=get_str_from_str_or_direct(len);
2462 char* target=get_str_from_str_or_direct(len);
2464 bool success=ui_labels->load(filename, target);
2471 bool CSGInterface::cmd_set_labels()
2473 if (m_nrhs!=3 || !create_return_values(0))
2477 char* target=get_string(tlen);
2478 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
2481 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2486 get_vector(lab, len);
2488 CLabels* labels=ui_labels->infer_labels(lab, len);
2492 if (strmatch(target,
"TRAIN"))
2493 ui_labels->set_train_labels(labels);
2494 else if (strmatch(target,
"TEST"))
2495 ui_labels->set_test_labels(labels);
2499 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2506 bool CSGInterface::cmd_get_labels()
2508 if (m_nrhs!=2 || !create_return_values(1))
2512 char* target=get_string(tlen);
2515 if (strmatch(target,
"TRAIN"))
2516 labels=ui_labels->get_train_labels();
2517 else if (strmatch(target,
"TEST"))
2518 labels=ui_labels->get_test_labels();
2522 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2539 bool CSGInterface::cmd_set_kernel_normalization()
2541 if (m_nrhs<2 || !create_return_values(0))
2545 char* normalization=get_string(len);
2555 bool success=ui_kernel->set_normalization(normalization, c, r);
2557 SG_FREE(normalization);
2561 bool CSGInterface::cmd_set_kernel()
2563 if (m_nrhs<2 || !create_return_values(0))
2566 SG_DEBUG(
"SGInterface: set_kernel\n")
2567 CKernel* kernel=create_kernel();
2568 return ui_kernel->set_kernel(kernel);
2571 bool CSGInterface::cmd_add_kernel()
2573 if (m_nrhs<3 || !create_return_values(0))
2576 float64_t weight=get_real_from_real_or_str();
2579 CKernel* kernel=create_kernel();
2581 SG_DEBUG(
"SGInterface: add_kernel\n")
2582 return ui_kernel->add_kernel(kernel, weight);
2585 bool CSGInterface::cmd_del_last_kernel()
2587 if (m_nrhs<1 || !create_return_values(0))
2590 return ui_kernel->del_last_kernel();
2593 CKernel* CSGInterface::create_kernel()
2597 char* type=get_str_from_str_or_direct(len);
2599 SG_DEBUG(
"set_kernel with type: %s\n", type)
2601 if (strmatch(type,
"COMBINED"))
2606 int32_t size=get_int_from_int_or_str();
2607 bool append_subkernel_weights=
false;
2609 append_subkernel_weights=get_bool_from_bool_or_str();
2611 kernel=ui_kernel->create_combined(size, append_subkernel_weights);
2613 else if (strmatch(type,
"DISTANCE"))
2618 int32_t size=get_int_from_int_or_str();
2621 width=get_real_from_real_or_str();
2623 kernel=ui_kernel->create_distance(size, width);
2625 else if (strmatch(type,
"WAVELET"))
2631 char* dtype=get_str_from_str_or_direct(len);
2632 if (strmatch(dtype,
"REAL"))
2634 int32_t size=get_int_from_int_or_str();
2640 Wdilation=get_real_from_real_or_str();
2643 Wtranslation=get_real_from_real_or_str();
2646 kernel=ui_kernel->create_sigmoid(size, Wdilation, Wtranslation);
2651 else if (strmatch(type,
"LINEAR"))
2658 char* dtype=get_str_from_str_or_direct(len);
2659 int32_t size=get_int_from_int_or_str();
2662 scale=get_real_from_real_or_str();
2664 if (strmatch(dtype,
"BYTE"))
2665 kernel=ui_kernel->create_linearbyte(size, scale);
2666 else if (strmatch(dtype,
"WORD"))
2667 kernel=ui_kernel->create_linearword(size, scale);
2668 else if (strmatch(dtype,
"CHAR"))
2669 kernel=ui_kernel->create_linearstring(size, scale);
2670 else if (strmatch(dtype,
"REAL"))
2671 kernel=ui_kernel->create_linear(size, scale);
2672 else if (strmatch(dtype,
"SPARSEREAL"))
2673 kernel=ui_kernel->create_sparselinear(size, scale);
2677 else if (strmatch(type,
"HISTOGRAM"))
2682 char* dtype=get_str_from_str_or_direct(len);
2683 if (strmatch(dtype,
"WORD"))
2685 int32_t size=get_int_from_int_or_str();
2686 kernel=ui_kernel->create_histogramword(size);
2691 else if (strmatch(type,
"SALZBERG"))
2696 char* dtype=get_str_from_str_or_direct(len);
2697 if (strmatch(dtype,
"WORD"))
2699 int32_t size=get_int_from_int_or_str();
2700 kernel=ui_kernel->create_salzbergword(size);
2705 else if (strmatch(type,
"POLYMATCH"))
2710 char* dtype=get_str_from_str_or_direct(len);
2711 int32_t size=get_int_from_int_or_str();
2713 bool inhomogene=
false;
2714 bool normalize=
true;
2718 degree=get_int_from_int_or_str();
2721 inhomogene=get_bool_from_bool_or_str();
2723 normalize=get_bool_from_bool_or_str();
2727 if (strmatch(dtype,
"CHAR"))
2729 kernel=ui_kernel->create_polymatchstring(
2730 size, degree, inhomogene, normalize);
2732 else if (strmatch(dtype,
"WORD"))
2734 kernel=ui_kernel->create_polymatchwordstring(
2735 size, degree, inhomogene, normalize);
2740 else if (strmatch(type,
"MATCH"))
2745 char* dtype=get_str_from_str_or_direct(len);
2746 if (strmatch(dtype,
"WORD"))
2748 int32_t size=get_int_from_int_or_str();
2750 bool normalize=
true;
2753 d=get_int_from_int_or_str();
2755 normalize=get_bool_from_bool_or_str();
2757 kernel=ui_kernel->create_matchwordstring(size, d, normalize);
2762 else if (strmatch(type,
"WEIGHTEDCOMMSTRING") || strmatch(type,
"COMMSTRING"))
2764 char* dtype=get_str_from_str_or_direct(len);
2765 int32_t size=get_int_from_int_or_str();
2766 bool use_sign=
false;
2767 char* norm_str=NULL;
2771 use_sign=get_bool_from_bool_or_str();
2774 norm_str=get_str_from_str_or_direct(len);
2777 if (strmatch(dtype,
"WORD"))
2779 if (strmatch(type,
"WEIGHTEDCOMMSTRING"))
2781 kernel=ui_kernel->create_commstring(
2784 else if (strmatch(type,
"COMMSTRING"))
2786 kernel=ui_kernel->create_commstring(
2790 else if (strmatch(dtype,
"ULONG"))
2792 kernel=ui_kernel->create_commstring(
2799 else if (strmatch(type,
"CHI2"))
2804 char* dtype=get_str_from_str_or_direct(len);
2805 if (strmatch(dtype,
"REAL"))
2807 int32_t size=get_int_from_int_or_str();
2811 width=get_real_from_real_or_str();
2813 kernel=ui_kernel->create_chi2(size, width);
2818 else if (strmatch(type,
"FIXEDDEGREE"))
2823 char* dtype=get_str_from_str_or_direct(len);
2824 if (strmatch(dtype,
"CHAR"))
2826 int32_t size=get_int_from_int_or_str();
2829 d=get_int_from_int_or_str();
2831 kernel=ui_kernel->create_fixeddegreestring(size, d);
2836 else if (strmatch(type,
"LOCALALIGNMENT"))
2841 char* dtype=get_str_from_str_or_direct(len);
2842 if (strmatch(dtype,
"CHAR"))
2844 int32_t size=get_int_from_int_or_str();
2846 kernel=ui_kernel->create_localalignmentstring(size);
2851 else if (strmatch(type,
"OLIGO"))
2856 char* dtype=get_str_from_str_or_direct(len);
2857 if (strmatch(dtype,
"CHAR"))
2859 int32_t size=get_int_from_int_or_str();
2860 int32_t k=get_int_from_int_or_str();
2861 float64_t w=get_real_from_real_or_str();
2863 kernel=ui_kernel->create_oligo(size, k, w);
2868 else if (strmatch(type,
"WEIGHTEDDEGREEPOS2") ||
2869 strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2874 char* dtype=get_str_from_str_or_direct(len);
2875 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2877 int32_t size=get_int_from_int_or_str();
2878 int32_t order=get_int_from_int_or_str();
2879 int32_t max_mismatch=get_int_from_int_or_str();
2880 int32_t length=get_int_from_int_or_str();
2881 int32_t* shifts=NULL;
2883 get_vector_from_int_vector_or_str(shifts, l);
2887 bool use_normalization=
true;
2888 if (strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2889 use_normalization=
false;
2891 kernel=ui_kernel->create_weighteddegreepositionstring2(
2892 size, order, max_mismatch, shifts, length,
2900 else if (strmatch(type,
"WEIGHTEDDEGREEPOS3"))
2905 char* dtype=get_str_from_str_or_direct(len);
2906 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2908 int32_t size=get_int_from_int_or_str();
2909 int32_t order=get_int_from_int_or_str();
2910 int32_t max_mismatch=get_int_from_int_or_str();
2911 int32_t length=get_int_from_int_or_str();
2912 int32_t mkl_stepsize=get_int_from_int_or_str();
2913 int32_t* shifts=NULL;
2915 get_vector_from_int_vector_or_str(shifts, l);
2919 if (m_nrhs>9+length)
2921 get_vector_from_real_vector_or_str(
2922 position_weights, length);
2925 kernel=ui_kernel->create_weighteddegreepositionstring3(
2926 size, order, max_mismatch, shifts, length,
2927 mkl_stepsize, position_weights);
2929 SG_FREE(position_weights);
2935 else if (strmatch(type,
"WEIGHTEDDEGREEPOS"))
2940 char* dtype=get_str_from_str_or_direct(len);
2941 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2943 int32_t size=get_int_from_int_or_str();
2945 int32_t max_mismatch=0;
2952 order=get_int_from_int_or_str();
2956 max_mismatch=get_int_from_int_or_str();
2960 length=get_int_from_int_or_str();
2964 center=get_int_from_int_or_str();
2967 step=get_real_from_real_or_str();
2973 kernel=ui_kernel->create_weighteddegreepositionstring(
2974 size, order, max_mismatch, length, center, step);
2979 else if (strmatch(type,
"WEIGHTEDDEGREE"))
2984 char* dtype=get_str_from_str_or_direct(len);
2985 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2987 int32_t size=get_int_from_int_or_str();
2989 int32_t max_mismatch=0;
2990 bool use_normalization=
true;
2991 int32_t mkl_stepsize=1;
2992 bool block_computation=
true;
2993 int32_t single_degree=-1;
2997 order=get_int_from_int_or_str();
3001 max_mismatch=get_int_from_int_or_str();
3005 use_normalization=get_bool_from_bool_or_str();
3009 mkl_stepsize=get_int_from_int_or_str();
3013 block_computation=get_int_from_int_or_str();
3016 single_degree=get_int_from_int_or_str();
3023 kernel=ui_kernel->create_weighteddegreestring(
3024 size, order, max_mismatch, use_normalization,
3025 mkl_stepsize, block_computation, single_degree);
3030 else if (strmatch(type,
"WEIGHTEDDEGREERBF"))
3035 char* dtype=get_str_from_str_or_direct(len);
3036 int32_t size=get_int_from_int_or_str();
3037 int32_t nof_properties=get_int_from_int_or_str();
3042 degree=get_int_from_int_or_str();
3045 width=get_real_from_real_or_str();
3051 kernel=ui_kernel->create_weighteddegreerbf(size, degree, nof_properties, width);
3056 else if (strmatch(type,
"SPECTRUMMISMATCHRBF"))
3061 char* dtype=get_str_from_str_or_direct(len);
3062 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
3064 int32_t size=get_int_from_int_or_str();
3065 int32_t degree=get_int_from_int_or_str();
3066 int32_t max_mismatch=get_int_from_int_or_str();
3067 float64_t width=get_real_from_real_or_str();
3075 get_matrix(helper_matrix, N, M);
3077 if (N == 128 && M == 128)
3080 memcpy(AA_matrix, helper_matrix, N*M*
sizeof(
float64_t)) ;
3081 kernel=ui_kernel->create_spectrummismatchrbf(size, AA_matrix, 128, 128, max_mismatch, degree, width);
3085 SG_ERROR(
"Matrix size %d %d\n", N, M)
3092 else if (strmatch(type,
"SLIK") || strmatch(type,
"LIK"))
3097 char* dtype=get_str_from_str_or_direct(len);
3098 if (strmatch(dtype,
"CHAR"))
3100 int32_t size=get_int_from_int_or_str();
3102 int32_t inner_degree=3;
3103 int32_t outer_degree=1;
3107 length=get_int_from_int_or_str();
3111 inner_degree=get_int_from_int_or_str();
3114 outer_degree=get_int_from_int_or_str();
3118 if (strmatch(type,
"SLIK"))
3120 kernel=ui_kernel->create_localityimprovedstring(
3121 size, length, inner_degree, outer_degree,
3126 kernel=ui_kernel->create_localityimprovedstring(
3127 size, length, inner_degree, outer_degree,
3134 else if (strmatch(type,
"POLY"))
3139 char* dtype=get_str_from_str_or_direct(len);
3140 int32_t size=get_int_from_int_or_str();
3142 bool inhomogene=
false;
3143 bool normalize=
true;
3147 degree=get_int_from_int_or_str();
3151 inhomogene=get_bool_from_bool_or_str();
3154 normalize=get_bool_from_bool_or_str();
3158 if (strmatch(dtype,
"REAL"))
3160 kernel=ui_kernel->create_poly(
3161 size, degree, inhomogene, normalize);
3163 else if (strmatch(dtype,
"SPARSEREAL"))
3165 kernel=ui_kernel->create_sparsepoly(
3166 size, degree, inhomogene, normalize);
3171 else if (strmatch(type,
"SIGMOID"))
3176 char* dtype=get_str_from_str_or_direct(len);
3177 if (strmatch(dtype,
"REAL"))
3179 int32_t size=get_int_from_int_or_str();
3185 gamma=get_real_from_real_or_str();
3188 coef0=get_real_from_real_or_str();
3191 kernel=ui_kernel->create_sigmoid(size, gamma, coef0);
3196 else if (strmatch(type,
"GAUSSIAN"))
3201 char* dtype=get_str_from_str_or_direct(len);
3202 int32_t size=get_int_from_int_or_str();
3205 width=get_real_from_real_or_str();
3207 if (strmatch(dtype,
"REAL"))
3208 kernel=ui_kernel->create_gaussian(size, width);
3209 else if (strmatch(dtype,
"SPARSEREAL"))
3210 kernel=ui_kernel->create_sparsegaussian(size, width);
3214 else if (strmatch(type,
"GAUSSIANSHIFT"))
3219 char* dtype=get_str_from_str_or_direct(len);
3220 if (strmatch(dtype,
"REAL"))
3222 int32_t size=get_int_from_int_or_str();
3223 float64_t width=get_real_from_real_or_str();
3224 int32_t max_shift=get_int_from_int_or_str();
3225 int32_t shift_step=get_int_from_int_or_str();
3227 kernel=ui_kernel->create_gaussianshift(
3228 size, width, max_shift, shift_step);
3233 else if (strmatch(type,
"CUSTOM"))
3235 if (m_nrhs!=4 || !create_return_values(0))
3241 get_matrix(kmatrix, num_feat, num_vec);
3244 char* ktype=get_string(tlen);
3246 if (!strmatch(ktype,
"DIAG") &&
3247 !strmatch(ktype,
"FULL") &&
3248 !strmatch(ktype,
"FULL2DIAG"))
3251 SG_ERROR(
"Undefined type, not DIAG, FULL or FULL2DIAG.\n")
3254 bool source_is_diag=
false;
3255 bool dest_is_diag=
false;
3257 if (strmatch(ktype,
"FULL2DIAG"))
3259 else if (strmatch(ktype,
"DIAG"))
3261 source_is_diag=
true;
3265 kernel=ui_kernel->create_custom(kmatrix, num_feat, num_vec,
3266 source_is_diag, dest_is_diag);
3268 else if (strmatch(type,
"CONST"))
3273 char* dtype=get_str_from_str_or_direct(len);
3274 if (strmatch(dtype,
"REAL"))
3276 int32_t size=get_int_from_int_or_str();
3279 c=get_real_from_real_or_str();
3281 kernel=ui_kernel->create_const(size, c);
3286 else if (strmatch(type,
"DIAG"))
3291 char* dtype=get_str_from_str_or_direct(len);
3292 if (strmatch(dtype,
"REAL"))
3294 int32_t size=get_int_from_int_or_str();
3297 diag=get_real_from_real_or_str();
3299 kernel=ui_kernel->create_diag(size, diag);
3305 else if (strmatch(type,
"TPPK"))
3310 char* dtype=get_str_from_str_or_direct(len);
3311 if (strmatch(dtype,
"INT"))
3313 int32_t size=get_int_from_int_or_str();
3317 get_matrix(km, rows, cols);
3318 kernel=ui_kernel->create_tppk(size, km, rows, cols);
3327 SG_DEBUG(
"created kernel: %p\n", kernel)
3340 int32_t from_order=0;
3341 bool normalize=
true;
3343 int32_t feature_class_len=0;
3344 char* feature_class_str=get_string(feature_class_len);
3345 ASSERT(feature_class_str)
3347 if (strmatch(feature_class_str,
"WD"))
3350 SG_ERROR(
"Please specify alphabet, WD, order, from_order\n")
3354 from_order=get_int();
3357 else if (strmatch(feature_class_str,
"WSPEC"))
3360 SG_ERROR(
"Please specify alphabet, order, WSPEC, start, normalize\n")
3365 normalize=get_bool();
3373 SG_FREE(feature_class_str);
3388 int32_t feature_class_len=0;
3390 char* feature_class_str=get_string(feature_class_len);
3391 ASSERT(feature_class_str)
3392 if (strmatch(feature_class_str,
"POLY"))
3398 normalize = get_bool();
3403 SG_ERROR(
"Unknown feature class: %s\n", feature_class_str)
3405 SG_FREE(feature_class_str);
3411 bool CSGInterface::cmd_init_kernel()
3417 bool CSGInterface::cmd_clean_kernel()
3419 if (m_nrhs<1 || !create_return_values(0))
3422 return ui_kernel->clean_kernel();
3425 bool CSGInterface::cmd_save_kernel()
3427 if (m_nrhs<2 || !create_return_values(0))
3431 char* filename=get_str_from_str_or_direct(len);
3433 bool success=ui_kernel->save_kernel(filename);
3439 bool CSGInterface::cmd_get_kernel_matrix()
3441 if (m_nrhs>2 || !create_return_values(1))
3448 target=get_string(len);
3449 bool success=ui_kernel->init_kernel(target);
3453 CKernel* kernel=ui_kernel->get_kernel();
3455 SG_ERROR(
"No kernel defined or not initialized.\n")
3466 bool CSGInterface::cmd_set_WD_position_weights()
3468 if (m_nrhs<2 || m_nrhs>3 || !create_return_values(0))
3471 CKernel* kernel=ui_kernel->get_kernel();
3490 get_matrix(weights, dim, len);
3497 if (dim!=1 && len>0)
3498 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n")
3500 ui_kernel->init_kernel(
"TRAIN");
3513 target=get_string(tlen);
3517 SG_ERROR(
"Couldn't find second argument to method.\n")
3520 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
3523 SG_ERROR(
"Second argument none of TRAIN or TEST.\n")
3526 if (strmatch(target,
"TEST"))
3530 if (dim!=1 && len>0)
3533 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n")
3536 if (dim==0 && len==0)
3538 if (create_return_values(3))
3550 if (create_return_values(3))
3559 ui_kernel->init_kernel(
"TRAIN");
3571 bool CSGInterface::cmd_get_subkernel_weights()
3573 if (m_nrhs!=1 || !create_return_values(1))
3576 CKernel *kernel=ui_kernel->get_kernel();
3585 int32_t num_weights=-1;
3586 weights=((
CCombinedKernel *) kernel)->get_subkernel_weights(num_weights);
3589 set_matrix(weights, 1, num_weights);
3599 get_degree_weights(degree, length);
3604 get_degree_weights(degree, length);
3607 SG_ERROR(
"Setting subkernel weights not supported on this kernel.\n")
3612 set_matrix(weights, degree, length);
3616 bool CSGInterface::cmd_set_subkernel_weights()
3618 if (m_nrhs!=2 || !create_return_values(0))
3621 CKernel* kernel=ui_kernel->get_kernel();
3629 get_matrix(weights, dim, len);
3637 if (dim!=degree || len<1)
3638 SG_ERROR(
"WD: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree)
3650 if (dim!=degree || len<1)
3651 SG_ERROR(
"WDPos: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree)
3661 if (dim!=1 || len!=num_subkernels)
3662 SG_ERROR(
"All: Dimension mismatch (should be 1 x num_subkernels)\n")
3671 bool CSGInterface::cmd_set_subkernel_weights_combined()
3673 if (m_nrhs!=3 || !create_return_values(0))
3676 CKernel* kernel=ui_kernel->get_kernel();
3680 SG_ERROR(
"Only works for combined kernels.\n")
3686 get_matrix(weights, dim, len);
3688 int32_t idx=get_int();
3689 SG_DEBUG(
"using kernel_idx=%i\n", idx)
3693 SG_ERROR(
"No subkernel at idx %d.\n", idx)
3701 if (dim!=degree || len<1)
3702 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3714 if (dim!=degree || len<1)
3715 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3725 if (dim!=1 || len!=num_subkernels)
3726 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n")
3735 bool CSGInterface::cmd_get_dotfeature_weights_combined()
3737 if (m_nrhs!=2 || !create_return_values(1))
3741 char* target=get_string(tlen);
3744 if (strmatch(target,
"TRAIN"))
3745 features=ui_features->get_train_features();
3746 else if (strmatch(target,
"TEST"))
3747 features=ui_features->get_test_features();
3751 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
3758 SG_ERROR(
"Only works for combined dot features.\n")
3766 bool CSGInterface::cmd_set_dotfeature_weights_combined()
3768 if (m_nrhs!=3 || !create_return_values(0))
3772 char* target=get_string(tlen);
3775 if (strmatch(target,
"TRAIN"))
3776 features=ui_features->get_train_features();
3777 else if (strmatch(target,
"TEST"))
3778 features=ui_features->get_test_features();
3782 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
3789 SG_ERROR(
"Only works for combined dot features.\n")
3794 get_matrix(weights, dim, len);
3801 bool CSGInterface::cmd_set_last_subkernel_weights()
3803 if (m_nrhs!=2 || !create_return_values(0))
3806 CKernel* kernel=ui_kernel->get_kernel();
3810 SG_ERROR(
"Only works for Combined kernels.\n")
3820 get_matrix(weights, dim, len);
3827 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3839 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3849 if (dim!=1 || len!=num_subkernels)
3850 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n")
3859 bool CSGInterface::cmd_get_WD_position_weights()
3861 if (m_nrhs!=1 || !create_return_values(1))
3864 CKernel* kernel=ui_kernel->get_kernel();
3872 SG_ERROR(
"Couldn't find last kernel.\n")
3876 SG_ERROR(
"Wrong subkernel type.\n")
3887 if (position_weights==NULL)
3888 set_vector(position_weights, 0);
3890 set_vector(position_weights, len);
3895 bool CSGInterface::cmd_get_last_subkernel_weights()
3897 if (m_nrhs!=1 || !create_return_values(1))
3900 CKernel* kernel=ui_kernel->get_kernel();
3905 SG_ERROR(
"Only works for Combined kernels.\n")
3909 SG_ERROR(
"Couldn't find last kernel.\n")
3916 int32_t num_weights=0;
3920 set_vector(weights, num_weights);
3927 get_degree_weights(degree, len);
3930 get_degree_weights(degree, len);
3932 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n")
3937 set_matrix(weights, degree, len);
3942 bool CSGInterface::cmd_compute_by_subkernels()
3944 if (m_nrhs!=1 || !create_return_values(1))
3947 CKernel* kernel=ui_kernel->get_kernel();
3964 SG_ERROR(
"Kernel optimization not initialized.\n")
3972 SG_ERROR(
"Kernel optimization not initialized.\n")
3975 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n")
3980 int32_t num_feat=degree*len;
3981 int32_t num=num_feat*num_vec;
3984 for (int32_t i=0; i<num; i++)
3990 for (int32_t i=0; i<num_vec; i++)
3997 for (int32_t i=0; i<num_vec; i++)
4001 set_matrix(result, num_feat, num_vec);
4007 bool CSGInterface::cmd_init_kernel_optimization()
4009 if (m_nrhs<1 || !create_return_values(0))
4012 return ui_kernel->init_kernel_optimization();
4015 bool CSGInterface::cmd_get_kernel_optimization()
4017 if (m_nrhs<1 || !create_return_values(1))
4020 CKernel* kernel=ui_kernel->get_kernel();
4031 int32_t max_order=get_int();
4032 if ((max_order<1) || (max_order>12))
4034 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order)
4039 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4044 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4049 for (int32_t i=0; i<num_suppvec; i++)
4056 num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4060 set_matrix(position_weights, num_sym, num_feat);
4061 SG_FREE(position_weights);
4074 set_vector(weights, len);
4092 bool CSGInterface::cmd_delete_kernel_optimization()
4094 if (m_nrhs<1 || !create_return_values(0))
4097 return ui_kernel->delete_kernel_optimization();
4100 bool CSGInterface::cmd_use_diagonal_speedup()
4102 if (m_nrhs<2 || !create_return_values(0))
4105 bool speedup=get_bool();
4107 CKernel* kernel=ui_kernel->get_kernel();
4113 SG_DEBUG(
"Identified combined kernel.\n")
4116 SG_ERROR(
"No last kernel defined.\n")
4120 SG_ERROR(
"Currently only commwordstring kernel supports diagonal speedup\n")
4124 SG_INFO(
"Diagonal speedup %s.\n", speedup ?
"enabled" :
"disabled")
4129 bool CSGInterface::cmd_set_kernel_optimization_type()
4131 if (m_nrhs<2 || !create_return_values(0))
4135 char* opt_type=get_str_from_str_or_direct(len);
4137 bool success=ui_kernel->set_optimization_type(opt_type);
4143 bool CSGInterface::cmd_set_solver()
4145 if (m_nrhs<2 || !create_return_values(0))
4149 char* solver=get_str_from_str_or_direct(len);
4151 bool success=ui_classifier->set_solver(solver);
4157 bool CSGInterface::cmd_set_constraint_generator()
4159 if (m_nrhs<2 || !create_return_values(0))
4163 char* cg=get_str_from_str_or_direct(len);
4165 bool success=ui_classifier->set_constraint_generator(cg);
4171 bool CSGInterface::cmd_set_prior_probs()
4173 if (m_nrhs<3 || !create_return_values(0))
4179 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n")
4181 float64_t pos_probs=get_real_from_real_or_str();
4182 float64_t neg_probs=get_real_from_real_or_str();
4189 bool CSGInterface::cmd_set_prior_probs_from_labels()
4191 if (m_nrhs<2 || !create_return_values(0))
4197 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n")
4201 get_vector(lab, len);
4204 for (int32_t i=0; i<len; i++)
4207 SG_ERROR(
"Couldn't set label %d (of %d): %f.\n", i, len, lab[i])
4218 bool CSGInterface::cmd_resize_kernel_cache()
4220 if (m_nrhs<2 || !create_return_values(0))
4223 int32_t size=get_int_from_int_or_str();
4224 return ui_kernel->resize_kernel_cache(size);
4226 #endif //USE_SVMLIGHT
4231 bool CSGInterface::cmd_set_distance()
4233 if (m_nrhs<3 || !create_return_values(0))
4238 char* type=get_str_from_str_or_direct(len);
4239 char* dtype=get_str_from_str_or_direct(len);
4241 if (strmatch(type,
"MINKOWSKI") && m_nrhs==4)
4243 float64_t k=get_real_from_real_or_str();
4244 distance=ui_distance->create_minkowski(k);
4246 else if (strmatch(type,
"MANHATTAN"))
4248 if (strmatch(dtype,
"REAL"))
4249 distance=ui_distance->create_generic(
D_MANHATTAN);
4250 else if (strmatch(dtype,
"WORD"))
4253 else if (strmatch(type,
"HAMMING") && strmatch(dtype,
"WORD"))
4255 bool use_sign=
false;
4257 use_sign=get_bool_from_bool_or_str();
4259 distance=ui_distance->create_hammingword(use_sign);
4261 else if (strmatch(type,
"CANBERRA"))
4263 if (strmatch(dtype,
"REAL"))
4264 distance=ui_distance->create_generic(
D_CANBERRA);
4265 else if (strmatch(dtype,
"WORD"))
4268 else if (strmatch(type,
"CHEBYSHEW") && strmatch(dtype,
"REAL"))
4270 distance=ui_distance->create_generic(
D_CHEBYSHEW);
4272 else if (strmatch(type,
"GEODESIC") && strmatch(dtype,
"REAL"))
4274 distance=ui_distance->create_generic(
D_GEODESIC);
4276 else if (strmatch(type,
"JENSEN") && strmatch(dtype,
"REAL"))
4278 distance=ui_distance->create_generic(
D_JENSEN);
4280 else if (strmatch(type,
"CHISQUARE") && strmatch(dtype,
"REAL"))
4282 distance=ui_distance->create_generic(
D_CHISQUARE);
4284 else if (strmatch(type,
"TANIMOTO") && strmatch(dtype,
"REAL"))
4286 distance=ui_distance->create_generic(
D_TANIMOTO);
4288 else if (strmatch(type,
"COSINE") && strmatch(dtype,
"REAL"))
4290 distance=ui_distance->create_generic(
D_COSINE);
4292 else if (strmatch(type,
"BRAYCURTIS") && strmatch(dtype,
"REAL"))
4296 else if (strmatch(type,
"EUCLIDEAN"))
4298 if (strmatch(dtype,
"REAL"))
4299 distance=ui_distance->create_generic(
D_EUCLIDEAN);
4300 else if (strmatch(dtype,
"SPARSEREAL"))
4308 return ui_distance->set_distance(distance);
4311 bool CSGInterface::cmd_init_distance()
4317 bool CSGInterface::cmd_get_distance_matrix()
4319 if (m_nrhs!=2 || !create_return_values(1))
4323 char* target=get_string(len);
4325 bool success=ui_distance->init_distance(target);
4331 SG_ERROR(
"No distance defined or not initialized.\n")
4343 bool CSGInterface::cmd_get_SPEC_consensus()
4345 if (m_nrhs!=1 || !create_return_values(1))
4348 CKernel* kernel=ui_kernel->get_kernel();
4352 SG_ERROR(
"Only works for CommWordString kernels.\n")
4354 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4357 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4361 for (int32_t i=0; i<num_suppvec; i++)
4368 num_feat, num_suppvec, sv_idx, sv_weight);
4372 set_vector(consensus, num_feat);
4378 bool CSGInterface::cmd_get_SPEC_scoring()
4380 if (m_nrhs!=2 || !create_return_values(1))
4383 int32_t max_order=get_int();
4384 CKernel* kernel=ui_kernel->get_kernel();
4390 SG_ERROR(
"Only works for (Weighted) CommWordString kernels.\n")
4392 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4395 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4400 for (int32_t i=0; i<num_suppvec; i++)
4406 if ((max_order<1) || (max_order>8))
4408 SG_WARNING(
"max_order out of range 1..8 (%d). setting to 1\n", max_order)
4415 max_order, num_feat, num_sym, NULL,
4416 num_suppvec, sv_idx, sv_weight);
4419 max_order, num_feat, num_sym, NULL,
4420 num_suppvec, sv_idx, sv_weight);
4424 set_matrix(position_weights, num_sym, num_feat);
4425 SG_FREE(position_weights);
4430 bool CSGInterface::cmd_get_WD_consensus()
4432 if (m_nrhs!=1 || !create_return_values(1))
4435 CKernel* kernel=ui_kernel->get_kernel();
4439 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4441 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4444 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4448 for (int32_t i=0; i<num_suppvec; i++)
4455 num_feat, num_suppvec, sv_idx, sv_weight);
4459 set_vector(consensus, num_feat);
4465 bool CSGInterface::cmd_compute_POIM_WD()
4467 if (m_nrhs!=3 || !create_return_values(1))
4470 int32_t max_order=get_int();
4472 int32_t num_dfeat=0;
4474 get_matrix(distribution, num_dfeat, num_dvec);
4479 CKernel* kernel=ui_kernel->get_kernel();
4483 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4493 if (num_dvec!=seqlen || num_dfeat!=num_sym)
4495 SG_ERROR(
"distribution should have (seqlen x num_sym) elements"
4496 "(seqlen: %d vs. %d symbols: %d vs. %d)\n", seqlen,
4497 num_dvec, num_sym, num_dfeat);
4500 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4503 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4506 for (int32_t i=0; i<num_suppvec; i++)
4522 max_order, seqlen, num_sym, NULL,
4523 num_suppvec, sv_idx, sv_weight, distribution);
4527 set_matrix(position_weights, num_sym, seqlen);
4528 SG_FREE(position_weights);
4533 bool CSGInterface::cmd_get_WD_scoring()
4535 if (m_nrhs!=2 || !create_return_values(1))
4538 int32_t max_order=get_int();
4540 CKernel* kernel=ui_kernel->get_kernel();
4544 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4546 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4549 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4554 for (int32_t i=0; i<num_suppvec; i++)
4560 if ((max_order<1) || (max_order>12))
4562 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order)
4568 max_order, num_feat, num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4572 set_matrix(position_weights, num_sym, num_feat);
4573 SG_FREE(position_weights);
4581 bool CSGInterface::cmd_classify()
4583 if (m_nrhs!=1 || !create_return_values(1))
4586 if (!ui_kernel->get_kernel() ||
4587 ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
4589 CFeatures* feat=ui_features->get_test_features();
4594 CLabels* labels=ui_classifier->classify();
4600 for (int32_t i=0; i<num_vec; i++)
4622 set_vector(result, num_vec);
4628 bool CSGInterface::cmd_classify_example()
4630 if (m_nrhs!=2 || !create_return_values(1))
4633 int32_t idx=get_int();
4636 if (!ui_classifier->classify_example(idx, result))
4637 SG_ERROR(
"Classify_example failed.\n")
4644 bool CSGInterface::cmd_get_classifier()
4646 if (m_nrhs<1 || m_nrhs>2 || !create_return_values(2))
4660 if (!ui_classifier->get_trained_classifier(
4661 weights, rows, cols, bias, brows, bcols, idx))
4666 set_matrix(bias, brows, bcols);
4671 set_matrix(weights, rows, cols);
4677 bool CSGInterface::cmd_new_classifier()
4679 if (m_nrhs<2 || !create_return_values(0))
4683 char* name=get_str_from_str_or_direct(len);
4689 d=get_int_from_int_or_str();
4692 from_d=get_int_from_int_or_str();
4695 bool success=ui_classifier->new_classifier(name, d, from_d);
4701 bool CSGInterface::cmd_save_classifier()
4703 if (m_nrhs<2 || !create_return_values(0))
4707 char* filename=get_str_from_str_or_direct(len);
4709 bool success=ui_classifier->save(filename);
4715 bool CSGInterface::cmd_load_classifier()
4717 if (m_nrhs<3 || !create_return_values(0))
4721 char* filename=get_str_from_str_or_direct(len);
4722 char* type=get_str_from_str_or_direct(len);
4724 bool success=ui_classifier->load(filename, type);
4726 if (dynamic_cast<CKernelMachine*>(ui_classifier->get_classifier()))
4739 bool CSGInterface::cmd_get_num_svms()
4741 if (m_nrhs!=1 || !create_return_values(1))
4744 set_int(ui_classifier->get_num_svms());
4750 bool CSGInterface::cmd_get_svm()
4752 return cmd_get_classifier();
4755 bool CSGInterface::cmd_set_svm()
4757 if (m_nrhs!=3 || !create_return_values(0))
4763 int32_t num_feat_alphas=0;
4764 int32_t num_vec_alphas=0;
4765 get_matrix(alphas, num_feat_alphas, num_vec_alphas);
4768 SG_ERROR(
"No proper alphas given.\n")
4769 if (num_vec_alphas!=2)
4770 SG_ERROR(
"Not 2 vectors in alphas.\n")
4772 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4774 SG_ERROR(
"No SVM object available.\n")
4780 for (int32_t i=0; i<num_support_vectors; i++)
4790 bool CSGInterface::cmd_set_linear_classifier()
4792 if (m_nrhs!=3 || !create_return_values(0))
4802 SG_ERROR(
"No proper weight vector given.\n")
4806 SG_ERROR(
"No Linear Classifier object available.\n")
4813 bool CSGInterface::cmd_get_svm_objective()
4815 if (m_nrhs!=1 || !create_return_values(1))
4818 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4827 bool CSGInterface::cmd_compute_svm_primal_objective()
4829 return do_compute_objective(SVM_PRIMAL);
4832 bool CSGInterface::cmd_compute_svm_dual_objective()
4834 return do_compute_objective(SVM_DUAL);
4837 bool CSGInterface::cmd_compute_mkl_dual_objective()
4839 return do_compute_objective(MKL_DUAL);
4842 bool CSGInterface::cmd_compute_relative_mkl_duality_gap()
4844 return do_compute_objective(MKL_RELATIVE_DUALITY_GAP);
4847 bool CSGInterface::cmd_compute_absolute_mkl_duality_gap()
4849 return do_compute_objective(MKL_ABSOLUTE_DUALITY_GAP);
4852 bool CSGInterface::do_compute_objective(E_WHICH_OBJ obj)
4854 if (m_nrhs!=1 || !create_return_values(1))
4859 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4864 trainlabels=ui_labels->get_train_labels();
4867 SG_ERROR(
"No trainlabels available.\n")
4869 CKernel* kernel=ui_kernel->get_kernel();
4873 if (!ui_kernel->is_initialized() || !kernel->
has_features())
4874 SG_ERROR(
"Kernel not initialized.\n")
4890 result=((
CMKL*) svm)->compute_mkl_primal_objective();
4894 result=((
CMKL*) svm)->compute_mkl_dual_objective();
4896 case MKL_RELATIVE_DUALITY_GAP:
4899 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4900 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4901 result=(primal-dual)/dual;
4904 case MKL_ABSOLUTE_DUALITY_GAP:
4907 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4908 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4913 SG_SERROR(
"Error calling do_compute_objective\n")
4921 bool CSGInterface::cmd_train_classifier()
4923 if (m_nrhs<1 || !create_return_values(0))
4926 CMachine* classifier=ui_classifier->get_classifier();
4928 SG_ERROR(
"No classifier available.\n")
4948 return ui_classifier->train_svm();
4950 return ui_classifier->train_mkl_multiclass();
4954 return ui_classifier->train_mkl();
4957 return ui_classifier->train_krr();
4964 int32_t k=get_int_from_int_or_str();
4966 return ui_classifier->train_knn(k);
4974 int32_t k=get_int_from_int_or_str();
4975 int32_t max_iter=get_int_from_int_or_str();
4977 return ui_classifier->train_clustering(k, max_iter);
4985 int32_t merges=get_int_from_int_or_str();
4987 return ui_classifier->train_clustering(merges);
4994 gamma=get_real_from_real_or_str();
4996 return ui_classifier->train_linear(gamma);
5007 return ui_classifier->train_linear();
5009 #ifdef USE_GPL_SHOGUN
5011 return ui_classifier->train_wdocas();
5015 SG_ERROR(
"Unknown classifier type %d.\n", type)
5021 bool CSGInterface::cmd_do_auc_maximization()
5023 if (m_nrhs!=2 || !create_return_values(0))
5026 bool do_auc=get_bool_from_bool_or_str();
5028 return ui_classifier->set_do_auc_maximization(do_auc);
5031 bool CSGInterface::cmd_set_perceptron_parameters()
5033 if (m_nrhs!=3 || !create_return_values(0))
5036 float64_t lernrate=get_real_from_real_or_str();
5037 int32_t maxiter=get_int_from_int_or_str();
5039 return ui_classifier->set_perceptron_parameters(lernrate, maxiter);
5042 bool CSGInterface::cmd_set_svm_qpsize()
5044 if (m_nrhs!=2 || !create_return_values(0))
5047 int32_t qpsize=get_int_from_int_or_str();
5049 return ui_classifier->set_svm_qpsize(qpsize);
5052 bool CSGInterface::cmd_set_svm_max_qpsize()
5054 if (m_nrhs!=2 || !create_return_values(0))
5057 int32_t max_qpsize=get_int_from_int_or_str();
5059 return ui_classifier->set_svm_max_qpsize(max_qpsize);
5062 bool CSGInterface::cmd_set_svm_bufsize()
5064 if (m_nrhs!=2 || !create_return_values(0))
5067 int32_t bufsize=get_int_from_int_or_str();
5069 return ui_classifier->set_svm_bufsize(bufsize);
5072 bool CSGInterface::cmd_set_svm_C()
5074 if (m_nrhs<2 || !create_return_values(0))
5077 float64_t C1=get_real_from_real_or_str();
5081 C2=get_real_from_real_or_str();
5083 return ui_classifier->set_svm_C(C1, C2);
5086 bool CSGInterface::cmd_set_svm_epsilon()
5088 if (m_nrhs!=2 || !create_return_values(0))
5091 float64_t epsilon=get_real_from_real_or_str();
5093 return ui_classifier->set_svm_epsilon(epsilon);
5096 bool CSGInterface::cmd_set_svr_tube_epsilon()
5098 if (m_nrhs!=2 || !create_return_values(0))
5101 float64_t tube_epsilon=get_real_from_real_or_str();
5103 return ui_classifier->set_svr_tube_epsilon(tube_epsilon);
5106 bool CSGInterface::cmd_set_svm_nu()
5108 if (m_nrhs!=2 || !create_return_values(0))
5111 float64_t nu=get_real_from_real_or_str();
5113 return ui_classifier->set_svm_nu(nu);
5116 bool CSGInterface::cmd_set_svm_mkl_parameters()
5118 if (m_nrhs<3 || m_nrhs>4 || !create_return_values(0))
5121 float64_t weight_epsilon=get_real_from_real_or_str();
5122 float64_t C_mkl=get_real_from_real_or_str();
5126 mkl_norm=get_real_from_real_or_str();
5128 return ui_classifier->set_svm_mkl_parameters(weight_epsilon, C_mkl, mkl_norm);
5131 bool CSGInterface::cmd_set_elasticnet_lambda()
5133 if (m_nrhs!=2 || !create_return_values(0))
5135 float64_t lambda=get_real_from_real_or_str();
5136 return ui_classifier->set_elasticnet_lambda(lambda);
5139 bool CSGInterface::cmd_set_mkl_block_norm()
5141 if (m_nrhs!=2 || !create_return_values(0))
5143 float64_t bnorm=get_real_from_real_or_str();
5144 return ui_classifier->set_mkl_block_norm(bnorm);
5148 bool CSGInterface::cmd_set_max_train_time()
5150 if (m_nrhs!=2 || !create_return_values(0))
5153 float64_t max_train_time=get_real_from_real_or_str();
5155 return ui_classifier->set_max_train_time(max_train_time);
5158 bool CSGInterface::cmd_set_svm_shrinking_enabled()
5160 if (m_nrhs!=2 || !create_return_values(0))
5163 bool shrinking_enabled=get_bool_from_bool_or_str();
5165 return ui_classifier->set_svm_shrinking_enabled(shrinking_enabled);
5168 bool CSGInterface::cmd_set_svm_batch_computation_enabled()
5170 if (m_nrhs!=2 || !create_return_values(0))
5173 bool batch_computation_enabled=get_bool_from_bool_or_str();
5175 return ui_classifier->set_svm_batch_computation_enabled(
5176 batch_computation_enabled);
5179 bool CSGInterface::cmd_set_svm_linadd_enabled()
5181 if (m_nrhs!=2 || !create_return_values(0))
5184 bool linadd_enabled=get_bool_from_bool_or_str();
5186 return ui_classifier->set_svm_linadd_enabled(linadd_enabled);
5189 bool CSGInterface::cmd_set_svm_bias_enabled()
5191 if (m_nrhs!=2 || !create_return_values(0))
5194 bool bias_enabled=get_bool_from_bool_or_str();
5196 return ui_classifier->set_svm_bias_enabled(bias_enabled);
5199 bool CSGInterface::cmd_set_mkl_interleaved_enabled()
5201 if (m_nrhs!=2 || !create_return_values(0))
5204 bool interleaved_enabled=get_bool_from_bool_or_str();
5206 return ui_classifier->set_mkl_interleaved_enabled(interleaved_enabled);
5209 bool CSGInterface::cmd_set_krr_tau()
5211 if (m_nrhs!=2 || !create_return_values(0))
5214 float64_t tau=get_real_from_real_or_str();
5216 return ui_classifier->set_krr_tau(tau);
5222 bool CSGInterface::cmd_add_preproc()
5224 if (m_nrhs<2 || !create_return_values(0))
5228 char* type=get_str_from_str_or_direct(len);
5231 if (strmatch(type,
"NORMONE"))
5232 preproc=ui_preproc->create_generic(
P_NORMONE);
5233 else if (strmatch(type,
"LOGPLUSONE"))
5235 else if (strmatch(type,
"SORTWORDSTRING"))
5237 else if (strmatch(type,
"SORTULONGSTRING"))
5239 else if (strmatch(type,
"DECOMPRESSCHARSTRING"))
5241 else if (strmatch(type,
"SORTWORD"))
5242 preproc=ui_preproc->create_generic(
P_SORTWORD);
5244 else if (strmatch(type,
"PRUNEVARSUBMEAN"))
5246 bool divide_by_std=
false;
5248 divide_by_std=get_bool_from_bool_or_str();
5250 preproc=ui_preproc->create_prunevarsubmean(divide_by_std);
5254 else if (strmatch(type,
"PCA") && m_nrhs==4)
5256 bool do_whitening=get_bool_from_bool_or_str();
5257 float64_t threshold=get_real_from_real_or_str();
5259 preproc=ui_preproc->create_pca(do_whitening, threshold);
5267 return ui_preproc->add_preproc(preproc);
5270 bool CSGInterface::cmd_del_preproc()
5272 if (m_nrhs!=1 || !create_return_values(0))
5275 return ui_preproc->del_preproc();
5278 bool CSGInterface::cmd_attach_preproc()
5280 if (m_nrhs<2 || !create_return_values(0))
5284 char* target=get_str_from_str_or_direct(len);
5286 bool do_force=
false;
5288 do_force=get_bool_from_bool_or_str();
5290 bool success=ui_preproc->attach_preproc(target, do_force);
5296 bool CSGInterface::cmd_clean_preproc()
5298 if (m_nrhs!=1 || !create_return_values(0))
5301 return ui_preproc->clean_preproc();
5306 bool CSGInterface::cmd_set_converter()
5309 char* type=get_str_from_str_or_direct(len);
5311 if (strmatch(type,
"lle"))
5313 int32_t k = get_int_from_int_or_str();
5314 ui_converter->create_locallylinearembedding(k);
5317 if (strmatch(type,
"npe"))
5319 int32_t k = get_int_from_int_or_str();
5320 ui_converter->create_neighborhoodpreservingembedding(k);
5323 if (strmatch(type,
"ltsa"))
5325 int32_t k = get_int_from_int_or_str();
5326 ui_converter->create_localtangentspacealignment(k);
5329 if (strmatch(type,
"lltsa"))
5331 int32_t k = get_int_from_int_or_str();
5332 ui_converter->create_linearlocaltangentspacealignment(k);
5335 if (strmatch(type,
"hlle"))
5337 int32_t k = get_int_from_int_or_str();
5338 ui_converter->create_hessianlocallylinearembedding(k);
5341 if (strmatch(type,
"laplacian_eigenmaps"))
5343 int32_t k = get_int_from_int_or_str();
5344 int32_t width = get_real_from_real_or_str();
5345 ui_converter->create_laplacianeigenmaps(k,width);
5348 if (strmatch(type,
"lpp"))
5350 int32_t k = get_int_from_int_or_str();
5351 int32_t width = get_real_from_real_or_str();
5352 ui_converter->create_localitypreservingprojections(k,width);
5355 if (strmatch(type,
"diffusion_maps"))
5357 int32_t t = get_int_from_int_or_str();
5358 int32_t width = get_real_from_real_or_str();
5359 ui_converter->create_diffusionmaps(t,width);
5362 if (strmatch(type,
"isomap"))
5364 int32_t k = get_int_from_int_or_str();
5365 ui_converter->create_isomap(k);
5368 if (strmatch(type,
"mds"))
5370 ui_converter->create_multidimensionalscaling();
5373 if (strmatch(type,
"jade"))
5375 ui_converter->create_jade();
5381 bool CSGInterface::cmd_apply_converter()
5383 if (m_nrhs!=1 || !create_return_values(1))
5392 bool CSGInterface::cmd_embed()
5394 int32_t target_dim = get_int_from_int_or_str();
5396 if (m_nrhs!=1 || !create_return_values(1))
5407 bool CSGInterface::cmd_new_plugin_estimator()
5409 if (m_nrhs<2 || !create_return_values(0))
5412 float64_t pos_pseudo=get_real_from_real_or_str();
5413 float64_t neg_pseudo=get_real_from_real_or_str();
5415 return ui_pluginestimate->new_estimator(pos_pseudo, neg_pseudo);
5418 bool CSGInterface::cmd_train_estimator()
5420 if (m_nrhs!=1 || !create_return_values(0))
5423 return ui_pluginestimate->train();
5426 bool CSGInterface::cmd_plugin_estimate_classify_example()
5428 if (m_nrhs!=2 || !create_return_values(1))
5431 int32_t idx=get_int();
5432 float64_t result=ui_pluginestimate->apply_one(idx);
5434 set_vector(&result, 1);
5438 bool CSGInterface::cmd_plugin_estimate_classify()
5440 if (m_nrhs!=1 || !create_return_values(1))
5443 CFeatures* feat=ui_features->get_test_features();
5449 CLabels* labels=ui_pluginestimate->apply();
5450 for (int32_t i=0; i<num_vec; i++)
5454 set_vector(result, num_vec);
5460 bool CSGInterface::cmd_set_plugin_estimate()
5462 if (m_nrhs!=3 || !create_return_values(0))
5466 int32_t num_probs=0;
5468 get_matrix(emission_probs, num_probs, num_vec);
5471 SG_ERROR(
"Need at least 1 set of positive and 1 set of negative params.\n")
5474 float64_t* neg_params=&(emission_probs[num_probs]);
5478 get_vector(model_sizes, len);
5480 int32_t seq_length=(int32_t) model_sizes[0];
5481 int32_t num_symbols=(int32_t) model_sizes[1];
5482 if (num_probs!=seq_length*num_symbols)
5483 SG_ERROR(
"Mismatch in number of emission probs and sequence length * number of symbols.\n")
5485 ui_pluginestimate->get_estimator()->set_model_params(
5486 pos_params, neg_params, seq_length, num_symbols);
5491 bool CSGInterface::cmd_get_plugin_estimate()
5493 if (m_nrhs!=1 || !create_return_values(2))
5498 int32_t num_params=0;
5499 int32_t seq_length=0;
5500 int32_t num_symbols=0;
5502 if (!ui_pluginestimate->get_estimator()->get_model_params(
5503 pos_params, neg_params, seq_length, num_symbols))
5506 num_params=seq_length*num_symbols;
5509 for (int32_t i=0; i<num_params; i++)
5510 result[i]=pos_params[i];
5511 for (int32_t i=0; i<num_params; i++)
5512 result[i+num_params]=neg_params[i];
5514 set_matrix(result, num_params, 2);
5520 set_vector(model_sizes, 2);
5525 bool CSGInterface::cmd_convergence_criteria()
5527 if (m_nrhs<3 || !create_return_values(0))
5530 int32_t num_iterations=get_int_from_int_or_str();
5531 float64_t epsilon=get_real_from_real_or_str();
5533 return ui_hmm->convergence_criteria(num_iterations, epsilon);
5536 bool CSGInterface::cmd_normalize()
5538 if (m_nrhs<2 || !create_return_values(0))
5541 bool keep_dead_states=get_bool_from_bool_or_str();
5543 return ui_hmm->normalize(keep_dead_states);
5546 bool CSGInterface::cmd_add_states()
5548 if (m_nrhs<3 || !create_return_values(0))
5551 int32_t num_states=get_int_from_int_or_str();
5552 float64_t value=get_real_from_real_or_str();
5554 return ui_hmm->add_states(num_states, value);
5557 bool CSGInterface::cmd_permutation_entropy()
5559 if (m_nrhs<3 || !create_return_values(0))
5562 int32_t width=get_int_from_int_or_str();
5563 int32_t seq_num=get_int_from_int_or_str();
5565 return ui_hmm->permutation_entropy(width, seq_num);
5568 bool CSGInterface::cmd_relative_entropy()
5570 if (m_nrhs!=1 || !create_return_values(1))
5575 bool success=ui_hmm->relative_entropy(entropy, len);
5579 set_vector(entropy, len);
5585 bool CSGInterface::cmd_entropy()
5587 if (m_nrhs!=1 || !create_return_values(1))
5592 bool success=ui_hmm->entropy(entropy, len);
5596 set_vector(entropy, len);
5602 bool CSGInterface::cmd_hmm_classify()
5604 return do_hmm_classify(
false,
false);
5607 bool CSGInterface::cmd_one_class_hmm_classify()
5609 return do_hmm_classify(
false,
true);
5612 bool CSGInterface::cmd_one_class_linear_hmm_classify()
5614 return do_hmm_classify(
true,
true);
5617 bool CSGInterface::do_hmm_classify(
bool linear,
bool one_class)
5619 if (m_nrhs>1 || !create_return_values(1))
5622 CFeatures* feat=ui_features->get_test_features();
5631 labels=ui_hmm->linear_one_class_classify();
5636 labels=ui_hmm->one_class_classify();
5638 labels=ui_hmm->classify();
5644 for (int32_t i=0; i<num_vec; i++)
5648 set_vector(result, num_vec);
5654 bool CSGInterface::cmd_one_class_hmm_classify_example()
5656 return do_hmm_classify_example(
true);
5659 bool CSGInterface::cmd_hmm_classify_example()
5661 return do_hmm_classify_example(
false);
5664 bool CSGInterface::do_hmm_classify_example(
bool one_class)
5666 if (m_nrhs!=2 || !create_return_values(1))
5669 int32_t idx=get_int();
5673 result=ui_hmm->one_class_classify_example(idx);
5675 result=ui_hmm->classify_example(idx);
5682 bool CSGInterface::cmd_output_hmm()
5684 if (m_nrhs!=1 || !create_return_values(0))
5687 return ui_hmm->output_hmm();
5690 bool CSGInterface::cmd_output_hmm_defined()
5692 if (m_nrhs!=1 || !create_return_values(0))
5695 return ui_hmm->output_hmm_defined();
5698 bool CSGInterface::cmd_hmm_likelihood()
5700 if (m_nrhs!=1 || !create_return_values(1))
5703 CHMM* h=ui_hmm->get_current();
5708 set_real(likelihood);
5713 bool CSGInterface::cmd_likelihood()
5715 if (m_nrhs!=1 || !create_return_values(0))
5718 return ui_hmm->likelihood();
5721 bool CSGInterface::cmd_save_likelihood()
5723 if (m_nrhs<2 || !create_return_values(0))
5727 char* filename=get_str_from_str_or_direct(len);
5729 bool is_binary=
false;
5731 is_binary=get_bool_from_bool_or_str();
5733 bool success=ui_hmm->save_likelihood(filename, is_binary);
5739 bool CSGInterface::cmd_get_viterbi_path()
5741 if (m_nrhs!=2 || !create_return_values(2))
5744 int32_t dim=get_int();
5747 CHMM* h=ui_hmm->get_current();
5751 CFeatures* feat=ui_features->get_test_features();
5761 if (!vec || num_feat<=0)
5768 SG_DEBUG(
"computing viterbi path for vector %d (length %d)\n", dim, num_feat)
5772 set_vector(path, num_feat);
5774 set_real(likelihood);
5779 bool CSGInterface::cmd_viterbi_train()
5781 if (m_nrhs!=1 || !create_return_values(0))
5784 return ui_hmm->viterbi_train();
5787 bool CSGInterface::cmd_viterbi_train_defined()
5789 if (m_nrhs!=1 || !create_return_values(0))
5792 return ui_hmm->viterbi_train_defined();
5795 bool CSGInterface::cmd_baum_welch_train()
5797 if (m_nrhs!=1 || !create_return_values(0))
5800 return ui_hmm->baum_welch_train();
5803 bool CSGInterface::cmd_baum_welch_train_defined()
5805 if (m_nrhs!=1 || !create_return_values(0))
5808 return ui_hmm->baum_welch_train_defined();
5812 bool CSGInterface::cmd_baum_welch_trans_train()
5814 if (m_nrhs!=1 || !create_return_values(0))
5817 return ui_hmm->baum_welch_trans_train();
5820 bool CSGInterface::cmd_linear_train()
5822 if (m_nrhs<1 || !create_return_values(0))
5828 char* align=get_str_from_str_or_direct(len);
5830 bool success=ui_hmm->linear_train(align[0]);
5836 return ui_hmm->linear_train();
5839 bool CSGInterface::cmd_save_path()
5841 if (m_nrhs<2 || !create_return_values(0))
5845 char* filename=get_str_from_str_or_direct(len);
5847 bool is_binary=
false;
5849 is_binary=get_bool_from_bool_or_str();
5851 bool success=ui_hmm->save_path(filename, is_binary);
5857 bool CSGInterface::cmd_append_hmm()
5859 if (m_nrhs!=5 || !create_return_values(0))
5862 CHMM* old_h=ui_hmm->get_current();
5877 get_matrix(a, M_a, N_a);
5883 get_matrix(b, M_b, N_b);
5886 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
5888 SG_ERROR(
"Model matrices not matching in size.\n"
5889 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
5890 N_p, N_q, N_a, M_a, N_b, M_b);
5893 CHMM* h=
new CHMM(N, M, NULL, ui_hmm->get_pseudo());
5904 h->
set_a(i,j, a[i+j*N]);
5908 h->
set_b(i,j, b[i+j*N]);
5916 bool CSGInterface::cmd_append_model()
5918 if (m_nrhs<2 || !create_return_values(0))
5920 if (m_nrhs>2 && m_nrhs!=4)
5924 char* filename=get_str_from_str_or_direct(len);
5929 base1=get_int_from_int_or_str();
5930 base2=get_int_from_int_or_str();
5933 bool success=ui_hmm->append_model(filename, base1, base2);
5939 bool CSGInterface::cmd_new_hmm()
5941 if (m_nrhs!=3 || !create_return_values(0))
5944 int32_t n=get_int_from_int_or_str();
5945 int32_t m=get_int_from_int_or_str();
5947 return ui_hmm->new_hmm(n, m);
5950 bool CSGInterface::cmd_load_hmm()
5952 if (m_nrhs!=2 || !create_return_values(0))
5956 char* filename=get_str_from_str_or_direct(len);
5958 bool success=ui_hmm->load(filename);
5964 bool CSGInterface::cmd_save_hmm()
5966 if (m_nrhs<2 || !create_return_values(0))
5970 char* filename=get_str_from_str_or_direct(len);
5972 bool is_binary=
false;
5974 is_binary=get_bool_from_bool_or_str();
5976 bool success=ui_hmm->save(filename, is_binary);
5982 bool CSGInterface::cmd_set_hmm()
5984 if (m_nrhs!=5 || !create_return_values(0))
5998 get_matrix(a, M_a, N_a);
6004 get_matrix(b, M_b, N_b);
6007 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
6009 SG_ERROR(
"Model matrices not matching in size.\n"
6010 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
6011 N_p, N_q, N_a, M_a, N_b, M_b);
6014 CHMM* current=ui_hmm->get_current();
6016 SG_ERROR(
"Need a previously created HMM.\n")
6022 current->
set_p(i, p[i]);
6023 current->
set_q(i, q[i]);
6028 current->
set_a(i,j, a[i+j*N]);
6032 current->
set_b(i,j, b[i+j*N]);
6040 bool CSGInterface::cmd_set_hmm_as()
6042 if (m_nrhs!=2 || !create_return_values(0))
6046 char* target=get_str_from_str_or_direct(len);
6048 bool success=ui_hmm->set_hmm_as(target);
6054 bool CSGInterface::cmd_set_chop()
6056 if (m_nrhs!=2 || !create_return_values(0))
6059 float64_t value=get_real_from_real_or_str();
6060 return ui_hmm->chop(value);
6063 bool CSGInterface::cmd_set_pseudo()
6065 if (m_nrhs!=2 || !create_return_values(0))
6068 float64_t value=get_real_from_real_or_str();
6069 return ui_hmm->set_pseudo(value);
6072 bool CSGInterface::cmd_load_definitions()
6074 if (m_nrhs<2 || !create_return_values(0))
6078 char* filename=get_str_from_str_or_direct(len);
6082 do_init=get_bool_from_bool_or_str();
6084 bool success=ui_hmm->load_definitions(filename, do_init);
6090 bool CSGInterface::cmd_get_hmm()
6092 if (m_nrhs!=1 || !create_return_values(4))
6095 CHMM* h=ui_hmm->get_current();
6099 int32_t N=h->
get_N();
6100 int32_t M=h->
get_M();
6120 a[i+j*N]=h->
get_a(i, j);
6121 set_matrix(a, N, N);
6127 b[i+j*N]=h->
get_b(i, j);
6128 set_matrix(b, N, M);
6134 bool CSGInterface::cmd_best_path()
6136 if (m_nrhs!=3 || !create_return_values(0))
6139 int32_t from=get_int_from_int_or_str();
6140 int32_t to=get_int_from_int_or_str();
6142 return ui_hmm->best_path(from, to);
6145 bool CSGInterface::cmd_best_path_2struct()
6147 if (m_nrhs!=12 || !create_return_values(3))
6150 SG_ERROR(
"Sorry, this parameter list is awful!\n")
6155 void CSGInterface::get_vector(
bool*& vector, int32_t& len)
6157 int32_t* int_vector;
6158 get_vector(int_vector, len);
6161 vector= SG_MALLOC(
bool, len);
6163 for (int32_t i=0; i<len; i++)
6164 vector[i]= (int_vector[i]!=0);
6166 SG_FREE(int_vector);
6169 void CSGInterface::set_vector(
const bool* vector, int32_t len)
6171 int32_t* int_vector = SG_MALLOC(int32_t, len);
6172 for (int32_t i=0;i<len;i++)
6179 set_vector(int_vector,len);
6180 SG_FREE(int_vector);
6183 bool CSGInterface::cmd_set_plif_struct()
6188 get_vector(ids,Nid);
6194 get_string_list(names, Nname,Mname);
6200 get_matrix(all_limits, Mlimits, Nlimits);
6203 int32_t Npenalties=0;
6204 int32_t Mpenalties=0;
6206 get_matrix(all_penalties, Mpenalties, Npenalties);
6209 int32_t Ntransform=0;
6210 int32_t Mtransform=0;
6212 get_string_list(all_transform, Ntransform, Mtransform);
6217 get_vector(min_values,Nmin);
6222 get_vector(max_values,Nmax);
6226 bool* all_use_cache;
6227 get_vector(all_use_cache,Ncache);
6231 int32_t* all_use_svm;
6232 get_vector(all_use_svm,Nsvm);
6237 get_vector(all_do_calc,Ncalc);
6240 SG_ERROR(
"Ncalc!=Nsvm, Ncalc:%i, Nsvm:%i\n",Ncalc,Nsvm)
6242 SG_ERROR(
"Ncalc!=Ncache, Ncalc:%i, Ncache:%i\n",Ncalc,Ncache)
6243 if (Ncalc!=Ntransform)
6244 SG_ERROR(
"Ncalc!=Ntransform, Ncalc:%i, Ntransform:%i\n",Ncalc,Ntransform)
6246 SG_ERROR(
"Ncalc!=Nmin, Ncalc:%i, Nmin:%i\n",Ncalc,Nmin)
6248 SG_ERROR(
"Ncalc!=Nmax, Ncalc:%i, Nmax:%i\n",Ncalc,Nmax)
6249 if (Ncalc!=Npenalties)
6250 SG_ERROR(
"Ncalc!=Npenalties, Ncalc:%i, Npenalties:%i\n",Ncalc,Npenalties)
6252 SG_ERROR(
"Ncalc!=Nlimits, Ncalc:%i, Nlimits:%i\n",Ncalc,Nlimits)
6254 SG_ERROR(
"Ncalc!=Nname, Ncalc:%i, Nname:%i\n",Ncalc,Nname)
6256 SG_ERROR(
"Ncalc!=Nid, Ncalc:%i, Nid:%i\n",Ncalc,Nid)
6257 if (Mlimits!=Mpenalties)
6258 SG_ERROR(
"Mlimits!=Mpenalties, Mlimits:%i, Mpenalties:%i\n",Mlimits,Mpenalties)
6261 int32_t M = Mlimits;
6275 SG_FREE(all_transform);
6276 SG_FREE(all_do_calc);
6281 bool CSGInterface::cmd_get_plif_struct()
6289 int32_t* ids = SG_MALLOC(int32_t, N);
6296 bool* all_use_cache = SG_MALLOC(
bool, N);
6297 int32_t* all_use_svm = SG_MALLOC(int32_t, N);
6298 bool* all_do_calc = SG_MALLOC(
bool, N);
6299 for (int32_t i=0;i<N;i++)
6303 names[i].
slen = strlen(PEN[i]->get_plif_name());
6306 for (int32_t j=0;j<M;j++)
6308 all_limits[i*M+j]=limits[j];
6309 all_penalties[i*M+j]=penalties[j];
6311 all_transform[i].
string = (
char*) PEN[i]->get_transform_type();
6312 all_transform[i].
slen = strlen(PEN[i]->get_transform_type());
6321 set_string_list(names, N);
6322 set_matrix(all_limits, M, N);
6323 set_matrix(all_penalties, M, N);
6324 set_string_list(all_transform, N);
6325 set_vector(min_values,N);
6326 set_vector(max_values,N);
6327 set_vector(all_use_cache,N);
6328 set_vector(all_use_svm,N);
6329 set_vector(all_do_calc,N);
6332 SG_FREE(max_values);
6333 SG_FREE(min_values);
6335 SG_FREE(all_transform);
6336 SG_FREE(all_limits);
6337 SG_FREE(all_penalties);
6338 SG_FREE(all_use_cache);
6339 SG_FREE(all_use_svm);
6340 SG_FREE(all_do_calc);
6357 bool CSGInterface::cmd_signals_set_positions()
6361 bool CSGInterface::cmd_signals_set_labels()
6365 bool CSGInterface::cmd_signals_set_split()
6369 bool CSGInterface::cmd_signals_set_train_mask()
6373 bool CSGInterface::cmd_signals_add_feature()
6377 bool CSGInterface::cmd_signals_add_kernel()
6381 bool CSGInterface::cmd_signals_run()
6386 bool CSGInterface::cmd_init_dyn_prog()
6389 int32_t num_svms=get_int();
6392 ui_structure->set_dyn_prog(h);
6396 bool CSGInterface::cmd_clean_up_dyn_prog()
6398 return ui_structure->cleanup();
6401 bool CSGInterface::cmd_set_model()
6406 CDynProg* h = ui_structure->get_dyn_prog();
6417 get_ndarray(penalties_array,Dim,numDim);
6422 SG_ERROR(
"error computing plif matrix\n")
6423 ui_structure->set_num_states(Dim[0]);
6424 SG_FREE(penalties_array);
6428 bool use_orf = get_bool();
6429 ui_structure->set_use_orf(use_orf);
6436 get_matrix(mod_words, Nmod,Mmod);
6437 if (Nmod != num_svms)
6438 SG_ERROR(
"should be equal: Nmod: %i, num_svms: %i\n",Nmod,num_svms)
6444 int32_t num_states=0;
6445 int32_t feat_dim3=0;
6446 int32_t* state_signals;
6447 get_matrix(state_signals,num_states,feat_dim3);
6448 ASSERT(num_states==Dim[0])
6457 get_matrix(orf_info,Norf,Morf);
6461 ui_structure->set_orf_info(orf_info, Norf, Morf);
6469 bool CSGInterface::cmd_precompute_content_svms()
6475 seq = get_string(seq_len);
6481 get_vector(all_pos, Npos);
6488 get_matrix(weights, Nweights, num_svms);
6490 SG_PRINT(
"Dimension mismatch: got %i, expect %i\n", Nweights, 5440)
6491 ui_structure->set_content_svm_weights(weights, Nweights, num_svms);
6493 CDynProg* h = ui_structure->get_dyn_prog();
6495 SG_ERROR(
"no DynProg object found, use init_dyn_prog first\n")
6508 SG_DEBUG(
"precompute_content_svms done\n")
6512 bool CSGInterface::cmd_get_lin_feat()
6514 CDynProg* h = ui_structure->get_dyn_prog();
6516 SG_ERROR(
"no DynProg object found, use set_model first\n")
6519 int32_t dim1, dim2 = 0;
6522 set_matrix(lin_feat, dim1, dim2);
6526 bool CSGInterface::cmd_set_lin_feat()
6531 seq = get_string(Nseq);
6537 get_vector(all_pos, Npos);
6541 int32_t num_svms, seq_len;
6543 get_matrix(lin_feat, num_svms, seq_len);
6547 SG_ERROR(
"Dimension mismatch: got %i positions and (%ix%i) values\n", Npos, num_svms, seq_len)
6556 CDynProg* h = ui_structure->get_dyn_prog();
6558 SG_ERROR(
"no DynProg object found, use set_model first\n")
6570 bool CSGInterface::cmd_long_transition_settings()
6572 bool use_long_transitions = get_bool();
6573 int32_t threshold = get_int();
6574 int32_t max_len = get_int();
6576 CDynProg* h = ui_structure->get_dyn_prog();
6578 SG_ERROR(
"no DynProg object found, use set_model first\n")
6584 bool CSGInterface::cmd_set_feature_matrix()
6586 int32_t num_states = ui_structure->get_num_states();
6593 get_ndarray(features, Dims, numDims);
6596 SG_ERROR(
"expected a 3 dimensional array, got %i dimensions\n", numDims)
6597 if (Dims[0]!=num_states)
6598 SG_ERROR(
"number of rows (%i) not equal number of states (%i)\n",Dims[0], num_states)
6599 ASSERT(ui_structure->set_feature_matrix(features, Dims))
6601 ASSERT(ui_structure->set_feature_dims(Dims))
6608 bool CSGInterface::cmd_set_feature_matrix_sparse()
6610 int32_t num_pos = ui_structure->get_num_positions();
6611 int32_t num_states = ui_structure->get_num_states();
6615 int32_t dim11, dim12 ;
6617 get_sparse_matrix(features1, dim11, dim12);
6619 int32_t dim21, dim22 ;
6621 get_sparse_matrix(features2, dim21, dim22);
6626 int32_t *Dims = SG_MALLOC(int32_t, 3);
6631 ASSERT(Dims[0]==num_states)
6634 ASSERT(ui_structure->set_feature_matrix_sparse(features1, features2, Dims))
6635 ASSERT(ui_structure->set_feature_dims(Dims))
6643 bool CSGInterface::cmd_init_intron_list()
6646 int32_t Nstart_positions;
6647 int32_t* start_positions;
6648 get_vector(start_positions, Nstart_positions);
6652 int32_t Nend_positions;
6653 int32_t* end_positions;
6654 get_vector(end_positions, Nend_positions);
6660 get_vector(quality, Nquality);
6666 get_vector(all_pos, Nall_pos);
6669 ASSERT(Nquality==Nend_positions)
6670 ASSERT(Nend_positions==Nstart_positions)
6674 intron_list->
init_list(all_pos, Nall_pos);
6676 intron_list->
read_introns(start_positions, end_positions, quality, Nstart_positions);
6678 SG_FREE(start_positions);
6679 SG_FREE(end_positions);
6689 CDynProg* h = ui_structure->get_dyn_prog();
6691 SG_ERROR(
"no DynProg object found, use set_model first\n")
6697 bool CSGInterface::cmd_precompute_tiling_features()
6701 CDynProg* h = ui_structure->get_dyn_prog();
6703 int32_t Nintensities=0;
6705 get_vector(intensities, Nintensities);
6707 int32_t Nprobe_pos=0;
6709 get_vector(probe_pos, Nprobe_pos);
6710 ASSERT(Nprobe_pos==Nintensities)
6712 int32_t Ntiling_plif_ids=0;
6713 int32_t* tiling_plif_ids;
6714 get_vector(tiling_plif_ids, Ntiling_plif_ids);
6721 bool CSGInterface::cmd_best_path_trans()
6723 CDynProg* h = ui_structure->get_dyn_prog();
6730 int32_t* feat_dims = ui_structure->get_feature_dims();
6731 float64_t* features = (ui_structure->get_feature_matrix(
false));
6734 int32_t* orf_info = ui_structure->get_orf_info();
6735 bool use_orf = ui_structure->get_use_orf();
6744 SG_ERROR(
"# transitions from initial state (%i) does not match # states (%i)\n", Np, num_states)
6752 SG_ERROR(
"# transitions to end state (%i) does not match # states (%i)\n", Nq, num_states)
6758 get_vector(all_nbest, Nnbest);
6763 nbest =all_nbest[0];
6764 nother=all_nbest[1];
6767 nbest =all_nbest[0];
6774 int32_t Nseg_path=0;
6775 int32_t Mseg_path=0;
6777 get_matrix(seg_path, Nseg_path, Mseg_path);
6782 int32_t num_a_trans=0;
6784 get_matrix(a_trans, num_a_trans, Na_trans);
6793 get_matrix(loss, Nloss,Mloss);
6819 SG_ERROR(
"svm arrays inconsistent\n")
6824 SG_DEBUG(
"best_path_trans: M: %i, Mseg_path: %i\n", M, Mseg_path)
6841 bool segment_loss_non_zero=
false;
6842 for (int32_t i=0; i<Nloss*Mloss; i++)
6845 segment_loss_non_zero=
true;
6855 if (segment_loss_non_zero)
6857 SG_DEBUG(
"Using version with segment_loss\n")
6865 SG_DEBUG(
"Using version without segment_loss\n")
6882 for (int32_t k=0; k<(nbest+nother); k++)
6884 for (int32_t i=0; i<M; i++)
6886 d_my_path[i*(nbest+nother)+k] = states.
matrix[i+k*M] ;
6887 d_my_pos[i*(nbest+nother)+k] = my_pos.
matrix[i+k*M] ;
6890 set_vector(p_prob.
vector,nbest+nother);
6891 set_vector(d_my_path, (nbest+nother)*M);
6892 set_vector(d_my_pos, (nbest+nother)*M);
6901 bool CSGInterface::cmd_best_path_trans_deriv()
6903 int32_t num_states = ui_structure->get_num_states();
6904 int32_t* feat_dims = ui_structure->get_feature_dims();
6905 float64_t* features = (ui_structure->get_feature_matrix(
false));
6917 SG_ERROR(
"Np!=num_states; Np:%i num_states:%i",Np,num_states)
6925 SG_ERROR(
"Nq!=num_states; Nq:%i num_states:%i",Nq,num_states)
6932 int32_t Nseg_path=0;
6933 int32_t Mseg_path=0;
6935 get_matrix(seg_path,Nseg_path,Mseg_path);
6940 int32_t num_a_trans=0;
6942 get_matrix(a_trans, num_a_trans, Na_trans);
6951 get_matrix(loss, Nloss,Mloss);
6955 int32_t Nmystate_seq=0;
6956 int32_t* mystate_seq=NULL;
6957 get_vector(mystate_seq, Nmystate_seq);
6961 int32_t Nmypos_seq=0;
6962 int32_t* mypos_seq=NULL;
6963 get_vector(mypos_seq, Nmypos_seq);
6968 int32_t max_plif_id = 0 ;
6969 int32_t max_plif_len = 1 ;
6970 for (int32_t i=0; i<Nplif; i++)
6972 if (i>0 && PEN[i]->get_id()!=i)
6973 SG_ERROR(
"PEN[i]->get_id()!=i; PEN[%i]->get_id():%i ,\n",i, PEN[i]->get_id())
6976 if (PEN[i]->get_plif_len()>max_plif_len)
6981 CDynProg* h = ui_structure->get_dyn_prog();
6993 SG_ERROR(
"svm arrays inconsistent\n")
6995 int32_t *my_path = SG_MALLOC(int32_t, Nmypos_seq+1);
6996 memset(my_path, -1, Nmypos_seq*
sizeof(int32_t)) ;
6997 int32_t *my_pos = SG_MALLOC(int32_t, Nmypos_seq+1);
6998 memset(my_pos, -1, Nmypos_seq*
sizeof(int32_t)) ;
7001 for (int32_t i=0; i<Nmypos_seq; i++)
7003 my_path[i] = mystate_seq[i] ;
7004 my_pos[i] = mypos_seq[i] ;
7038 for (int32_t i=0; i<num_states; i++)
7040 for (int32_t j=0; j<num_states; j++)
7041 p_A_deriv[i+j*num_states] = h->
get_a_deriv(i, j) ;
7047 for (int32_t
id=0;
id<=max_plif_id;
id++)
7051 ASSERT(len<=max_plif_len)
7052 for (int32_t j=0; j<max_plif_len; j++)
7053 a_Plif_deriv.
element(
id, j)= deriv[j] ;
7056 set_vector(p_p_deriv, num_states);
7057 set_vector(p_q_deriv, num_states);
7058 set_matrix(p_A_deriv, num_states, num_states);
7059 set_matrix(p_Plif_deriv, (max_plif_id+1), max_plif_len);
7060 set_vector(p_my_scores, Nmypos_seq);
7061 set_vector(p_my_losses, Nmypos_seq);
7066 SG_FREE(p_Plif_deriv);
7077 SG_FREE(mystate_seq);
7083 bool CSGInterface::cmd_precompute_subkernels()
7085 if (m_nrhs!=1 || !create_return_values(0))
7088 return ui_kernel->precompute_subkernels();
7090 bool CSGInterface::cmd_crc()
7092 if (m_nrhs!=2 || !create_return_values(1))
7096 char*
string=get_string(slen);
7098 uint8_t* bstring=SG_MALLOC(uint8_t, slen);
7100 for (int32_t i=0; i<slen; i++)
7101 bstring[i]=
string[i];
7111 bool CSGInterface::cmd_system()
7113 if (m_nrhs<2 || !create_return_values(0))
7116 const int32_t MAX_LEN=10000;
7118 int32_t command_len=0;
7119 char* command=SG_MALLOC(
char, MAX_LEN+1);
7120 memset(command, 0,
sizeof(
char)*MAX_LEN+1);
7121 char* cmd=get_str_from_str_or_direct(len);
7122 strncat(command, cmd, MAX_LEN);
7126 while (m_rhs_counter<m_nrhs)
7128 char* arg=get_str_from_str_or_direct(len);
7129 command_len += len + 1;
7131 if (command_len >= MAX_LEN)
7136 strcat(command,
" ");
7137 strcat(command, arg);
7141 int status=system(command);
7146 bool CSGInterface::cmd_exit()
7152 bool CSGInterface::cmd_exec()
7154 if (m_nrhs<2 || !create_return_values(0))
7158 char* filename=get_str_from_str_or_direct(len);
7159 FILE* file=fopen(filename,
"r");
7163 SG_ERROR(
"Error opening file: %s.\n", filename)
7176 bool CSGInterface::cmd_set_output()
7178 if (m_nrhs<2 || !create_return_values(0))
7182 char* filename=get_str_from_str_or_direct(len);
7188 SG_INFO(
"Setting output file to: %s.\n", filename)
7190 if (strmatch(filename,
"STDERR"))
7191 io->set_target(stderr);
7192 else if (strmatch(filename,
"STDOUT"))
7193 io->set_target(stdout);
7196 file_out=fopen(filename,
"w");
7198 SG_ERROR(
"Error opening output file %s.\n", filename)
7199 io->set_target(file_out);
7205 bool CSGInterface::cmd_set_threshold()
7207 if (m_nrhs!=2 || !create_return_values(0))
7210 float64_t value=get_real_from_real_or_str();
7212 ui_math->set_threshold(value);
7216 bool CSGInterface::cmd_init_random()
7218 if (m_nrhs!=2 || !create_return_values(0))
7221 uint32_t initseed=(uint32_t) get_int_from_int_or_str();
7222 ui_math->init_random(initseed);
7227 bool CSGInterface::cmd_set_num_threads()
7229 if (m_nrhs!=2 || !create_return_values(0))
7232 int32_t num_threads=get_int_from_int_or_str();
7234 parallel->set_num_threads(num_threads);
7235 SG_INFO(
"Set number of threads to %d.\n", num_threads)
7240 bool CSGInterface::cmd_translate_string()
7242 if (m_nrhs!=4 || !create_return_values(1))
7247 get_vector(
string, len);
7249 int32_t order=get_int();
7250 int32_t start=get_int();
7252 const int32_t max_val=2;
7254 uint16_t* obs=SG_MALLOC(uint16_t, len);
7256 for (i=0; i<len; i++)
7258 switch ((
char)
string[i])
7260 case 'A': obs[i]=0;
break;
7261 case 'C': obs[i]=1;
break;
7262 case 'G': obs[i]=2;
break;
7263 case 'T': obs[i]=3;
break;
7264 case 'a': obs[i]=0;
break;
7265 case 'c': obs[i]=1;
break;
7266 case 'g': obs[i]=2;
break;
7267 case 't': obs[i]=3;
break;
7268 default:
SG_ERROR(
"Wrong letter in string.\n")
7273 for (i=len-1; i>=order-1; i--)
7276 for (j=i; j>=i-order+1; j--)
7277 value=(value>>max_val) | ((obs[j])<<(max_val*(order-1)));
7279 obs[i]=(uint16_t) value;
7282 for (i=order-2;i>=0;i--)
7285 for (j=i; j>=i-order+1; j--)
7287 value= (value >> max_val);
7289 value|=(obs[j]) << (max_val * (order-1));
7295 for (i=start; i<len; i++)
7299 set_vector(real_obs, len);
7305 bool CSGInterface::cmd_clear()
7332 bool CSGInterface::cmd_tic()
7338 bool CSGInterface::cmd_toc()
7344 bool CSGInterface::cmd_print()
7346 if (m_nrhs<2 || !create_return_values(0))
7350 char* msg=get_str_from_str_or_direct(len);
7358 bool CSGInterface::cmd_echo()
7360 if (m_nrhs<2 || !create_return_values(0))
7364 char* level=get_str_from_str_or_direct(len);
7366 if (strmatch(level,
"OFF"))
7381 bool CSGInterface::cmd_loglevel()
7383 if (m_nrhs<2 || !create_return_values(0))
7387 char* level=get_str_from_str_or_direct(len);
7389 if (strmatch(level,
"ALL") || strmatch(level,
"GCDEBUG"))
7391 else if (strmatch(level,
"DEBUG"))
7393 else if (strmatch(level,
"INFO"))
7395 else if (strmatch(level,
"NOTICE"))
7397 else if (strmatch(level,
"WARN"))
7399 else if (strmatch(level,
"ERROR"))
7401 else if (strmatch(level,
"CRITICAL"))
7403 else if (strmatch(level,
"ALERT"))
7405 else if (strmatch(level,
"EMERGENCY"))
7408 SG_ERROR(
"Unknown loglevel '%s'.\n", level)
7410 SG_INFO(
"Loglevel set to %s.\n", level)
7416 bool CSGInterface::cmd_syntax_highlight()
7418 if (m_nrhs<2 || !create_return_values(0))
7422 char* hili=get_str_from_str_or_direct(len);
7424 if (strmatch(hili,
"ON"))
7427 io->enable_syntax_highlighting();
7429 else if (strmatch(hili,
"OFF"))
7432 io->disable_syntax_highlighting();
7437 SG_INFO(
"Syntax hilighting set to %s.\n", hili)
7443 bool CSGInterface::cmd_progress()
7445 if (m_nrhs<2 || !create_return_values(0))
7449 char* progress=get_str_from_str_or_direct(len);
7451 if (strmatch(progress,
"ON"))
7452 io->enable_progress();
7453 else if (strmatch(progress,
"OFF"))
7454 io->disable_progress();
7456 SG_ERROR(
"arguments to progress are ON|OFF - found '%s'.\n", progress)
7458 SG_INFO(
"Progress set to %s.\n", progress)
7464 bool CSGInterface::cmd_get_version()
7466 if (m_nrhs!=1 || !create_return_values(1))
7469 set_int(version->get_version_revision());
7474 bool CSGInterface::cmd_help()
7476 if ((m_nrhs!=1 && m_nrhs!=2) || !create_return_values(0))
7484 SG_PRINT(
"Help is available for the following topics.\n"
7485 "-------------------------------------------\n\n");
7488 bool is_group_item=
false;
7502 SG_PRINT(
"\nUse sg('%shelp%s', '%s<topic>%s')"
7503 " to see the list of commands in this group, e.g.\n\n"
7504 "\tsg('%shelp%s', '%sFeatures%s')\n\n"
7505 "to see the list of commands for the 'Features' group.\n"
7506 "\nOr use sg('%shelp%s', '%sall%s')"
7507 " to see a brief listing of all commands.\n\nTo disable syntax"
7508 " highlighting (useful e.g. in the matlab GUI) use\n\n"
7509 "\tsg('syntax_highlight','OFF')\n",
7520 bool in_group=
false;
7522 char* command=get_string(clen);
7524 if (strmatch(
"doxygen", command) || strmatch(
"DOXYGEN", command))
7531 SG_PRINT(
"\\arg \\b %s \\verbatim %s%s%s \\endverbatim\n",
7539 SG_PRINT(
"\n\\section %s_sec %s\n",
7545 if (strmatch(
"all", command) || strmatch(
"ALL", command))
7560 SG_PRINT(
"\nCommands in group %s%s%s\n",
7584 found=strmatch(
sg_methods[i].command, command);
7589 SG_PRINT(
"Usage for %s%s%s\n\n\t%s%s%s%s%s\n",
7602 SG_PRINT(
"Commands in group %s%s%s\n\n",
7616 SG_PRINT(
"Could not find help for command %s.\n", command)
7619 SG_PRINT(
"\n\nUse sg('%shelp%s', '%s<command>%s')"
7620 " to see the usage pattern of a single command, e.g.\n\n"
7621 "\tsg('%shelp%s', '%sclassify%s')\n\n"
7622 " to see the usage pattern of the command 'classify'.\n",
7637 #ifdef TRACE_MEMORY_ALLOCS
7641 bool CSGInterface::cmd_whos()
7643 if ((m_nrhs!=1) || !create_return_values(0))
7646 #ifdef TRACE_MEMORY_ALLOCS
7647 SG_PRINT(
"Blocks allocated by shogun\n")
7648 list_memory_allocs();
7652 SG_PRINT(
"Requires shogun to be compiled with --enable-trace-mallocs\n")
7657 bool CSGInterface::cmd_send_command()
7662 char* arg=get_string(len);
7664 m_legacy_strptr=arg;
7666 char* command=get_str_from_str(len);
7672 if (strmatch(command,
sg_methods[i].command))
7676 m_nrhs=get_num_args_in_str()+1;
7680 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
7701 SG_ERROR(
"Non-supported legacy command %s.\n", command)
7708 bool CSGInterface::cmd_run_python()
7710 SG_ERROR(
"Only available in the elwms interface\n")
7714 bool CSGInterface::cmd_run_octave()
7716 SG_ERROR(
"Only available in the elwms interface\n")
7720 bool CSGInterface::cmd_run_r()
7722 SG_ERROR(
"Only available in the elwms interface\n")
7726 #ifdef USE_GPL_SHOGUN
7727 bool CSGInterface::cmd_pr_loqo()
7729 if (m_nrhs!=7 || !create_return_values(2))
7734 get_vector(c, lenc);
7741 get_matrix(H, nH, mH);
7747 get_matrix(A, nA, mA);
7753 get_vector(b, lenb);
7758 get_vector(l, lenl);
7763 get_vector(u, lenu);
7772 pr_loqo(n,m, c, H, A, b, l, u, x, y, 0, 5, 50, 0.05, 100, 0);
7787 #endif //USE_GPL_SHOGUN
7789 void CSGInterface::print_prompt()
7800 char* CSGInterface::get_str_from_str_or_direct(int32_t& len)
7802 if (m_legacy_strptr)
7803 return get_str_from_str(len);
7805 return get_string(len);
7808 int32_t CSGInterface::get_int_from_int_or_str()
7810 if (m_legacy_strptr)
7813 char* str=get_str_from_str(len);
7814 int32_t val=strtol(str, NULL, 10);
7823 float64_t CSGInterface::get_real_from_real_or_str()
7825 if (m_legacy_strptr)
7828 char* str=get_str_from_str(len);
7838 bool CSGInterface::get_bool_from_bool_or_str()
7840 if (m_legacy_strptr)
7843 char* str=get_str_from_str(len);
7844 bool val=strtol(str, NULL, 10)!=0;
7853 void CSGInterface::get_vector_from_int_vector_or_str(int32_t*& vector, int32_t& len)
7855 if (m_legacy_strptr)
7857 len=get_vector_len_from_str(len);
7864 vector=SG_MALLOC(int32_t, len);
7867 for (int32_t i=0; i<len; i++)
7869 str=get_str_from_str(slen);
7870 vector[i]=strtol(str, NULL, 10);
7876 get_vector(vector, len);
7879 void CSGInterface::get_vector_from_real_vector_or_str(
7882 if (m_legacy_strptr)
7884 len=get_vector_len_from_str(len);
7894 for (int32_t i=0; i<len; i++)
7896 str=get_str_from_str(slen);
7897 vector[i]=strtod(str, NULL);
7903 get_vector(vector, len);
7906 int32_t CSGInterface::get_vector_len_from_str(int32_t expected_len)
7908 int32_t num_args=get_num_args_in_str();
7910 if (expected_len==0 || num_args==expected_len)
7912 else if (num_args==2*expected_len)
7915 return expected_len;
7918 SG_ERROR(
"Expected vector length %d does not match actual length %d.\n", expected_len, num_args)
7923 char* CSGInterface::get_str_from_str(int32_t& len)
7925 if (!m_legacy_strptr)
7929 while (m_legacy_strptr[i]!=
'\0' && !isspace(m_legacy_strptr[i]))
7933 char* str=SG_MALLOC(
char, len+1);
7934 for (i=0; i<len; i++)
7935 str[i]=m_legacy_strptr[i];
7939 if (m_legacy_strptr[len]==
'\0')
7940 m_legacy_strptr=NULL;
7943 m_legacy_strptr=m_legacy_strptr+len;
7950 int32_t CSGInterface::get_num_args_in_str()
7952 if (!m_legacy_strptr)
7958 while (m_legacy_strptr[i]!=
'\0')
7960 if (!isspace(m_legacy_strptr[i]) && !in_arg)
7965 else if (isspace(m_legacy_strptr[i]) && in_arg)
7978 bool CSGInterface::handle()
7990 SG_DEBUG(
"command: %s, nrhs %d\n", command, m_nrhs)
7994 if (strmatch(command,
sg_methods[i].command))
8005 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
8016 SG_ERROR(
"Non-supported command %s%s%s.\n",
8035 SG_ERROR(
"Unknown command %s%s%s.\n",
virtual const char * get_name() const =0
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
#define N_GET_SVM_OBJECTIVE
#define N_COMPUTE_MKL_PRIMAL_OBJECTIVE
virtual int32_t get_max_vector_length()
#define N_COMPUTE_BY_SUBKERNELS
int32_t get_num_support_vectors()
#define N_RELATIVE_ENTROPY
Computes the standard linear kernel on CDotFeatures.
static bool set_handler()
void best_path_trans_deriv(int32_t *my_state_seq, int32_t *my_pos_seq, int32_t my_seq_len, const float64_t *seq_array, int32_t max_num_signals)
#define N_SET_CONSTRAINT_GENERATOR
static void fill_vector(T *vec, int32_t len, T value)
#define N_ADD_DOTFEATURES
#define N_INIT_KERNEL_OPTIMIZATION
virtual ELabelType get_label_type() const =0
#define N_HMM_CLASSIFY_EXAMPLE
#define N_SVM_MAX_TRAIN_TIME
Real Labels are real-valued labels.
#define N_SIGNALS_ADD_FEATURE
The class DenseFeatures implements dense feature matrices.
static char * skip_spaces(char *str)
virtual bool has_features()
void set_lin_feat(float64_t *p_lin_feat, int32_t p_num_svms, int32_t p_seq_len)
#define N_SIGNALS_SET_MODEL
void set_ansi_syntax_hilighting()
Class Distance, a base class for all the distances used in the Shogun toolbox.
#define N_ADD_MULTIPLE_FEATURES
float64_t compute_svm_primal_objective()
#define N_SET_PERCEPTRON_PARAMETERS
int32_t get_M() const
access function for number of observations M
RAWDNA - letters 0,1,2,3.
void set_dict_weights(SGMatrix< float64_t > dictionary_weights)
virtual void set_w(const SGVector< float64_t > src_w)
virtual EKernelType get_kernel_type()
#define N_SET_FEATURE_MATRIX_SPARSE
void set_observations(CStringFeatures< uint16_t > *obs, CHMM *hmm=NULL)
void set_plif_matrices(CPlifMatrix *pm)
The class Labels models labels, i.e. class assignments of objects.
void create_word_string()
virtual int32_t get_num_labels() const =0
void set_plif_transform_type(SGString< char > *transform_type, int32_t num_values, int32_t maxlen=0)
real valued labels (e.g. for regression, classifier outputs)
void set_observation_matrix(SGNDArray< float64_t > seq)
float64_t get_a_deriv(T_STATES line_, T_STATES column) const
multi-class labels 0,1,...
char * get_plif_name() const
static uint32_t crc32(uint8_t *data, int32_t len)
UI HMM (Hidden Markov Model)
SGMatrix< ST > get_feature_matrix()
void set_gene_string(SGVector< char > genestr)
void set_orf_info(SGMatrix< int32_t > orf_info)
void get_path_scores(float64_t **my_scores, int32_t *seq_len)
CPlifBase ** get_plif_matrix()
#define N_TRAIN_REGRESSION
#define N_COMPUTE_RELATIVE_MKL_DUALITY_GAP
static uint32_t get_seed()
returns number generator seed
#define N_TRAIN_CLASSIFIER
bool set_weights(SGMatrix< float64_t > new_weights)
#define N_OUTPUT_HMM_DEFINED
SGVector< float64_t > get_scores()
#define N_SET_PLIF_STRUCT
virtual int32_t get_num_vectors() const =0
#define N_GET_WD_POS_WEIGHTS
bool is_tree_initialized()
#define N_SET_PRIOR_PROBS_FROM_LABELS
#define N_DEL_LAST_KERNEL
#define SG_NOTIMPLEMENTED
The class Alphabet implements an alphabet and alphabet utility functions.
#define N_TRANSLATE_STRING
bool delete_position_weights()
#define N_GET_SPEC_CONSENSUS
#define N_SET_SUBKERNEL_WEIGHTS_COMBINED
#define N_ONE_CLASS_LINEAR_HMM_CLASSIFY
#define N_COMPUTE_ABSOLUTE_MKL_DUALITY_GAP
float64_t get_b(T_STATES line_, uint16_t column) const
static uint32_t get_log_range()
returns range of logtable
const char * get_command_suffix()
#define N_SIGNALS_SET_SPLIT
The SalzbergWordString kernel implements the Salzberg kernel.
A generic KernelMachine interface.
bool set_position_weights(float64_t *pws, int32_t len)
float64_t get_label(int32_t idx)
void set_pos(SGVector< int32_t > pos)
void set_plif_use_cache(SGVector< bool > use_cache)
#define N_VITERBI_TRAIN_DEFINED
#define N_DO_AUC_MAXIMIZATION
int32_t get_num_positions()
Features that compute the Weighted Degreee Kernel feature space explicitly.
Features that support dot products among other operations.
#define N_USE_BATCH_COMPUTATION
#define N_PLUGIN_ESTIMATE_CLASSIFY_EXAMPLE
SGMatrix< float64_t > get_kernel_matrix()
The WeightedCommWordString kernel may be used to compute the weighted spectrum kernel (i...
#define N_GET_DISTANCE_MATRIX
A generic learning machine interface.
#define N_GET_PLUGIN_ESTIMATE
bool set_label(int32_t idx, float64_t label)
#define N_CONVERGENCE_CRITERIA
#define N_INIT_INTRON_LIST
Features that compute the Weighted Spectrum Kernel feature space explicitly.
#define N_LOAD_CLASSIFIER
void precompute_content_values()
#define USAGE_IO(method, in, out)
Multiclass Labels for multi-class classification.
#define N_SAVE_CLASSIFIER
void init_list(int32_t *all_pos, int32_t len)
#define N_SET_PLUGIN_ESTIMATE
#define N_PRECOMPUTE_SUBKERNELS
const char * get_command_prefix()
void load_ascii_file(char *fname, bool remap_to_bin=true, EAlphabet ascii_alphabet=DNA, EAlphabet binary_alphabet=RAWDNA)
CSGInterfaceMethod sg_methods[]
#define N_GET_WD_CONSENSUS
void init_mod_words_array(SGMatrix< int32_t > p_mod_words_array)
#define N_BAUM_WELCH_TRAIN
#define USAGE_I(method, in)
#define N_MKL_USE_INTERLEAVED_OPTIMIZATION
#define N_APPLY_CONVERTER
float64_t model_probability(int32_t dimension=-1)
inline proxy for model probability.
float64_t compute_svm_dual_objective()
virtual bool apply_preprocessor(bool force_preprocessing=false)
bool compute_plif_matrix(SGNDArray< float64_t > penalties_array)
floatmax_t get_num_symbols()
void set_intron_list(CIntronList *intron_list, int32_t num_plifs)
virtual float64_t get_max_value() const
index_t num_features
total number of features
Class SGObject is the base class of all shogun objects.
#define N_COMPUTE_MKL_DUAL_OBJECTIVE
bool set_element(T e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
void set_bias(float64_t bias)
void set_q_vector(SGVector< float64_t > q)
#define N_SIGNALS_SET_POSITIONS
#define USAGE_O(method, out)
The CommWordString kernel may be used to compute the spectrum kernel from strings that have been mapp...
void add(Matrix A, Matrix B, Matrix C, typename Matrix::Scalar alpha=1.0, typename Matrix::Scalar beta=1.0)
const float64_t * get_cum_derivative(int32_t &p_len) const
#define N_SIGNALS_ADD_KERNEL
#define N_GET_KERNEL_MATRIX
#define N_TRAIN_CLUSTERING
#define N_SET_DOTFEATURE_WEIGHTS_COMBINED
#define N_COMPUTE_SVM_PRIMAL_OBJECTIVE
void set_plif_penalties(SGMatrix< float64_t > penalties)
void precompute_stop_codons()
static bool unset_handler()
#define N_SVM_CLASSIFY_EXAMPLE
void set_p(T_STATES offset, float64_t value)
void set_plif_limits(SGMatrix< float64_t > limits)
#define N_GET_LAST_SUBKERNEL_WEIGHTS
bool set_alpha(int32_t idx, float64_t val)
SGMatrix< int32_t > get_positions()
SGVector< float64_t > get_w() const
#define N_SIGNALS_SET_TRAIN_MASK
#define N_GET_DOTFEATURE_WEIGHTS_COMBINED
void set_prior_probs_from_labels(CLabels *labels)
bool delete_position_weights_rhs()
bool delete_position_weights_lhs()
float64_t get_q(T_STATES offset) const
virtual void set_position_weights(SGVector< float64_t > pws)
#define N_RESIZE_KERNEL_CACHE
#define N_SET_WD_POS_WEIGHTS
float64_t get_alpha(int32_t idx)
SGMatrix< int32_t > get_states()
void compute_by_tree(int32_t idx, float64_t *LevelContrib)
The Weighted Degree String kernel.
float64_t * get_degree_weights(int32_t &d, int32_t &len)
void best_path_set_segment_loss(SGMatrix< float64_t > segment_loss)
#define N_GET_KERNEL_OPTIMIZATION
#define N_BEST_PATH_2STRUCT
void set_content_type_array(SGMatrix< float64_t > seg_path)
int32_t get_use_svm() const
virtual EFeatureClass get_feature_class() const =0
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
#define N_SET_LINEAR_CLASSIFIER
void set_q(T_STATES offset, float64_t value)
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
void precompute_tiling_plifs(CPlif **PEN, const int32_t *tiling_plif_ids, const int32_t num_tiling_plifs)
bool set_support_vector(int32_t idx, int32_t val)
void set_plif_min_values(SGVector< float64_t > min_values)
float64_t get_q_deriv(T_STATES offset) const
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Multiple Kernel Learning.
float64_t * get_lin_feat(int32_t &dim1, int32_t &dim2)
#define N_BEST_PATH_TRANS_DERIV
virtual EMachineType get_classifier_type()
#define N_SET_FEATURE_MATRIX
#define N_CLEAN_UP_DYN_PROG
int32_t get_support_vector(int32_t idx)
T_STATES * get_path(int32_t dim, float64_t &prob)
const char * get_prompt_suffix()
void set_a_trans_matrix(SGMatrix< float64_t > a_trans)
virtual void set_subkernel_weights(SGVector< float64_t > weights)
#define N_GET_VITERBI_PATH
virtual void add_preprocessor(CPreprocessor *p)
#define N_SET_KERNEL_OPTIMIZATION_TYPE
void set_plif_ids(SGVector< int32_t > ids)
bool append_model(CHMM *append_model, float64_t *cur_out, float64_t *app_out)
virtual float64_t get_min_value() const
void set_plif_use_svm(SGVector< int32_t > use_svm)
#define N_GET_PLIF_STRUCT
#define N_SYNTAX_HIGHLIGHT
void get_dictionary(int32_t &dsize, float64_t *&dweights)
SGVector< float64_t > get_plif_limits()
float64_t get_p_deriv(T_STATES offset) const
bool set_position_weights_lhs(float64_t *pws, int32_t len, int32_t num)
#define N_CLASSIFY_EXAMPLE
float64_t get_a(T_STATES line_, T_STATES column) const
all of classes and functions are contained in the shogun namespace
SGVector< float64_t > get_plif_penalties()
#define N_DELETE_KERNEL_OPTIMIZATION
#define N_PERMUTATION_ENTROPY
bool is_tree_initialized()
#define N_PRECOMPUTE_CONTENT_SVMS
void disable_syntax_hilighting()
void set_prior_probs(float64_t pos_prior_, float64_t neg_prior_)
#define N_COMPUTE_SVM_DUAL_OBJECTIVE
virtual EKernelType get_kernel_type()=0
#define N_LONG_TRANSITION_SETTINGS
float64_t get_p(T_STATES offset) const
void set_plif_max_values(SGVector< float64_t > max_values)
#define N_LOAD_DEFINITIONS
The class Features is the base class of all feature objects.
#define N_NEW_PLUGIN_ESTIMATOR
#define N_TRAIN_ESTIMATOR
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
#define N_GET_SUBKERNEL_WEIGHTS
#define N_GET_SPEC_SCORING
Class Preprocessor defines a preprocessor interface.
#define N_SVR_TUBE_EPSILON
Dynamic Programming Class.
#define N_ONE_CLASS_HMM_CLASSIFY_EXAMPLE
#define N_BEST_PATH_TRANS
Features that allow stacking of a number of DotFeatures.
#define N_USE_DIAGONAL_SPEEDUP
virtual int32_t get_num_subkernels()
void set_p_vector(SGVector< float64_t > p)
#define N_ONE_CLASS_HMM_CLASSIFY
A generic Support Vector Machine Interface.
void set_plif_names(SGString< char > *names, int32_t num_values, int32_t maxlen=0)
void get_path_losses(float64_t **my_losses, int32_t *seq_len)
float64_t * get_degree_weights(int32_t &d, int32_t &len)
const T & element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const
void set_b(T_STATES line_, uint16_t column, float64_t value)
#define N_COMPUTE_POIM_WD
Binary Labels for binary classification.
void init_tiling_data(int32_t *probe_pos, float64_t *intensities, const int32_t num_probes)
bool compute_signal_plifs(SGMatrix< int32_t > state_signals)
bool set_position_weights_rhs(float64_t *pws, int32_t len, int32_t num)
virtual void set_bias(float64_t b)
#define N_SAVE_LIKELIHOOD
#define N_DEL_LAST_FEATURES
SGMatrix< float64_t > get_distance_matrix()
#define N_PLUGIN_ESTIMATE_CLASSIFY
virtual float64_t compute_by_tree(int32_t idx)
void set_kernel(CKernel *k)
implement DotFeatures for the polynomial kernel
#define N_BAUM_WELCH_TRANS_TRAIN
The Weighted Degree Position String kernel (Weighted Degree kernel with shifts).
const char * get_prompt_prefix()
#define N_PRECOMPUTE_TILING_FEATURES
#define N_BAUM_WELCH_TRAIN_DEFINED
#define N_SET_PRIOR_PROBS
Preprocessor SortWordString, sorts the indivual strings in ascending order.
#define N_SET_LAST_SUBKERNEL_WEIGHTS
float64_t * extract_w(int32_t max_degree, int32_t &num_feat, int32_t &num_sym, float64_t *w_result, int32_t num_suppvec, int32_t *IDX, float64_t *alphas)
void set_num_states(int32_t N)
bool has_property(EFeatureProperty p) const
void read_introns(int32_t *start_pos, int32_t *end_pos, int32_t *quality, int32_t len)
void long_transition_settings(bool use_long_transitions, int32_t threshold, int32_t max_len)
virtual bool has_features()
CSegmentLoss * get_segment_loss_object()
bool obtain_from_char_features(CStringFeatures< CT > *sf, int32_t start, int32_t p_order, int32_t gap, bool rev)
void set_a(T_STATES line_, T_STATES column, float64_t value)
index_t num_vectors
total number of vectors
#define N_SET_SUBKERNEL_WEIGHTS
int32_t get_degree() const
bool set_weights(SGMatrix< float64_t > new_weights)
static void delete_penalty_struct(CPlif **PEN, int32_t P)
void set_segment_loss(float64_t *segment_loss, int32_t m, int32_t n)
float64_t get_objective()
void init_content_svm_value_array(const int32_t p_num_svms)
void compute_nbest_paths(int32_t max_num_signals, bool use_orf, int16_t nbest, bool with_loss, bool with_multiple_sequences)
T_STATES get_N() const
access function for number of states N
virtual EFeatureType get_feature_type() const =0
void create_plifs(int32_t num_plifs, int32_t num_limits)
store plif arrays for all transitions in the model
#define N_SIGNALS_SET_LABELS
bool create_new_model(int32_t num)
#define N_SET_KERNEL_NORMALIZATION
void set_sparse_features(CSparseFeatures< float64_t > *seq_sparse1, CSparseFeatures< float64_t > *seq_sparse2)
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...