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 },
76 (&CSGInterface::cmd_pr_loqo),
78 "'Var1', Var1, 'Var2', Var2",
"results")
82 (&CSGInterface::cmd_load_features),
88 (&CSGInterface::cmd_save_features),
93 (&CSGInterface::cmd_clean_features),
98 (&CSGInterface::cmd_get_features),
103 (&CSGInterface::cmd_add_features),
109 (&CSGInterface::cmd_add_multiple_features),
115 (&CSGInterface::cmd_add_dotfeatures),
121 (&CSGInterface::cmd_set_features),
133 (&CSGInterface::cmd_set_reference_features),
138 (&CSGInterface::cmd_del_last_features),
143 (&CSGInterface::cmd_convert),
156 (&CSGInterface::cmd_reshape),
163 (&CSGInterface::cmd_load_labels),
169 (&CSGInterface::cmd_set_labels),
175 (&CSGInterface::cmd_get_labels),
180 {
"Kernel", NULL, NULL },
183 (&CSGInterface::cmd_set_kernel_normalization),
189 (&CSGInterface::cmd_set_kernel),
194 (&CSGInterface::cmd_add_kernel),
199 (&CSGInterface::cmd_del_last_kernel),
204 (&CSGInterface::cmd_init_kernel),
209 (&CSGInterface::cmd_clean_kernel),
214 (&CSGInterface::cmd_save_kernel),
219 (&CSGInterface::cmd_get_kernel_matrix),
224 (&CSGInterface::cmd_set_WD_position_weights),
229 (&CSGInterface::cmd_get_subkernel_weights),
234 (&CSGInterface::cmd_set_subkernel_weights),
239 (&CSGInterface::cmd_set_subkernel_weights_combined),
244 (&CSGInterface::cmd_get_dotfeature_weights_combined),
249 (&CSGInterface::cmd_set_dotfeature_weights_combined),
254 (&CSGInterface::cmd_set_last_subkernel_weights),
259 (&CSGInterface::cmd_get_WD_position_weights),
264 (&CSGInterface::cmd_get_last_subkernel_weights),
269 (&CSGInterface::cmd_compute_by_subkernels),
274 (&CSGInterface::cmd_init_kernel_optimization),
279 (&CSGInterface::cmd_get_kernel_optimization),
284 (&CSGInterface::cmd_delete_kernel_optimization),
289 (&CSGInterface::cmd_use_diagonal_speedup),
294 (&CSGInterface::cmd_set_kernel_optimization_type),
299 (&CSGInterface::cmd_set_solver),
304 (&CSGInterface::cmd_set_constraint_generator),
306 "|SVMLIGHT|LIGHT|SVMLIGHT_ONECLASS|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM" 311 (&CSGInterface::cmd_set_prior_probs),
316 (&CSGInterface::cmd_set_prior_probs_from_labels),
322 {
"Distance", NULL, NULL },
325 (&CSGInterface::cmd_set_distance),
330 (&CSGInterface::cmd_init_distance),
335 (&CSGInterface::cmd_get_distance_matrix),
340 {
"Classifier", NULL, NULL },
343 (&CSGInterface::cmd_classify),
348 (&CSGInterface::cmd_classify),
353 (&CSGInterface::cmd_classify_example),
358 (&CSGInterface::cmd_classify_example),
363 (&CSGInterface::cmd_get_classifier),
368 (&CSGInterface::cmd_get_classifier),
373 (&CSGInterface::cmd_new_classifier),
375 "|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM" 376 "|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF" 377 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA" 382 (&CSGInterface::cmd_new_classifier),
384 "|LIBSVM|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM" 385 "|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF" 386 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA" 391 (&CSGInterface::cmd_new_classifier),
396 (&CSGInterface::cmd_new_classifier),
401 (&CSGInterface::cmd_load_classifier),
406 (&CSGInterface::cmd_save_classifier),
411 (&CSGInterface::cmd_get_num_svms),
416 (&CSGInterface::cmd_get_svm),
421 (&CSGInterface::cmd_set_svm),
426 (&CSGInterface::cmd_set_linear_classifier),
431 (&CSGInterface::cmd_get_svm_objective),
436 (&CSGInterface::cmd_compute_svm_primal_objective),
441 (&CSGInterface::cmd_compute_svm_dual_objective),
446 (&CSGInterface::cmd_compute_svm_primal_objective),
451 (&CSGInterface::cmd_compute_mkl_dual_objective),
456 (&CSGInterface::cmd_compute_relative_mkl_duality_gap),
461 (&CSGInterface::cmd_compute_absolute_mkl_duality_gap),
466 (&CSGInterface::cmd_do_auc_maximization),
471 (&CSGInterface::cmd_set_perceptron_parameters),
476 (&CSGInterface::cmd_train_classifier),
481 (&CSGInterface::cmd_train_classifier),
486 (&CSGInterface::cmd_train_classifier),
491 (&CSGInterface::cmd_train_classifier),
496 (&CSGInterface::cmd_set_svm_qpsize),
501 (&CSGInterface::cmd_set_svm_max_qpsize),
506 (&CSGInterface::cmd_set_svm_bufsize),
511 (&CSGInterface::cmd_set_svm_C),
516 (&CSGInterface::cmd_set_svm_epsilon),
521 (&CSGInterface::cmd_set_svr_tube_epsilon),
526 (&CSGInterface::cmd_set_svm_nu),
531 (&CSGInterface::cmd_set_svm_mkl_parameters),
536 (&CSGInterface::cmd_set_elasticnet_lambda),
541 (&CSGInterface::cmd_set_mkl_block_norm),
546 (&CSGInterface::cmd_set_max_train_time),
551 (&CSGInterface::cmd_set_svm_shrinking_enabled),
556 (&CSGInterface::cmd_set_svm_batch_computation_enabled),
561 (&CSGInterface::cmd_set_svm_linadd_enabled),
566 (&CSGInterface::cmd_set_svm_bias_enabled),
571 (&CSGInterface::cmd_set_mkl_interleaved_enabled),
576 (&CSGInterface::cmd_set_krr_tau),
581 {
"Preprocessors", NULL, NULL },
584 (&CSGInterface::cmd_add_preproc),
589 (&CSGInterface::cmd_del_preproc),
594 (&CSGInterface::cmd_attach_preproc),
599 (&CSGInterface::cmd_clean_preproc),
603 {
"Converters", NULL, NULL },
606 (&CSGInterface::cmd_set_converter),
611 (&CSGInterface::cmd_apply_converter),
616 (&CSGInterface::cmd_embed),
621 {
"HMM", NULL, NULL },
624 (&CSGInterface::cmd_new_hmm),
629 (&CSGInterface::cmd_load_hmm),
634 (&CSGInterface::cmd_save_hmm),
639 (&CSGInterface::cmd_get_hmm),
644 (&CSGInterface::cmd_append_hmm),
649 (&CSGInterface::cmd_append_model),
654 (&CSGInterface::cmd_set_hmm),
659 (&CSGInterface::cmd_set_hmm_as),
664 (&CSGInterface::cmd_set_chop),
669 (&CSGInterface::cmd_set_pseudo),
674 (&CSGInterface::cmd_load_definitions),
679 (&CSGInterface::cmd_hmm_classify),
684 (&CSGInterface::cmd_one_class_linear_hmm_classify),
689 (&CSGInterface::cmd_one_class_hmm_classify),
694 (&CSGInterface::cmd_one_class_hmm_classify_example),
699 (&CSGInterface::cmd_hmm_classify_example),
704 (&CSGInterface::cmd_output_hmm),
709 (&CSGInterface::cmd_output_hmm_defined),
714 (&CSGInterface::cmd_hmm_likelihood),
719 (&CSGInterface::cmd_likelihood),
724 (&CSGInterface::cmd_save_likelihood),
729 (&CSGInterface::cmd_get_viterbi_path),
734 (&CSGInterface::cmd_viterbi_train_defined),
739 (&CSGInterface::cmd_viterbi_train),
744 (&CSGInterface::cmd_baum_welch_train),
749 (&CSGInterface::cmd_baum_welch_train_defined),
754 (&CSGInterface::cmd_baum_welch_trans_train),
759 (&CSGInterface::cmd_linear_train),
764 (&CSGInterface::cmd_save_path),
769 (&CSGInterface::cmd_convergence_criteria),
774 (&CSGInterface::cmd_normalize),
779 (&CSGInterface::cmd_add_states),
784 (&CSGInterface::cmd_permutation_entropy),
789 (&CSGInterface::cmd_relative_entropy),
794 (&CSGInterface::cmd_entropy),
799 (&CSGInterface::cmd_set_feature_matrix),
804 (&CSGInterface::cmd_set_feature_matrix_sparse),
809 (&CSGInterface::cmd_new_plugin_estimator),
814 (&CSGInterface::cmd_train_estimator),
819 (&CSGInterface::cmd_plugin_estimate_classify_example),
824 (&CSGInterface::cmd_plugin_estimate_classify),
829 (&CSGInterface::cmd_set_plugin_estimate),
834 (&CSGInterface::cmd_get_plugin_estimate),
837 {
"Signals", NULL, NULL },
840 (&CSGInterface::cmd_signals_set_model),
845 (&CSGInterface::cmd_signals_set_positions),
850 (&CSGInterface::cmd_signals_set_labels),
855 (&CSGInterface::cmd_signals_set_split),
860 (&CSGInterface::cmd_signals_set_train_mask),
865 (&CSGInterface::cmd_signals_add_feature),
870 (&CSGInterface::cmd_signals_add_kernel),
875 (&CSGInterface::cmd_signals_run),
878 {
"Structure", NULL, NULL },
881 (&CSGInterface::cmd_best_path),
886 (&CSGInterface::cmd_best_path_2struct),
898 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
902 (&CSGInterface::cmd_set_plif_struct),
915 (&CSGInterface::cmd_get_plif_struct),
928 (&CSGInterface::cmd_precompute_subkernels),
933 (&CSGInterface::cmd_precompute_content_svms),
940 (&CSGInterface::cmd_get_lin_feat),
945 (&CSGInterface::cmd_set_lin_feat),
950 (&CSGInterface::cmd_init_dyn_prog),
955 (&CSGInterface::cmd_clean_up_dyn_prog),
960 (&CSGInterface::cmd_init_intron_list),
967 (&CSGInterface::cmd_precompute_tiling_features),
974 (&CSGInterface::cmd_long_transition_settings),
982 (&CSGInterface::cmd_set_model),
991 (&CSGInterface::cmd_best_path_trans),
998 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
1002 (&CSGInterface::cmd_best_path_trans_deriv),
1019 USAGE_COMMA
"q_deriv" 1020 USAGE_COMMA
"cmd_deriv" 1021 USAGE_COMMA
"penalties_deriv" 1022 USAGE_COMMA
"my_scores" 1023 USAGE_COMMA
"my_loss")
1026 {
"POIM", NULL, NULL },
1029 (&CSGInterface::cmd_compute_POIM_WD),
1034 (&CSGInterface::cmd_get_SPEC_consensus),
1039 (&CSGInterface::cmd_get_SPEC_scoring),
1044 (&CSGInterface::cmd_get_WD_consensus),
1049 (&CSGInterface::cmd_get_WD_scoring),
1054 {
"Utility", NULL, NULL },
1057 (&CSGInterface::cmd_crc),
1062 (&CSGInterface::cmd_system),
1067 (&CSGInterface::cmd_exit),
1072 (&CSGInterface::cmd_exit),
1077 (&CSGInterface::cmd_exec),
1082 (&CSGInterface::cmd_set_output),
1087 (&CSGInterface::cmd_set_threshold),
1092 (&CSGInterface::cmd_init_random),
1097 (&CSGInterface::cmd_set_num_threads),
1102 (&CSGInterface::cmd_translate_string),
1104 "string, order, start",
"translation")
1108 (&CSGInterface::cmd_clear),
1113 (&CSGInterface::cmd_tic),
1118 (&CSGInterface::cmd_toc),
1123 (&CSGInterface::cmd_print),
1128 (&CSGInterface::cmd_echo),
1133 (&CSGInterface::cmd_loglevel),
1138 (&CSGInterface::cmd_syntax_highlight),
1143 (&CSGInterface::cmd_progress),
1148 (&CSGInterface::cmd_get_version),
1153 (&CSGInterface::cmd_help),
1158 (&CSGInterface::cmd_whos),
1163 (&CSGInterface::cmd_send_command),
1168 (&CSGInterface::cmd_run_python),
1170 "'Var1', Var1, 'Var2', Var2,..., python_function",
"results")
1174 (&CSGInterface::cmd_run_octave),
1176 "'Var1', Var1, 'Var2', Var2,..., octave_function",
"results")
1180 (&CSGInterface::cmd_run_r),
1182 "'Var1', Var1, 'Var2', Var2,..., r_function",
"results")
1188 CSGInterface::CSGInterface(
bool print_copyright)
1204 if (print_copyright)
1206 version->print_version();
1207 SG_PRINT(
"( seeding random number generator with %u (seed size %d))\n",
1210 SG_PRINT(
"initializing log-table (size=%i*%i*%i=%2.1fMB) ... ) ",
1221 CSGInterface::~CSGInterface()
1223 delete ui_classifier;
1225 delete ui_pluginestimate;
1231 delete ui_structure;
1235 delete ui_converter;
1241 void CSGInterface::reset()
1247 m_legacy_strptr=NULL;
1252 void CSGInterface::translate_arg(CSGInterface* source, CSGInterface* target)
1254 switch (source->get_argument_type())
1257 target->set_int(source->get_int());
1260 target->set_real(source->get_real());
1263 target->set_bool(source->get_bool());
1269 source->get_vector(v, len);
1270 target->set_vector(v, len);
1278 source->get_vector(v, len);
1279 target->set_vector(v, len);
1287 source->get_vector(v, len);
1288 target->set_vector(v, len);
1296 source->get_vector(v, len);
1297 target->set_vector(v, len);
1305 source->get_vector(v, len);
1306 target->set_vector(v, len);
1310 case VECTOR_SHORTREAL:
1314 source->get_vector(v, len);
1315 target->set_vector(v, len);
1323 source->get_vector(v, len);
1324 target->set_vector(v, len);
1332 source->get_vector(v, len);
1333 target->set_vector(v, len);
1341 int32_t max_str_len=0;
1343 source->get_string_list(strs, num_str, max_str_len);
1344 target->set_string_list(strs, num_str);
1351 int32_t max_str_len=0;
1353 source->get_string_list(strs, num_str,max_str_len);
1354 target->set_string_list(strs, num_str);
1361 int32_t max_str_len=0;
1363 source->get_string_list(strs, num_str,max_str_len);
1364 target->set_string_list(strs, num_str);
1371 int32_t max_str_len=0;
1373 source->get_string_list(strs, num_str, max_str_len);
1374 target->set_string_list(strs, num_str);
1381 int32_t max_str_len=0;
1383 source->get_string_list(strs, num_str, max_str_len);
1384 target->set_string_list(strs, num_str);
1392 int32_t* fmatrix=NULL;
1393 source->get_matrix(fmatrix, num_feat, num_vec);
1394 target->set_matrix(fmatrix, num_feat, num_vec);
1403 source->get_matrix(fmatrix, num_feat, num_vec);
1404 target->set_matrix(fmatrix, num_feat, num_vec);
1412 int16_t* fmatrix=NULL;
1413 source->get_matrix(fmatrix, num_feat, num_vec);
1414 target->set_matrix(fmatrix, num_feat, num_vec);
1418 case DENSE_SHORTREAL:
1423 source->get_matrix(fmatrix, num_feat, num_vec);
1424 target->set_matrix(fmatrix, num_feat, num_vec);
1432 uint16_t* fmatrix=NULL;
1433 source->get_matrix(fmatrix, num_feat, num_vec);
1434 target->set_matrix(fmatrix, num_feat, num_vec);
1521 source->get_sparse_matrix(fmatrix, num_feat, num_vec);
1523 for (int32_t i=0; i<num_vec; i++)
1524 nnz+=fmatrix[i].num_feat_entries;
1525 target->set_sparse_matrix(fmatrix, num_feat, num_vec, nnz);
1542 bool CSGInterface::cmd_load_features()
1544 if (m_nrhs<8 || !create_return_values(0))
1548 char* filename=get_str_from_str_or_direct(len);
1549 char* fclass=get_str_from_str_or_direct(len);
1550 char* type=get_str_from_str_or_direct(len);
1551 char* target=get_str_from_str_or_direct(len);
1552 int32_t size=get_int_from_int_or_str();
1553 int32_t comp_features=get_int_from_int_or_str();
1555 bool success=ui_features->load(
1556 filename, fclass, type, target, size, comp_features);
1565 bool CSGInterface::cmd_save_features()
1567 if (m_nrhs<5 || !create_return_values(0))
1571 char* filename=get_str_from_str_or_direct(len);
1572 char* type=get_str_from_str_or_direct(len);
1573 char* target=get_str_from_str_or_direct(len);
1575 bool success=ui_features->save(filename, type, target);
1583 bool CSGInterface::cmd_clean_features()
1585 if (m_nrhs<2 || !create_return_values(0))
1589 char* target=get_str_from_str_or_direct(len);
1591 bool success=ui_features->clean(target);
1597 bool CSGInterface::cmd_get_features()
1599 if (m_nrhs!=2 || !create_return_values(1))
1603 char* target=get_string(tlen);
1606 if (strmatch(target,
"TRAIN"))
1607 feat=ui_features->get_train_features();
1608 else if (strmatch(target,
"TEST"))
1609 feat=ui_features->get_test_features();
1613 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
1631 set_matrix(fmatrix, num_feat, num_vec);
1638 set_matrix(fmatrix, num_feat, num_vec);
1645 set_matrix(fmatrix, num_feat, num_vec);
1652 set_matrix(fmatrix, num_feat, num_vec);
1659 set_matrix(fmatrix, num_feat, num_vec);
1666 set_matrix(fmatrix, num_feat, num_vec);
1673 set_matrix(fmatrix, num_feat, num_vec);
1690 get_num_nonzero_entries();
1707 int32_t max_str_len=0;
1713 set_string_list(fmatrix, num_str);
1720 set_string_list(fmatrix, num_str);
1727 set_string_list(fmatrix, num_str);
1756 bool CSGInterface::cmd_add_features()
1758 if (m_nrhs<3 || !create_return_values(0))
1761 return do_set_features(
true,
false);
1764 bool CSGInterface::cmd_add_multiple_features()
1766 if ((m_nrhs!=4 && m_nrhs<5) || !create_return_values(0))
1769 int32_t repetitions=get_int();
1773 return do_set_features(
true,
false, repetitions);
1776 bool CSGInterface::cmd_add_dotfeatures()
1778 if (m_nrhs<3 || !create_return_values(0))
1781 return do_set_features(
true,
true);
1784 bool CSGInterface::cmd_set_features()
1786 if (m_nrhs<3 || !create_return_values(0))
1789 return do_set_features(
false,
false);
1792 bool CSGInterface::do_set_features(
bool add,
bool check_dot, int32_t repetitions)
1795 char* target=get_string(tlen);
1796 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
1799 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
1806 switch (get_argument_type())
1811 get_sparse_matrix(fmatrix, num_feat, num_vec);
1820 get_matrix(fmatrix, num_feat, num_vec);
1834 int32_t* fmatrix=NULL;
1835 get_matrix(fmatrix, num_feat, num_vec);
1845 int16_t* fmatrix=NULL;
1846 get_matrix(fmatrix, num_feat, num_vec);
1856 uint16_t* fmatrix=NULL;
1857 get_matrix(fmatrix, num_feat, num_vec);
1865 case DENSE_SHORTREAL:
1868 get_matrix(fmatrix, num_feat, num_vec);
1879 SG_ERROR(
"Please specify alphabet!\n")
1882 int32_t max_str_len=0;
1884 get_string_list(fmatrix, num_str, max_str_len);
1886 int32_t alphabet_len=0;
1887 char* alphabet_str=get_string(alphabet_len);
1890 if (strmatch(alphabet_str,
"DNABINFILE"))
1892 SG_FREE(alphabet_str);
1894 ASSERT(fmatrix[0].
string)
1904 SG_ERROR(
"Couldn't load DNA features from file.\n")
1911 bool convert_to_word=
false;
1912 bool convert_to_ulong=
false;
1914 if (strmatch(alphabet_str,
"DNAWORD"))
1917 convert_to_word=
true;
1919 else if (strmatch(alphabet_str,
"DNAULONG"))
1922 convert_to_ulong=
true;
1925 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1928 SG_FREE(alphabet_str);
1936 SG_ERROR(
"Couldnt set byte string features.\n")
1941 if (convert_to_word || convert_to_ulong)
1942 convert_to_bitembedding(feat, convert_to_word, convert_to_ulong);
1945 obtain_from_single_string(feat);
1952 SG_ERROR(
"Please specify alphabet!\n")
1955 int32_t max_str_len=0;
1957 get_string_list(fmatrix, num_str, max_str_len);
1959 int32_t alphabet_len=0;
1960 char* alphabet_str=get_string(alphabet_len);
1963 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1964 SG_FREE(alphabet_str);
1971 SG_ERROR(
"Couldnt set byte string features.\n")
1978 SG_ERROR(
"Wrong argument type %d.\n", get_argument_type())
1984 SG_ERROR(
"Feature type not supported by DOT Features\n")
1987 if (strmatch(target,
"TRAIN"))
1990 ui_features->set_train_features(feat);
1993 for (int32_t i=0; i<repetitions; i++)
1994 ui_features->add_train_dotfeatures((
CDotFeatures*) feat);
1998 for (int32_t i=0; i<repetitions; i++)
1999 ui_features->add_train_features(feat);
2005 ui_features->set_test_features(feat);
2008 for (int32_t i=0; i<repetitions; i++)
2009 ui_features->add_test_dotfeatures((
CDotFeatures*) feat);
2013 for (int32_t i=0; i<repetitions; i++)
2014 ui_features->add_test_features(feat);
2023 bool CSGInterface::cmd_set_reference_features()
2025 if (m_nrhs<3 || !create_return_values(0))
2029 char* target=get_str_from_str_or_direct(len);
2031 bool success=ui_features->set_reference_features(target);
2037 bool CSGInterface::cmd_del_last_features()
2039 if (m_nrhs<2 || !create_return_values(0))
2043 char* target=get_str_from_str_or_direct(len);
2044 bool success=ui_features->del_last_feature_obj(target);
2050 bool CSGInterface::cmd_convert()
2052 if (m_nrhs<5 || !create_return_values(0))
2056 char* target=get_str_from_str_or_direct(len);
2057 CFeatures* features=ui_features->get_convert_features(target);
2061 SG_ERROR(
"No \"%s\" features available.\n", target)
2064 char* from_class=get_str_from_str_or_direct(len);
2065 char* from_type=get_str_from_str_or_direct(len);
2066 char* to_class=get_str_from_str_or_direct(len);
2067 char* to_type=get_str_from_str_or_direct(len);
2070 if (strmatch(from_class,
"SIMPLE"))
2072 if (strmatch(from_type,
"REAL"))
2074 if (strmatch(to_class,
"SPARSE") &&
2075 strmatch(to_type,
"REAL"))
2077 result=ui_features->convert_simple_real_to_sparse_real(
2084 else if (strmatch(from_type,
"CHAR"))
2086 if (strmatch(to_class,
"STRING") &&
2087 strmatch(to_type,
"CHAR"))
2089 result=ui_features->convert_simple_char_to_string_char(
2092 else if (strmatch(to_class,
"SIMPLE"))
2094 if (strmatch(to_type,
"ALIGN") && m_nrhs==8)
2096 float64_t gap_cost=get_real_from_real_or_str();
2097 result=ui_features->convert_simple_char_to_simple_align(
2107 else if (strmatch(from_type,
"WORD"))
2109 if (strmatch(to_class,
"SIMPLE") &&
2110 strmatch(to_type,
"SALZBERG"))
2112 result=ui_features->convert_simple_word_to_simple_salzberg(
2123 else if (strmatch(from_class,
"SPARSE"))
2125 if (strmatch(from_type,
"REAL"))
2127 if (strmatch(to_class,
"SIMPLE") &&
2128 strmatch(to_type,
"REAL"))
2130 result=ui_features->convert_sparse_real_to_simple_real(
2140 else if (strmatch(from_class,
"STRING"))
2142 if (strmatch(from_type,
"CHAR"))
2144 if (strmatch(to_class,
"STRING"))
2153 order=get_int_from_int_or_str();
2157 start=get_int_from_int_or_str();
2161 gap=get_int_from_int_or_str();
2165 char* rev_str=get_str_from_str_or_direct(len);
2175 if (strmatch(to_type,
"BYTE"))
2177 result=ui_features->convert_string_char_to_string_generic<char,uint8_t>(
2181 else if (strmatch(to_type,
"WORD"))
2183 result=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2187 else if (strmatch(to_type,
"ULONG"))
2189 result=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2200 else if (strmatch(from_type,
"BYTE"))
2202 if (strmatch(to_class,
"STRING"))
2211 order=get_int_from_int_or_str();
2215 start=get_int_from_int_or_str();
2219 gap=get_int_from_int_or_str();
2223 char* rev_str=get_str_from_str_or_direct(len);
2233 if (strmatch(to_type,
"WORD"))
2235 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint16_t>(
2239 else if (strmatch(to_type,
"ULONG"))
2241 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint64_t>(
2252 else if (strmatch(from_type,
"WORD"))
2254 if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"TOP"))
2256 result=ui_features->convert_string_word_to_simple_top(
2259 else if (strmatch(to_class,
"SPEC") && strmatch(to_type,
"WORD") && m_nrhs==7)
2261 bool use_norm=get_bool();
2269 else if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"FK"))
2271 result=ui_features->convert_string_word_to_simple_fk(
2280 if (result && ui_features->set_convert_features(result, target))
2281 SG_INFO(
"Conversion was successful.\n")
2286 SG_FREE(from_class);
2290 return (result!=NULL);
2293 void CSGInterface::convert_to_bitembedding(
CFeatures* &features,
bool convert_to_word,
bool convert_to_ulong)
2307 if (convert_to_word)
2309 SG_INFO(
"Converting into word-bitembedding\n")
2310 features=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2314 if (convert_to_ulong)
2316 SG_INFO(
"Converting into ulong-bitembedding\n")
2317 features=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2322 void CSGInterface::obtain_from_single_string(
CFeatures* features)
2328 char* str=get_string(len);
2331 if (strmatch(str,
"from_position_list"))
2333 obtain_from_position_list(features);
2335 else if (strmatch(str,
"slide_window"))
2337 obtain_by_sliding_window(features);
2343 bool CSGInterface::obtain_from_position_list(
CFeatures* features)
2345 int32_t winsize=get_int();
2347 int32_t* shifts=NULL;
2348 int32_t num_shift=0;
2349 get_vector(shifts, num_shift);
2355 SG_DEBUG(
"winsize: %d num_shifts: %d skip: %d\n", winsize, num_shift, skip)
2359 for (int32_t i=0; i<num_shift; i++)
2371 obtain_by_position_list(winsize, &positions, skip)>0);
2377 obtain_by_position_list(winsize, &positions, skip)>0);
2383 obtain_by_position_list(winsize, &positions, skip)>0);
2389 obtain_by_position_list(winsize, &positions, skip)>0);
2393 SG_ERROR(
"Unsupported string features type.\n")
2399 bool CSGInterface::obtain_by_sliding_window(
CFeatures* features)
2401 int32_t winsize=get_int();
2402 int32_t shift=get_int();
2424 SG_SERROR(
"Unsupported string features type.\n")
2431 bool CSGInterface::cmd_reshape()
2433 if (m_nrhs<4 || !create_return_values(0))
2437 char* target=get_str_from_str_or_direct(len);
2438 int32_t num_feat=get_int_from_int_or_str();
2439 int32_t num_vec=get_int_from_int_or_str();
2441 bool success=ui_features->reshape(target, num_feat, num_vec);
2447 bool CSGInterface::cmd_load_labels()
2449 if (m_nrhs<4 || !create_return_values(0))
2453 char* filename=get_str_from_str_or_direct(len);
2454 char* target=get_str_from_str_or_direct(len);
2456 bool success=ui_labels->load(filename, target);
2463 bool CSGInterface::cmd_set_labels()
2465 if (m_nrhs!=3 || !create_return_values(0))
2469 char* target=get_string(tlen);
2470 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
2473 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2478 get_vector(lab, len);
2480 CLabels* labels=ui_labels->infer_labels(lab, len);
2484 if (strmatch(target,
"TRAIN"))
2485 ui_labels->set_train_labels(labels);
2486 else if (strmatch(target,
"TEST"))
2487 ui_labels->set_test_labels(labels);
2491 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2498 bool CSGInterface::cmd_get_labels()
2500 if (m_nrhs!=2 || !create_return_values(1))
2504 char* target=get_string(tlen);
2507 if (strmatch(target,
"TRAIN"))
2508 labels=ui_labels->get_train_labels();
2509 else if (strmatch(target,
"TEST"))
2510 labels=ui_labels->get_test_labels();
2514 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
2531 bool CSGInterface::cmd_set_kernel_normalization()
2533 if (m_nrhs<2 || !create_return_values(0))
2537 char* normalization=get_string(len);
2547 bool success=ui_kernel->set_normalization(normalization, c, r);
2549 SG_FREE(normalization);
2553 bool CSGInterface::cmd_set_kernel()
2555 if (m_nrhs<2 || !create_return_values(0))
2558 SG_DEBUG(
"SGInterface: set_kernel\n")
2559 CKernel* kernel=create_kernel();
2560 return ui_kernel->set_kernel(kernel);
2563 bool CSGInterface::cmd_add_kernel()
2565 if (m_nrhs<3 || !create_return_values(0))
2568 float64_t weight=get_real_from_real_or_str();
2571 CKernel* kernel=create_kernel();
2573 SG_DEBUG(
"SGInterface: add_kernel\n")
2574 return ui_kernel->add_kernel(kernel, weight);
2577 bool CSGInterface::cmd_del_last_kernel()
2579 if (m_nrhs<1 || !create_return_values(0))
2582 return ui_kernel->del_last_kernel();
2585 CKernel* CSGInterface::create_kernel()
2589 char* type=get_str_from_str_or_direct(len);
2591 SG_DEBUG(
"set_kernel with type: %s\n", type)
2593 if (strmatch(type,
"COMBINED"))
2598 int32_t size=get_int_from_int_or_str();
2599 bool append_subkernel_weights=
false;
2601 append_subkernel_weights=get_bool_from_bool_or_str();
2603 kernel=ui_kernel->create_combined(size, append_subkernel_weights);
2605 else if (strmatch(type,
"DISTANCE"))
2610 int32_t size=get_int_from_int_or_str();
2613 width=get_real_from_real_or_str();
2615 kernel=ui_kernel->create_distance(size, width);
2617 else if (strmatch(type,
"WAVELET"))
2623 char* dtype=get_str_from_str_or_direct(len);
2624 if (strmatch(dtype,
"REAL"))
2626 int32_t size=get_int_from_int_or_str();
2632 Wdilation=get_real_from_real_or_str();
2635 Wtranslation=get_real_from_real_or_str();
2638 kernel=ui_kernel->create_sigmoid(size, Wdilation, Wtranslation);
2643 else if (strmatch(type,
"LINEAR"))
2650 char* dtype=get_str_from_str_or_direct(len);
2651 int32_t size=get_int_from_int_or_str();
2654 scale=get_real_from_real_or_str();
2656 if (strmatch(dtype,
"BYTE"))
2657 kernel=ui_kernel->create_linearbyte(size, scale);
2658 else if (strmatch(dtype,
"WORD"))
2659 kernel=ui_kernel->create_linearword(size, scale);
2660 else if (strmatch(dtype,
"CHAR"))
2661 kernel=ui_kernel->create_linearstring(size, scale);
2662 else if (strmatch(dtype,
"REAL"))
2663 kernel=ui_kernel->create_linear(size, scale);
2664 else if (strmatch(dtype,
"SPARSEREAL"))
2665 kernel=ui_kernel->create_sparselinear(size, scale);
2669 else if (strmatch(type,
"HISTOGRAM"))
2674 char* dtype=get_str_from_str_or_direct(len);
2675 if (strmatch(dtype,
"WORD"))
2677 int32_t size=get_int_from_int_or_str();
2678 kernel=ui_kernel->create_histogramword(size);
2683 else if (strmatch(type,
"SALZBERG"))
2688 char* dtype=get_str_from_str_or_direct(len);
2689 if (strmatch(dtype,
"WORD"))
2691 int32_t size=get_int_from_int_or_str();
2692 kernel=ui_kernel->create_salzbergword(size);
2697 else if (strmatch(type,
"POLYMATCH"))
2702 char* dtype=get_str_from_str_or_direct(len);
2703 int32_t size=get_int_from_int_or_str();
2705 bool inhomogene=
false;
2706 bool normalize=
true;
2710 degree=get_int_from_int_or_str();
2713 inhomogene=get_bool_from_bool_or_str();
2715 normalize=get_bool_from_bool_or_str();
2719 if (strmatch(dtype,
"CHAR"))
2721 kernel=ui_kernel->create_polymatchstring(
2722 size, degree, inhomogene, normalize);
2724 else if (strmatch(dtype,
"WORD"))
2726 kernel=ui_kernel->create_polymatchwordstring(
2727 size, degree, inhomogene, normalize);
2732 else if (strmatch(type,
"MATCH"))
2737 char* dtype=get_str_from_str_or_direct(len);
2738 if (strmatch(dtype,
"WORD"))
2740 int32_t size=get_int_from_int_or_str();
2742 bool normalize=
true;
2745 d=get_int_from_int_or_str();
2747 normalize=get_bool_from_bool_or_str();
2749 kernel=ui_kernel->create_matchwordstring(size, d, normalize);
2754 else if (strmatch(type,
"WEIGHTEDCOMMSTRING") || strmatch(type,
"COMMSTRING"))
2756 char* dtype=get_str_from_str_or_direct(len);
2757 int32_t size=get_int_from_int_or_str();
2758 bool use_sign=
false;
2759 char* norm_str=NULL;
2763 use_sign=get_bool_from_bool_or_str();
2766 norm_str=get_str_from_str_or_direct(len);
2769 if (strmatch(dtype,
"WORD"))
2771 if (strmatch(type,
"WEIGHTEDCOMMSTRING"))
2773 kernel=ui_kernel->create_commstring(
2776 else if (strmatch(type,
"COMMSTRING"))
2778 kernel=ui_kernel->create_commstring(
2782 else if (strmatch(dtype,
"ULONG"))
2784 kernel=ui_kernel->create_commstring(
2791 else if (strmatch(type,
"CHI2"))
2796 char* dtype=get_str_from_str_or_direct(len);
2797 if (strmatch(dtype,
"REAL"))
2799 int32_t size=get_int_from_int_or_str();
2803 width=get_real_from_real_or_str();
2805 kernel=ui_kernel->create_chi2(size, width);
2810 else if (strmatch(type,
"FIXEDDEGREE"))
2815 char* dtype=get_str_from_str_or_direct(len);
2816 if (strmatch(dtype,
"CHAR"))
2818 int32_t size=get_int_from_int_or_str();
2821 d=get_int_from_int_or_str();
2823 kernel=ui_kernel->create_fixeddegreestring(size, d);
2828 else if (strmatch(type,
"LOCALALIGNMENT"))
2833 char* dtype=get_str_from_str_or_direct(len);
2834 if (strmatch(dtype,
"CHAR"))
2836 int32_t size=get_int_from_int_or_str();
2838 kernel=ui_kernel->create_localalignmentstring(size);
2843 else if (strmatch(type,
"OLIGO"))
2848 char* dtype=get_str_from_str_or_direct(len);
2849 if (strmatch(dtype,
"CHAR"))
2851 int32_t size=get_int_from_int_or_str();
2852 int32_t k=get_int_from_int_or_str();
2853 float64_t w=get_real_from_real_or_str();
2855 kernel=ui_kernel->create_oligo(size, k, w);
2860 else if (strmatch(type,
"WEIGHTEDDEGREEPOS2") ||
2861 strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2866 char* dtype=get_str_from_str_or_direct(len);
2867 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2869 int32_t size=get_int_from_int_or_str();
2870 int32_t order=get_int_from_int_or_str();
2871 int32_t max_mismatch=get_int_from_int_or_str();
2872 int32_t length=get_int_from_int_or_str();
2873 int32_t* shifts=NULL;
2875 get_vector_from_int_vector_or_str(shifts, l);
2879 bool use_normalization=
true;
2880 if (strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2881 use_normalization=
false;
2883 kernel=ui_kernel->create_weighteddegreepositionstring2(
2884 size, order, max_mismatch, shifts, length,
2892 else if (strmatch(type,
"WEIGHTEDDEGREEPOS3"))
2897 char* dtype=get_str_from_str_or_direct(len);
2898 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2900 int32_t size=get_int_from_int_or_str();
2901 int32_t order=get_int_from_int_or_str();
2902 int32_t max_mismatch=get_int_from_int_or_str();
2903 int32_t length=get_int_from_int_or_str();
2904 int32_t mkl_stepsize=get_int_from_int_or_str();
2905 int32_t* shifts=NULL;
2907 get_vector_from_int_vector_or_str(shifts, l);
2911 if (m_nrhs>9+length)
2913 get_vector_from_real_vector_or_str(
2914 position_weights, length);
2917 kernel=ui_kernel->create_weighteddegreepositionstring3(
2918 size, order, max_mismatch, shifts, length,
2919 mkl_stepsize, position_weights);
2921 SG_FREE(position_weights);
2927 else if (strmatch(type,
"WEIGHTEDDEGREEPOS"))
2932 char* dtype=get_str_from_str_or_direct(len);
2933 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2935 int32_t size=get_int_from_int_or_str();
2937 int32_t max_mismatch=0;
2944 order=get_int_from_int_or_str();
2948 max_mismatch=get_int_from_int_or_str();
2952 length=get_int_from_int_or_str();
2956 center=get_int_from_int_or_str();
2959 step=get_real_from_real_or_str();
2965 kernel=ui_kernel->create_weighteddegreepositionstring(
2966 size, order, max_mismatch, length, center, step);
2971 else if (strmatch(type,
"WEIGHTEDDEGREE"))
2976 char* dtype=get_str_from_str_or_direct(len);
2977 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2979 int32_t size=get_int_from_int_or_str();
2981 int32_t max_mismatch=0;
2982 bool use_normalization=
true;
2983 int32_t mkl_stepsize=1;
2984 bool block_computation=
true;
2985 int32_t single_degree=-1;
2989 order=get_int_from_int_or_str();
2993 max_mismatch=get_int_from_int_or_str();
2997 use_normalization=get_bool_from_bool_or_str();
3001 mkl_stepsize=get_int_from_int_or_str();
3005 block_computation=get_int_from_int_or_str();
3008 single_degree=get_int_from_int_or_str();
3015 kernel=ui_kernel->create_weighteddegreestring(
3016 size, order, max_mismatch, use_normalization,
3017 mkl_stepsize, block_computation, single_degree);
3022 else if (strmatch(type,
"WEIGHTEDDEGREERBF"))
3027 char* dtype=get_str_from_str_or_direct(len);
3028 int32_t size=get_int_from_int_or_str();
3029 int32_t nof_properties=get_int_from_int_or_str();
3034 degree=get_int_from_int_or_str();
3037 width=get_real_from_real_or_str();
3043 kernel=ui_kernel->create_weighteddegreerbf(size, degree, nof_properties, width);
3048 else if (strmatch(type,
"SPECTRUMMISMATCHRBF"))
3053 char* dtype=get_str_from_str_or_direct(len);
3054 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
3056 int32_t size=get_int_from_int_or_str();
3057 int32_t degree=get_int_from_int_or_str();
3058 int32_t max_mismatch=get_int_from_int_or_str();
3059 float64_t width=get_real_from_real_or_str();
3067 get_matrix(helper_matrix, N, M);
3069 if (N == 128 && M == 128)
3072 memcpy(AA_matrix, helper_matrix, N*M*
sizeof(
float64_t)) ;
3073 kernel=ui_kernel->create_spectrummismatchrbf(size, AA_matrix, 128, 128, max_mismatch, degree, width);
3077 SG_ERROR(
"Matrix size %d %d\n", N, M)
3084 else if (strmatch(type,
"SLIK") || strmatch(type,
"LIK"))
3089 char* dtype=get_str_from_str_or_direct(len);
3090 if (strmatch(dtype,
"CHAR"))
3092 int32_t size=get_int_from_int_or_str();
3094 int32_t inner_degree=3;
3095 int32_t outer_degree=1;
3099 length=get_int_from_int_or_str();
3103 inner_degree=get_int_from_int_or_str();
3106 outer_degree=get_int_from_int_or_str();
3110 if (strmatch(type,
"SLIK"))
3112 kernel=ui_kernel->create_localityimprovedstring(
3113 size, length, inner_degree, outer_degree,
3118 kernel=ui_kernel->create_localityimprovedstring(
3119 size, length, inner_degree, outer_degree,
3126 else if (strmatch(type,
"POLY"))
3131 char* dtype=get_str_from_str_or_direct(len);
3132 int32_t size=get_int_from_int_or_str();
3134 bool inhomogene=
false;
3135 bool normalize=
true;
3139 degree=get_int_from_int_or_str();
3143 inhomogene=get_bool_from_bool_or_str();
3146 normalize=get_bool_from_bool_or_str();
3150 if (strmatch(dtype,
"REAL"))
3152 kernel=ui_kernel->create_poly(
3153 size, degree, inhomogene, normalize);
3155 else if (strmatch(dtype,
"SPARSEREAL"))
3157 kernel=ui_kernel->create_sparsepoly(
3158 size, degree, inhomogene, normalize);
3163 else if (strmatch(type,
"SIGMOID"))
3168 char* dtype=get_str_from_str_or_direct(len);
3169 if (strmatch(dtype,
"REAL"))
3171 int32_t size=get_int_from_int_or_str();
3177 gamma=get_real_from_real_or_str();
3180 coef0=get_real_from_real_or_str();
3183 kernel=ui_kernel->create_sigmoid(size, gamma, coef0);
3188 else if (strmatch(type,
"GAUSSIAN"))
3193 char* dtype=get_str_from_str_or_direct(len);
3194 int32_t size=get_int_from_int_or_str();
3197 width=get_real_from_real_or_str();
3199 if (strmatch(dtype,
"REAL"))
3200 kernel=ui_kernel->create_gaussian(size, width);
3201 else if (strmatch(dtype,
"SPARSEREAL"))
3202 kernel=ui_kernel->create_sparsegaussian(size, width);
3206 else if (strmatch(type,
"GAUSSIANSHIFT"))
3211 char* dtype=get_str_from_str_or_direct(len);
3212 if (strmatch(dtype,
"REAL"))
3214 int32_t size=get_int_from_int_or_str();
3215 float64_t width=get_real_from_real_or_str();
3216 int32_t max_shift=get_int_from_int_or_str();
3217 int32_t shift_step=get_int_from_int_or_str();
3219 kernel=ui_kernel->create_gaussianshift(
3220 size, width, max_shift, shift_step);
3225 else if (strmatch(type,
"CUSTOM"))
3227 if (m_nrhs!=4 || !create_return_values(0))
3233 get_matrix(kmatrix, num_feat, num_vec);
3236 char* ktype=get_string(tlen);
3238 if (!strmatch(ktype,
"DIAG") &&
3239 !strmatch(ktype,
"FULL") &&
3240 !strmatch(ktype,
"FULL2DIAG"))
3243 SG_ERROR(
"Undefined type, not DIAG, FULL or FULL2DIAG.\n")
3246 bool source_is_diag=
false;
3247 bool dest_is_diag=
false;
3249 if (strmatch(ktype,
"FULL2DIAG"))
3251 else if (strmatch(ktype,
"DIAG"))
3253 source_is_diag=
true;
3257 kernel=ui_kernel->create_custom(kmatrix, num_feat, num_vec,
3258 source_is_diag, dest_is_diag);
3260 else if (strmatch(type,
"CONST"))
3265 char* dtype=get_str_from_str_or_direct(len);
3266 if (strmatch(dtype,
"REAL"))
3268 int32_t size=get_int_from_int_or_str();
3271 c=get_real_from_real_or_str();
3273 kernel=ui_kernel->create_const(size, c);
3278 else if (strmatch(type,
"DIAG"))
3283 char* dtype=get_str_from_str_or_direct(len);
3284 if (strmatch(dtype,
"REAL"))
3286 int32_t size=get_int_from_int_or_str();
3289 diag=get_real_from_real_or_str();
3291 kernel=ui_kernel->create_diag(size, diag);
3297 else if (strmatch(type,
"TPPK"))
3302 char* dtype=get_str_from_str_or_direct(len);
3303 if (strmatch(dtype,
"INT"))
3305 int32_t size=get_int_from_int_or_str();
3309 get_matrix(km, rows, cols);
3310 kernel=ui_kernel->create_tppk(size, km, rows, cols);
3319 SG_DEBUG(
"created kernel: %p\n", kernel)
3332 int32_t from_order=0;
3333 bool normalize=
true;
3335 int32_t feature_class_len=0;
3336 char* feature_class_str=get_string(feature_class_len);
3337 ASSERT(feature_class_str)
3339 if (strmatch(feature_class_str,
"WD"))
3342 SG_ERROR(
"Please specify alphabet, WD, order, from_order\n")
3346 from_order=get_int();
3349 else if (strmatch(feature_class_str,
"WSPEC"))
3352 SG_ERROR(
"Please specify alphabet, order, WSPEC, start, normalize\n")
3357 normalize=get_bool();
3365 SG_FREE(feature_class_str);
3380 int32_t feature_class_len=0;
3382 char* feature_class_str=get_string(feature_class_len);
3383 ASSERT(feature_class_str)
3384 if (strmatch(feature_class_str,
"POLY"))
3390 normalize = get_bool();
3395 SG_ERROR(
"Unknown feature class: %s\n", feature_class_str)
3397 SG_FREE(feature_class_str);
3403 bool CSGInterface::cmd_init_kernel()
3409 bool CSGInterface::cmd_clean_kernel()
3411 if (m_nrhs<1 || !create_return_values(0))
3414 return ui_kernel->clean_kernel();
3417 bool CSGInterface::cmd_save_kernel()
3419 if (m_nrhs<2 || !create_return_values(0))
3423 char* filename=get_str_from_str_or_direct(len);
3425 bool success=ui_kernel->save_kernel(filename);
3431 bool CSGInterface::cmd_get_kernel_matrix()
3433 if (m_nrhs>2 || !create_return_values(1))
3440 target=get_string(len);
3441 bool success=ui_kernel->init_kernel(target);
3445 CKernel* kernel=ui_kernel->get_kernel();
3447 SG_ERROR(
"No kernel defined or not initialized.\n")
3458 bool CSGInterface::cmd_set_WD_position_weights()
3460 if (m_nrhs<2 || m_nrhs>3 || !create_return_values(0))
3463 CKernel* kernel=ui_kernel->get_kernel();
3482 get_matrix(weights, dim, len);
3489 if (dim!=1 && len>0)
3490 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n")
3492 ui_kernel->init_kernel(
"TRAIN");
3505 target=get_string(tlen);
3509 SG_ERROR(
"Couldn't find second argument to method.\n")
3512 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
3515 SG_ERROR(
"Second argument none of TRAIN or TEST.\n")
3518 if (strmatch(target,
"TEST"))
3522 if (dim!=1 && len>0)
3525 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n")
3528 if (dim==0 && len==0)
3530 if (create_return_values(3))
3542 if (create_return_values(3))
3551 ui_kernel->init_kernel(
"TRAIN");
3563 bool CSGInterface::cmd_get_subkernel_weights()
3565 if (m_nrhs!=1 || !create_return_values(1))
3568 CKernel *kernel=ui_kernel->get_kernel();
3577 int32_t num_weights=-1;
3578 weights=((
CCombinedKernel *) kernel)->get_subkernel_weights(num_weights);
3581 set_matrix(weights, 1, num_weights);
3591 get_degree_weights(degree, length);
3596 get_degree_weights(degree, length);
3599 SG_ERROR(
"Setting subkernel weights not supported on this kernel.\n")
3604 set_matrix(weights, degree, length);
3608 bool CSGInterface::cmd_set_subkernel_weights()
3610 if (m_nrhs!=2 || !create_return_values(0))
3613 CKernel* kernel=ui_kernel->get_kernel();
3621 get_matrix(weights, dim, len);
3629 if (dim!=degree || len<1)
3630 SG_ERROR(
"WD: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree)
3642 if (dim!=degree || len<1)
3643 SG_ERROR(
"WDPos: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree)
3653 if (dim!=1 || len!=num_subkernels)
3654 SG_ERROR(
"All: Dimension mismatch (should be 1 x num_subkernels)\n")
3663 bool CSGInterface::cmd_set_subkernel_weights_combined()
3665 if (m_nrhs!=3 || !create_return_values(0))
3668 CKernel* kernel=ui_kernel->get_kernel();
3672 SG_ERROR(
"Only works for combined kernels.\n")
3678 get_matrix(weights, dim, len);
3680 int32_t idx=get_int();
3681 SG_DEBUG(
"using kernel_idx=%i\n", idx)
3685 SG_ERROR(
"No subkernel at idx %d.\n", idx)
3693 if (dim!=degree || len<1)
3694 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3706 if (dim!=degree || len<1)
3707 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3717 if (dim!=1 || len!=num_subkernels)
3718 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n")
3727 bool CSGInterface::cmd_get_dotfeature_weights_combined()
3729 if (m_nrhs!=2 || !create_return_values(1))
3733 char* target=get_string(tlen);
3736 if (strmatch(target,
"TRAIN"))
3737 features=ui_features->get_train_features();
3738 else if (strmatch(target,
"TEST"))
3739 features=ui_features->get_test_features();
3743 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
3750 SG_ERROR(
"Only works for combined dot features.\n")
3758 bool CSGInterface::cmd_set_dotfeature_weights_combined()
3760 if (m_nrhs!=3 || !create_return_values(0))
3764 char* target=get_string(tlen);
3767 if (strmatch(target,
"TRAIN"))
3768 features=ui_features->get_train_features();
3769 else if (strmatch(target,
"TEST"))
3770 features=ui_features->get_test_features();
3774 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n")
3781 SG_ERROR(
"Only works for combined dot features.\n")
3786 get_matrix(weights, dim, len);
3793 bool CSGInterface::cmd_set_last_subkernel_weights()
3795 if (m_nrhs!=2 || !create_return_values(0))
3798 CKernel* kernel=ui_kernel->get_kernel();
3802 SG_ERROR(
"Only works for Combined kernels.\n")
3812 get_matrix(weights, dim, len);
3819 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3831 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n")
3841 if (dim!=1 || len!=num_subkernels)
3842 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n")
3851 bool CSGInterface::cmd_get_WD_position_weights()
3853 if (m_nrhs!=1 || !create_return_values(1))
3856 CKernel* kernel=ui_kernel->get_kernel();
3864 SG_ERROR(
"Couldn't find last kernel.\n")
3868 SG_ERROR(
"Wrong subkernel type.\n")
3879 if (position_weights==NULL)
3880 set_vector(position_weights, 0);
3882 set_vector(position_weights, len);
3887 bool CSGInterface::cmd_get_last_subkernel_weights()
3889 if (m_nrhs!=1 || !create_return_values(1))
3892 CKernel* kernel=ui_kernel->get_kernel();
3897 SG_ERROR(
"Only works for Combined kernels.\n")
3901 SG_ERROR(
"Couldn't find last kernel.\n")
3908 int32_t num_weights=0;
3912 set_vector(weights, num_weights);
3919 get_degree_weights(degree, len);
3922 get_degree_weights(degree, len);
3924 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n")
3929 set_matrix(weights, degree, len);
3934 bool CSGInterface::cmd_compute_by_subkernels()
3936 if (m_nrhs!=1 || !create_return_values(1))
3939 CKernel* kernel=ui_kernel->get_kernel();
3956 SG_ERROR(
"Kernel optimization not initialized.\n")
3964 SG_ERROR(
"Kernel optimization not initialized.\n")
3967 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n")
3972 int32_t num_feat=degree*len;
3973 int32_t num=num_feat*num_vec;
3976 for (int32_t i=0; i<num; i++)
3982 for (int32_t i=0; i<num_vec; i++)
3989 for (int32_t i=0; i<num_vec; i++)
3993 set_matrix(result, num_feat, num_vec);
3999 bool CSGInterface::cmd_init_kernel_optimization()
4001 if (m_nrhs<1 || !create_return_values(0))
4004 return ui_kernel->init_kernel_optimization();
4007 bool CSGInterface::cmd_get_kernel_optimization()
4009 if (m_nrhs<1 || !create_return_values(1))
4012 CKernel* kernel=ui_kernel->get_kernel();
4023 int32_t max_order=get_int();
4024 if ((max_order<1) || (max_order>12))
4026 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order)
4031 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4036 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4041 for (int32_t i=0; i<num_suppvec; i++)
4048 num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4052 set_matrix(position_weights, num_sym, num_feat);
4053 SG_FREE(position_weights);
4066 set_vector(weights, len);
4084 bool CSGInterface::cmd_delete_kernel_optimization()
4086 if (m_nrhs<1 || !create_return_values(0))
4089 return ui_kernel->delete_kernel_optimization();
4092 bool CSGInterface::cmd_use_diagonal_speedup()
4094 if (m_nrhs<2 || !create_return_values(0))
4097 bool speedup=get_bool();
4099 CKernel* kernel=ui_kernel->get_kernel();
4105 SG_DEBUG(
"Identified combined kernel.\n")
4108 SG_ERROR(
"No last kernel defined.\n")
4112 SG_ERROR(
"Currently only commwordstring kernel supports diagonal speedup\n")
4116 SG_INFO(
"Diagonal speedup %s.\n", speedup ?
"enabled" :
"disabled")
4121 bool CSGInterface::cmd_set_kernel_optimization_type()
4123 if (m_nrhs<2 || !create_return_values(0))
4127 char* opt_type=get_str_from_str_or_direct(len);
4129 bool success=ui_kernel->set_optimization_type(opt_type);
4135 bool CSGInterface::cmd_set_solver()
4137 if (m_nrhs<2 || !create_return_values(0))
4141 char* solver=get_str_from_str_or_direct(len);
4143 bool success=ui_classifier->set_solver(solver);
4149 bool CSGInterface::cmd_set_constraint_generator()
4151 if (m_nrhs<2 || !create_return_values(0))
4155 char* cg=get_str_from_str_or_direct(len);
4157 bool success=ui_classifier->set_constraint_generator(cg);
4163 bool CSGInterface::cmd_set_prior_probs()
4165 if (m_nrhs<3 || !create_return_values(0))
4171 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n")
4173 float64_t pos_probs=get_real_from_real_or_str();
4174 float64_t neg_probs=get_real_from_real_or_str();
4181 bool CSGInterface::cmd_set_prior_probs_from_labels()
4183 if (m_nrhs<2 || !create_return_values(0))
4189 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n")
4193 get_vector(lab, len);
4196 for (int32_t i=0; i<len; i++)
4199 SG_ERROR(
"Couldn't set label %d (of %d): %f.\n", i, len, lab[i])
4214 bool CSGInterface::cmd_set_distance()
4216 if (m_nrhs<3 || !create_return_values(0))
4221 char* type=get_str_from_str_or_direct(len);
4222 char* dtype=get_str_from_str_or_direct(len);
4224 if (strmatch(type,
"MINKOWSKI") && m_nrhs==4)
4226 float64_t k=get_real_from_real_or_str();
4227 distance=ui_distance->create_minkowski(k);
4229 else if (strmatch(type,
"MANHATTAN"))
4231 if (strmatch(dtype,
"REAL"))
4232 distance=ui_distance->create_generic(
D_MANHATTAN);
4233 else if (strmatch(dtype,
"WORD"))
4236 else if (strmatch(type,
"HAMMING") && strmatch(dtype,
"WORD"))
4238 bool use_sign=
false;
4240 use_sign=get_bool_from_bool_or_str();
4242 distance=ui_distance->create_hammingword(use_sign);
4244 else if (strmatch(type,
"CANBERRA"))
4246 if (strmatch(dtype,
"REAL"))
4247 distance=ui_distance->create_generic(
D_CANBERRA);
4248 else if (strmatch(dtype,
"WORD"))
4251 else if (strmatch(type,
"CHEBYSHEW") && strmatch(dtype,
"REAL"))
4253 distance=ui_distance->create_generic(
D_CHEBYSHEW);
4255 else if (strmatch(type,
"GEODESIC") && strmatch(dtype,
"REAL"))
4257 distance=ui_distance->create_generic(
D_GEODESIC);
4259 else if (strmatch(type,
"JENSEN") && strmatch(dtype,
"REAL"))
4261 distance=ui_distance->create_generic(
D_JENSEN);
4263 else if (strmatch(type,
"CHISQUARE") && strmatch(dtype,
"REAL"))
4265 distance=ui_distance->create_generic(
D_CHISQUARE);
4267 else if (strmatch(type,
"TANIMOTO") && strmatch(dtype,
"REAL"))
4269 distance=ui_distance->create_generic(
D_TANIMOTO);
4271 else if (strmatch(type,
"COSINE") && strmatch(dtype,
"REAL"))
4273 distance=ui_distance->create_generic(
D_COSINE);
4275 else if (strmatch(type,
"BRAYCURTIS") && strmatch(dtype,
"REAL"))
4279 else if (strmatch(type,
"EUCLIDEAN"))
4281 if (strmatch(dtype,
"REAL"))
4282 distance=ui_distance->create_generic(
D_EUCLIDEAN);
4283 else if (strmatch(dtype,
"SPARSEREAL"))
4291 return ui_distance->set_distance(distance);
4294 bool CSGInterface::cmd_init_distance()
4300 bool CSGInterface::cmd_get_distance_matrix()
4302 if (m_nrhs!=2 || !create_return_values(1))
4306 char* target=get_string(len);
4308 bool success=ui_distance->init_distance(target);
4314 SG_ERROR(
"No distance defined or not initialized.\n")
4326 bool CSGInterface::cmd_get_SPEC_consensus()
4328 if (m_nrhs!=1 || !create_return_values(1))
4331 CKernel* kernel=ui_kernel->get_kernel();
4335 SG_ERROR(
"Only works for CommWordString kernels.\n")
4337 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4340 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4344 for (int32_t i=0; i<num_suppvec; i++)
4351 num_feat, num_suppvec, sv_idx, sv_weight);
4355 set_vector(consensus, num_feat);
4361 bool CSGInterface::cmd_get_SPEC_scoring()
4363 if (m_nrhs!=2 || !create_return_values(1))
4366 int32_t max_order=get_int();
4367 CKernel* kernel=ui_kernel->get_kernel();
4373 SG_ERROR(
"Only works for (Weighted) CommWordString kernels.\n")
4375 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4378 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4383 for (int32_t i=0; i<num_suppvec; i++)
4389 if ((max_order<1) || (max_order>8))
4391 SG_WARNING(
"max_order out of range 1..8 (%d). setting to 1\n", max_order)
4398 max_order, num_feat, num_sym, NULL,
4399 num_suppvec, sv_idx, sv_weight);
4402 max_order, num_feat, num_sym, NULL,
4403 num_suppvec, sv_idx, sv_weight);
4407 set_matrix(position_weights, num_sym, num_feat);
4408 SG_FREE(position_weights);
4413 bool CSGInterface::cmd_get_WD_consensus()
4415 if (m_nrhs!=1 || !create_return_values(1))
4418 CKernel* kernel=ui_kernel->get_kernel();
4422 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4424 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4427 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4431 for (int32_t i=0; i<num_suppvec; i++)
4438 num_feat, num_suppvec, sv_idx, sv_weight);
4442 set_vector(consensus, num_feat);
4448 bool CSGInterface::cmd_compute_POIM_WD()
4450 if (m_nrhs!=3 || !create_return_values(1))
4453 int32_t max_order=get_int();
4455 int32_t num_dfeat=0;
4457 get_matrix(distribution, num_dfeat, num_dvec);
4462 CKernel* kernel=ui_kernel->get_kernel();
4466 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4476 if (num_dvec!=seqlen || num_dfeat!=num_sym)
4478 SG_ERROR(
"distribution should have (seqlen x num_sym) elements" 4479 "(seqlen: %d vs. %d symbols: %d vs. %d)\n", seqlen,
4480 num_dvec, num_sym, num_dfeat);
4483 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4486 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4489 for (int32_t i=0; i<num_suppvec; i++)
4505 max_order, seqlen, num_sym, NULL,
4506 num_suppvec, sv_idx, sv_weight, distribution);
4510 set_matrix(position_weights, num_sym, seqlen);
4511 SG_FREE(position_weights);
4516 bool CSGInterface::cmd_get_WD_scoring()
4518 if (m_nrhs!=2 || !create_return_values(1))
4521 int32_t max_order=get_int();
4523 CKernel* kernel=ui_kernel->get_kernel();
4527 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n")
4529 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4532 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
4537 for (int32_t i=0; i<num_suppvec; i++)
4543 if ((max_order<1) || (max_order>12))
4545 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order)
4551 max_order, num_feat, num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4555 set_matrix(position_weights, num_sym, num_feat);
4556 SG_FREE(position_weights);
4564 bool CSGInterface::cmd_classify()
4566 if (m_nrhs!=1 || !create_return_values(1))
4569 if (!ui_kernel->get_kernel() ||
4570 ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
4572 CFeatures* feat=ui_features->get_test_features();
4577 CLabels* labels=ui_classifier->classify();
4583 for (int32_t i=0; i<num_vec; i++)
4605 set_vector(result, num_vec);
4611 bool CSGInterface::cmd_classify_example()
4613 if (m_nrhs!=2 || !create_return_values(1))
4616 int32_t idx=get_int();
4619 if (!ui_classifier->classify_example(idx, result))
4620 SG_ERROR(
"Classify_example failed.\n")
4627 bool CSGInterface::cmd_get_classifier()
4629 if (m_nrhs<1 || m_nrhs>2 || !create_return_values(2))
4643 if (!ui_classifier->get_trained_classifier(
4644 weights, rows, cols, bias, brows, bcols, idx))
4649 set_matrix(bias, brows, bcols);
4654 set_matrix(weights, rows, cols);
4660 bool CSGInterface::cmd_new_classifier()
4662 if (m_nrhs<2 || !create_return_values(0))
4666 char* name=get_str_from_str_or_direct(len);
4672 d=get_int_from_int_or_str();
4675 from_d=get_int_from_int_or_str();
4678 bool success=ui_classifier->new_classifier(name, d, from_d);
4684 bool CSGInterface::cmd_save_classifier()
4686 if (m_nrhs<2 || !create_return_values(0))
4690 char* filename=get_str_from_str_or_direct(len);
4692 bool success=ui_classifier->save(filename);
4698 bool CSGInterface::cmd_load_classifier()
4700 if (m_nrhs<3 || !create_return_values(0))
4704 char* filename=get_str_from_str_or_direct(len);
4705 char* type=get_str_from_str_or_direct(len);
4707 bool success=ui_classifier->load(filename, type);
4709 if (dynamic_cast<CKernelMachine*>(ui_classifier->get_classifier()))
4722 bool CSGInterface::cmd_get_num_svms()
4724 if (m_nrhs!=1 || !create_return_values(1))
4727 set_int(ui_classifier->get_num_svms());
4733 bool CSGInterface::cmd_get_svm()
4735 return cmd_get_classifier();
4738 bool CSGInterface::cmd_set_svm()
4740 if (m_nrhs!=3 || !create_return_values(0))
4746 int32_t num_feat_alphas=0;
4747 int32_t num_vec_alphas=0;
4748 get_matrix(alphas, num_feat_alphas, num_vec_alphas);
4751 SG_ERROR(
"No proper alphas given.\n")
4752 if (num_vec_alphas!=2)
4753 SG_ERROR(
"Not 2 vectors in alphas.\n")
4755 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4757 SG_ERROR(
"No SVM object available.\n")
4763 for (int32_t i=0; i<num_support_vectors; i++)
4773 bool CSGInterface::cmd_set_linear_classifier()
4775 if (m_nrhs!=3 || !create_return_values(0))
4785 SG_ERROR(
"No proper weight vector given.\n")
4789 SG_ERROR(
"No Linear Classifier object available.\n")
4796 bool CSGInterface::cmd_get_svm_objective()
4798 if (m_nrhs!=1 || !create_return_values(1))
4801 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4810 bool CSGInterface::cmd_compute_svm_primal_objective()
4812 return do_compute_objective(SVM_PRIMAL);
4815 bool CSGInterface::cmd_compute_svm_dual_objective()
4817 return do_compute_objective(SVM_DUAL);
4820 bool CSGInterface::cmd_compute_mkl_dual_objective()
4822 return do_compute_objective(MKL_DUAL);
4825 bool CSGInterface::cmd_compute_relative_mkl_duality_gap()
4827 return do_compute_objective(MKL_RELATIVE_DUALITY_GAP);
4830 bool CSGInterface::cmd_compute_absolute_mkl_duality_gap()
4832 return do_compute_objective(MKL_ABSOLUTE_DUALITY_GAP);
4835 bool CSGInterface::do_compute_objective(E_WHICH_OBJ obj)
4837 if (m_nrhs!=1 || !create_return_values(1))
4842 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4847 trainlabels=ui_labels->get_train_labels();
4850 SG_ERROR(
"No trainlabels available.\n")
4852 CKernel* kernel=ui_kernel->get_kernel();
4856 if (!ui_kernel->is_initialized() || !kernel->
has_features())
4857 SG_ERROR(
"Kernel not initialized.\n")
4873 result=((
CMKL*) svm)->compute_mkl_primal_objective();
4877 result=((
CMKL*) svm)->compute_mkl_dual_objective();
4879 case MKL_RELATIVE_DUALITY_GAP:
4882 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4883 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4884 result=(primal-dual)/dual;
4887 case MKL_ABSOLUTE_DUALITY_GAP:
4890 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4891 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4896 SG_SERROR(
"Error calling do_compute_objective\n")
4904 bool CSGInterface::cmd_train_classifier()
4906 if (m_nrhs<1 || !create_return_values(0))
4909 CMachine* classifier=ui_classifier->get_classifier();
4911 SG_ERROR(
"No classifier available.\n")
4931 return ui_classifier->train_svm();
4933 return ui_classifier->train_mkl_multiclass();
4937 return ui_classifier->train_mkl();
4940 return ui_classifier->train_krr();
4947 int32_t k=get_int_from_int_or_str();
4949 return ui_classifier->train_knn(k);
4957 int32_t k=get_int_from_int_or_str();
4958 int32_t max_iter=get_int_from_int_or_str();
4960 return ui_classifier->train_clustering(k, max_iter);
4968 int32_t merges=get_int_from_int_or_str();
4970 return ui_classifier->train_clustering(merges);
4977 gamma=get_real_from_real_or_str();
4979 return ui_classifier->train_linear(gamma);
4990 return ui_classifier->train_linear();
4993 return ui_classifier->train_wdocas();
4996 SG_ERROR(
"Unknown classifier type %d.\n", type)
5002 bool CSGInterface::cmd_do_auc_maximization()
5004 if (m_nrhs!=2 || !create_return_values(0))
5007 bool do_auc=get_bool_from_bool_or_str();
5009 return ui_classifier->set_do_auc_maximization(do_auc);
5012 bool CSGInterface::cmd_set_perceptron_parameters()
5014 if (m_nrhs!=3 || !create_return_values(0))
5017 float64_t lernrate=get_real_from_real_or_str();
5018 int32_t maxiter=get_int_from_int_or_str();
5020 return ui_classifier->set_perceptron_parameters(lernrate, maxiter);
5023 bool CSGInterface::cmd_set_svm_qpsize()
5025 if (m_nrhs!=2 || !create_return_values(0))
5028 int32_t qpsize=get_int_from_int_or_str();
5030 return ui_classifier->set_svm_qpsize(qpsize);
5033 bool CSGInterface::cmd_set_svm_max_qpsize()
5035 if (m_nrhs!=2 || !create_return_values(0))
5038 int32_t max_qpsize=get_int_from_int_or_str();
5040 return ui_classifier->set_svm_max_qpsize(max_qpsize);
5043 bool CSGInterface::cmd_set_svm_bufsize()
5045 if (m_nrhs!=2 || !create_return_values(0))
5048 int32_t bufsize=get_int_from_int_or_str();
5050 return ui_classifier->set_svm_bufsize(bufsize);
5053 bool CSGInterface::cmd_set_svm_C()
5055 if (m_nrhs<2 || !create_return_values(0))
5058 float64_t C1=get_real_from_real_or_str();
5062 C2=get_real_from_real_or_str();
5064 return ui_classifier->set_svm_C(C1, C2);
5067 bool CSGInterface::cmd_set_svm_epsilon()
5069 if (m_nrhs!=2 || !create_return_values(0))
5074 return ui_classifier->set_svm_epsilon(epsilon);
5077 bool CSGInterface::cmd_set_svr_tube_epsilon()
5079 if (m_nrhs!=2 || !create_return_values(0))
5082 float64_t tube_epsilon=get_real_from_real_or_str();
5084 return ui_classifier->set_svr_tube_epsilon(tube_epsilon);
5087 bool CSGInterface::cmd_set_svm_nu()
5089 if (m_nrhs!=2 || !create_return_values(0))
5092 float64_t nu=get_real_from_real_or_str();
5094 return ui_classifier->set_svm_nu(nu);
5097 bool CSGInterface::cmd_set_svm_mkl_parameters()
5099 if (m_nrhs<3 || m_nrhs>4 || !create_return_values(0))
5102 float64_t weight_epsilon=get_real_from_real_or_str();
5103 float64_t C_mkl=get_real_from_real_or_str();
5107 mkl_norm=get_real_from_real_or_str();
5109 return ui_classifier->set_svm_mkl_parameters(weight_epsilon, C_mkl, mkl_norm);
5112 bool CSGInterface::cmd_set_elasticnet_lambda()
5114 if (m_nrhs!=2 || !create_return_values(0))
5116 float64_t lambda=get_real_from_real_or_str();
5117 return ui_classifier->set_elasticnet_lambda(lambda);
5120 bool CSGInterface::cmd_set_mkl_block_norm()
5122 if (m_nrhs!=2 || !create_return_values(0))
5124 float64_t bnorm=get_real_from_real_or_str();
5125 return ui_classifier->set_mkl_block_norm(bnorm);
5129 bool CSGInterface::cmd_set_max_train_time()
5131 if (m_nrhs!=2 || !create_return_values(0))
5134 float64_t max_train_time=get_real_from_real_or_str();
5136 return ui_classifier->set_max_train_time(max_train_time);
5139 bool CSGInterface::cmd_set_svm_shrinking_enabled()
5141 if (m_nrhs!=2 || !create_return_values(0))
5144 bool shrinking_enabled=get_bool_from_bool_or_str();
5146 return ui_classifier->set_svm_shrinking_enabled(shrinking_enabled);
5149 bool CSGInterface::cmd_set_svm_batch_computation_enabled()
5151 if (m_nrhs!=2 || !create_return_values(0))
5154 bool batch_computation_enabled=get_bool_from_bool_or_str();
5156 return ui_classifier->set_svm_batch_computation_enabled(
5157 batch_computation_enabled);
5160 bool CSGInterface::cmd_set_svm_linadd_enabled()
5162 if (m_nrhs!=2 || !create_return_values(0))
5165 bool linadd_enabled=get_bool_from_bool_or_str();
5167 return ui_classifier->set_svm_linadd_enabled(linadd_enabled);
5170 bool CSGInterface::cmd_set_svm_bias_enabled()
5172 if (m_nrhs!=2 || !create_return_values(0))
5175 bool bias_enabled=get_bool_from_bool_or_str();
5177 return ui_classifier->set_svm_bias_enabled(bias_enabled);
5180 bool CSGInterface::cmd_set_mkl_interleaved_enabled()
5182 if (m_nrhs!=2 || !create_return_values(0))
5185 bool interleaved_enabled=get_bool_from_bool_or_str();
5187 return ui_classifier->set_mkl_interleaved_enabled(interleaved_enabled);
5190 bool CSGInterface::cmd_set_krr_tau()
5192 if (m_nrhs!=2 || !create_return_values(0))
5195 float64_t tau=get_real_from_real_or_str();
5197 return ui_classifier->set_krr_tau(tau);
5203 bool CSGInterface::cmd_add_preproc()
5205 if (m_nrhs<2 || !create_return_values(0))
5209 char* type=get_str_from_str_or_direct(len);
5212 if (strmatch(type,
"NORMONE"))
5213 preproc=ui_preproc->create_generic(
P_NORMONE);
5214 else if (strmatch(type,
"LOGPLUSONE"))
5216 else if (strmatch(type,
"SORTWORDSTRING"))
5218 else if (strmatch(type,
"SORTULONGSTRING"))
5220 else if (strmatch(type,
"DECOMPRESSCHARSTRING"))
5222 else if (strmatch(type,
"SORTWORD"))
5223 preproc=ui_preproc->create_generic(
P_SORTWORD);
5225 else if (strmatch(type,
"PRUNEVARSUBMEAN"))
5227 bool divide_by_std=
false;
5229 divide_by_std=get_bool_from_bool_or_str();
5231 preproc=ui_preproc->create_prunevarsubmean(divide_by_std);
5235 else if (strmatch(type,
"PCA") && m_nrhs==4)
5237 bool do_whitening=get_bool_from_bool_or_str();
5238 float64_t threshold=get_real_from_real_or_str();
5240 preproc=ui_preproc->create_pca(do_whitening, threshold);
5248 return ui_preproc->add_preproc(preproc);
5251 bool CSGInterface::cmd_del_preproc()
5253 if (m_nrhs!=1 || !create_return_values(0))
5256 return ui_preproc->del_preproc();
5259 bool CSGInterface::cmd_attach_preproc()
5261 if (m_nrhs<2 || !create_return_values(0))
5265 char* target=get_str_from_str_or_direct(len);
5267 bool do_force=
false;
5269 do_force=get_bool_from_bool_or_str();
5271 bool success=ui_preproc->attach_preproc(target, do_force);
5277 bool CSGInterface::cmd_clean_preproc()
5279 if (m_nrhs!=1 || !create_return_values(0))
5282 return ui_preproc->clean_preproc();
5287 bool CSGInterface::cmd_set_converter()
5290 char* type=get_str_from_str_or_direct(len);
5292 if (strmatch(type,
"lle"))
5294 int32_t k = get_int_from_int_or_str();
5295 ui_converter->create_locallylinearembedding(k);
5298 if (strmatch(type,
"npe"))
5300 int32_t k = get_int_from_int_or_str();
5301 ui_converter->create_neighborhoodpreservingembedding(k);
5304 if (strmatch(type,
"ltsa"))
5306 int32_t k = get_int_from_int_or_str();
5307 ui_converter->create_localtangentspacealignment(k);
5310 if (strmatch(type,
"lltsa"))
5312 int32_t k = get_int_from_int_or_str();
5313 ui_converter->create_linearlocaltangentspacealignment(k);
5316 if (strmatch(type,
"hlle"))
5318 int32_t k = get_int_from_int_or_str();
5319 ui_converter->create_hessianlocallylinearembedding(k);
5322 if (strmatch(type,
"laplacian_eigenmaps"))
5324 int32_t k = get_int_from_int_or_str();
5325 int32_t width = get_real_from_real_or_str();
5326 ui_converter->create_laplacianeigenmaps(k,width);
5329 if (strmatch(type,
"lpp"))
5331 int32_t k = get_int_from_int_or_str();
5332 int32_t width = get_real_from_real_or_str();
5333 ui_converter->create_localitypreservingprojections(k,width);
5336 if (strmatch(type,
"diffusion_maps"))
5338 int32_t t = get_int_from_int_or_str();
5339 int32_t width = get_real_from_real_or_str();
5340 ui_converter->create_diffusionmaps(t,width);
5343 if (strmatch(type,
"isomap"))
5345 int32_t k = get_int_from_int_or_str();
5346 ui_converter->create_isomap(k);
5349 if (strmatch(type,
"mds"))
5351 ui_converter->create_multidimensionalscaling();
5354 if (strmatch(type,
"jade"))
5356 ui_converter->create_jade();
5362 bool CSGInterface::cmd_apply_converter()
5364 if (m_nrhs!=1 || !create_return_values(1))
5373 bool CSGInterface::cmd_embed()
5375 int32_t target_dim = get_int_from_int_or_str();
5377 if (m_nrhs!=1 || !create_return_values(1))
5388 bool CSGInterface::cmd_new_plugin_estimator()
5390 if (m_nrhs<2 || !create_return_values(0))
5393 float64_t pos_pseudo=get_real_from_real_or_str();
5394 float64_t neg_pseudo=get_real_from_real_or_str();
5396 return ui_pluginestimate->new_estimator(pos_pseudo, neg_pseudo);
5399 bool CSGInterface::cmd_train_estimator()
5401 if (m_nrhs!=1 || !create_return_values(0))
5404 return ui_pluginestimate->train();
5407 bool CSGInterface::cmd_plugin_estimate_classify_example()
5409 if (m_nrhs!=2 || !create_return_values(1))
5412 int32_t idx=get_int();
5413 float64_t result=ui_pluginestimate->apply_one(idx);
5415 set_vector(&result, 1);
5419 bool CSGInterface::cmd_plugin_estimate_classify()
5421 if (m_nrhs!=1 || !create_return_values(1))
5424 CFeatures* feat=ui_features->get_test_features();
5430 CLabels* labels=ui_pluginestimate->apply();
5431 for (int32_t i=0; i<num_vec; i++)
5435 set_vector(result, num_vec);
5441 bool CSGInterface::cmd_set_plugin_estimate()
5443 if (m_nrhs!=3 || !create_return_values(0))
5447 int32_t num_probs=0;
5449 get_matrix(emission_probs, num_probs, num_vec);
5452 SG_ERROR(
"Need at least 1 set of positive and 1 set of negative params.\n")
5455 float64_t* neg_params=&(emission_probs[num_probs]);
5459 get_vector(model_sizes, len);
5461 int32_t seq_length=(int32_t) model_sizes[0];
5462 int32_t num_symbols=(int32_t) model_sizes[1];
5463 if (num_probs!=seq_length*num_symbols)
5464 SG_ERROR(
"Mismatch in number of emission probs and sequence length * number of symbols.\n")
5466 ui_pluginestimate->get_estimator()->set_model_params(
5467 pos_params, neg_params, seq_length, num_symbols);
5472 bool CSGInterface::cmd_get_plugin_estimate()
5474 if (m_nrhs!=1 || !create_return_values(2))
5479 int32_t num_params=0;
5480 int32_t seq_length=0;
5481 int32_t num_symbols=0;
5483 if (!ui_pluginestimate->get_estimator()->get_model_params(
5484 pos_params, neg_params, seq_length, num_symbols))
5487 num_params=seq_length*num_symbols;
5490 for (int32_t i=0; i<num_params; i++)
5491 result[i]=pos_params[i];
5492 for (int32_t i=0; i<num_params; i++)
5493 result[i+num_params]=neg_params[i];
5495 set_matrix(result, num_params, 2);
5501 set_vector(model_sizes, 2);
5506 bool CSGInterface::cmd_convergence_criteria()
5508 if (m_nrhs<3 || !create_return_values(0))
5511 int32_t num_iterations=get_int_from_int_or_str();
5514 return ui_hmm->convergence_criteria(num_iterations, epsilon);
5517 bool CSGInterface::cmd_normalize()
5519 if (m_nrhs<2 || !create_return_values(0))
5522 bool keep_dead_states=get_bool_from_bool_or_str();
5524 return ui_hmm->normalize(keep_dead_states);
5527 bool CSGInterface::cmd_add_states()
5529 if (m_nrhs<3 || !create_return_values(0))
5532 int32_t num_states=get_int_from_int_or_str();
5533 float64_t value=get_real_from_real_or_str();
5535 return ui_hmm->add_states(num_states, value);
5538 bool CSGInterface::cmd_permutation_entropy()
5540 if (m_nrhs<3 || !create_return_values(0))
5543 int32_t width=get_int_from_int_or_str();
5544 int32_t seq_num=get_int_from_int_or_str();
5546 return ui_hmm->permutation_entropy(width, seq_num);
5549 bool CSGInterface::cmd_relative_entropy()
5551 if (m_nrhs!=1 || !create_return_values(1))
5556 bool success=ui_hmm->relative_entropy(entropy, len);
5560 set_vector(entropy, len);
5566 bool CSGInterface::cmd_entropy()
5568 if (m_nrhs!=1 || !create_return_values(1))
5573 bool success=ui_hmm->entropy(entropy, len);
5577 set_vector(entropy, len);
5583 bool CSGInterface::cmd_hmm_classify()
5585 return do_hmm_classify(
false,
false);
5588 bool CSGInterface::cmd_one_class_hmm_classify()
5590 return do_hmm_classify(
false,
true);
5593 bool CSGInterface::cmd_one_class_linear_hmm_classify()
5595 return do_hmm_classify(
true,
true);
5598 bool CSGInterface::do_hmm_classify(
bool linear,
bool one_class)
5600 if (m_nrhs>1 || !create_return_values(1))
5603 CFeatures* feat=ui_features->get_test_features();
5612 labels=ui_hmm->linear_one_class_classify();
5617 labels=ui_hmm->one_class_classify();
5619 labels=ui_hmm->classify();
5625 for (int32_t i=0; i<num_vec; i++)
5629 set_vector(result, num_vec);
5635 bool CSGInterface::cmd_one_class_hmm_classify_example()
5637 return do_hmm_classify_example(
true);
5640 bool CSGInterface::cmd_hmm_classify_example()
5642 return do_hmm_classify_example(
false);
5645 bool CSGInterface::do_hmm_classify_example(
bool one_class)
5647 if (m_nrhs!=2 || !create_return_values(1))
5650 int32_t idx=get_int();
5654 result=ui_hmm->one_class_classify_example(idx);
5656 result=ui_hmm->classify_example(idx);
5663 bool CSGInterface::cmd_output_hmm()
5665 if (m_nrhs!=1 || !create_return_values(0))
5668 return ui_hmm->output_hmm();
5671 bool CSGInterface::cmd_output_hmm_defined()
5673 if (m_nrhs!=1 || !create_return_values(0))
5676 return ui_hmm->output_hmm_defined();
5679 bool CSGInterface::cmd_hmm_likelihood()
5681 if (m_nrhs!=1 || !create_return_values(1))
5684 CHMM* h=ui_hmm->get_current();
5689 set_real(likelihood);
5694 bool CSGInterface::cmd_likelihood()
5696 if (m_nrhs!=1 || !create_return_values(0))
5699 return ui_hmm->likelihood();
5702 bool CSGInterface::cmd_save_likelihood()
5704 if (m_nrhs<2 || !create_return_values(0))
5708 char* filename=get_str_from_str_or_direct(len);
5710 bool is_binary=
false;
5712 is_binary=get_bool_from_bool_or_str();
5714 bool success=ui_hmm->save_likelihood(filename, is_binary);
5720 bool CSGInterface::cmd_get_viterbi_path()
5722 if (m_nrhs!=2 || !create_return_values(2))
5725 int32_t dim=get_int();
5728 CHMM* h=ui_hmm->get_current();
5732 CFeatures* feat=ui_features->get_test_features();
5742 if (!vec || num_feat<=0)
5749 SG_DEBUG(
"computing viterbi path for vector %d (length %d)\n", dim, num_feat)
5753 set_vector(path, num_feat);
5755 set_real(likelihood);
5760 bool CSGInterface::cmd_viterbi_train()
5762 if (m_nrhs!=1 || !create_return_values(0))
5765 return ui_hmm->viterbi_train();
5768 bool CSGInterface::cmd_viterbi_train_defined()
5770 if (m_nrhs!=1 || !create_return_values(0))
5773 return ui_hmm->viterbi_train_defined();
5776 bool CSGInterface::cmd_baum_welch_train()
5778 if (m_nrhs!=1 || !create_return_values(0))
5781 return ui_hmm->baum_welch_train();
5784 bool CSGInterface::cmd_baum_welch_train_defined()
5786 if (m_nrhs!=1 || !create_return_values(0))
5789 return ui_hmm->baum_welch_train_defined();
5793 bool CSGInterface::cmd_baum_welch_trans_train()
5795 if (m_nrhs!=1 || !create_return_values(0))
5798 return ui_hmm->baum_welch_trans_train();
5801 bool CSGInterface::cmd_linear_train()
5803 if (m_nrhs<1 || !create_return_values(0))
5809 char* align=get_str_from_str_or_direct(len);
5811 bool success=ui_hmm->linear_train(align[0]);
5817 return ui_hmm->linear_train();
5820 bool CSGInterface::cmd_save_path()
5822 if (m_nrhs<2 || !create_return_values(0))
5826 char* filename=get_str_from_str_or_direct(len);
5828 bool is_binary=
false;
5830 is_binary=get_bool_from_bool_or_str();
5832 bool success=ui_hmm->save_path(filename, is_binary);
5838 bool CSGInterface::cmd_append_hmm()
5840 if (m_nrhs!=5 || !create_return_values(0))
5843 CHMM* old_h=ui_hmm->get_current();
5858 get_matrix(a, M_a, N_a);
5864 get_matrix(b, M_b, N_b);
5867 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
5869 SG_ERROR(
"Model matrices not matching in size.\n" 5870 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
5871 N_p, N_q, N_a, M_a, N_b, M_b);
5874 CHMM* h=
new CHMM(N, M, NULL, ui_hmm->get_pseudo());
5885 h->
set_a(i,j, a[i+j*N]);
5889 h->
set_b(i,j, b[i+j*N]);
5897 bool CSGInterface::cmd_append_model()
5899 if (m_nrhs<2 || !create_return_values(0))
5901 if (m_nrhs>2 && m_nrhs!=4)
5905 char* filename=get_str_from_str_or_direct(len);
5910 base1=get_int_from_int_or_str();
5911 base2=get_int_from_int_or_str();
5914 bool success=ui_hmm->append_model(filename, base1, base2);
5920 bool CSGInterface::cmd_new_hmm()
5922 if (m_nrhs!=3 || !create_return_values(0))
5925 int32_t n=get_int_from_int_or_str();
5926 int32_t m=get_int_from_int_or_str();
5928 return ui_hmm->new_hmm(n, m);
5931 bool CSGInterface::cmd_load_hmm()
5933 if (m_nrhs!=2 || !create_return_values(0))
5937 char* filename=get_str_from_str_or_direct(len);
5939 bool success=ui_hmm->load(filename);
5945 bool CSGInterface::cmd_save_hmm()
5947 if (m_nrhs<2 || !create_return_values(0))
5951 char* filename=get_str_from_str_or_direct(len);
5953 bool is_binary=
false;
5955 is_binary=get_bool_from_bool_or_str();
5957 bool success=ui_hmm->save(filename, is_binary);
5963 bool CSGInterface::cmd_set_hmm()
5965 if (m_nrhs!=5 || !create_return_values(0))
5979 get_matrix(a, M_a, N_a);
5985 get_matrix(b, M_b, N_b);
5988 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
5990 SG_ERROR(
"Model matrices not matching in size.\n" 5991 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
5992 N_p, N_q, N_a, M_a, N_b, M_b);
5995 CHMM* current=ui_hmm->get_current();
5997 SG_ERROR(
"Need a previously created HMM.\n")
6003 current->
set_p(i, p[i]);
6004 current->
set_q(i, q[i]);
6009 current->
set_a(i,j, a[i+j*N]);
6013 current->
set_b(i,j, b[i+j*N]);
6021 bool CSGInterface::cmd_set_hmm_as()
6023 if (m_nrhs!=2 || !create_return_values(0))
6027 char* target=get_str_from_str_or_direct(len);
6029 bool success=ui_hmm->set_hmm_as(target);
6035 bool CSGInterface::cmd_set_chop()
6037 if (m_nrhs!=2 || !create_return_values(0))
6040 float64_t value=get_real_from_real_or_str();
6041 return ui_hmm->chop(value);
6044 bool CSGInterface::cmd_set_pseudo()
6046 if (m_nrhs!=2 || !create_return_values(0))
6049 float64_t value=get_real_from_real_or_str();
6050 return ui_hmm->set_pseudo(value);
6053 bool CSGInterface::cmd_load_definitions()
6055 if (m_nrhs<2 || !create_return_values(0))
6059 char* filename=get_str_from_str_or_direct(len);
6063 do_init=get_bool_from_bool_or_str();
6065 bool success=ui_hmm->load_definitions(filename, do_init);
6071 bool CSGInterface::cmd_get_hmm()
6073 if (m_nrhs!=1 || !create_return_values(4))
6076 CHMM* h=ui_hmm->get_current();
6080 int32_t N=h->
get_N();
6081 int32_t M=h->
get_M();
6101 a[i+j*N]=h->
get_a(i, j);
6102 set_matrix(a, N, N);
6108 b[i+j*N]=h->
get_b(i, j);
6109 set_matrix(b, N, M);
6115 bool CSGInterface::cmd_best_path()
6117 if (m_nrhs!=3 || !create_return_values(0))
6120 int32_t from=get_int_from_int_or_str();
6121 int32_t to=get_int_from_int_or_str();
6123 return ui_hmm->best_path(from, to);
6126 bool CSGInterface::cmd_best_path_2struct()
6128 if (m_nrhs!=12 || !create_return_values(3))
6131 SG_ERROR(
"Sorry, this parameter list is awful!\n")
6136 void CSGInterface::get_vector(
bool*& vector, int32_t& len)
6138 int32_t* int_vector;
6139 get_vector(int_vector, len);
6142 vector= SG_MALLOC(
bool, len);
6144 for (int32_t i=0; i<len; i++)
6145 vector[i]= (int_vector[i]!=0);
6147 SG_FREE(int_vector);
6150 void CSGInterface::set_vector(
const bool* vector, int32_t len)
6152 int32_t* int_vector = SG_MALLOC(int32_t, len);
6153 for (int32_t i=0;i<len;i++)
6160 set_vector(int_vector,len);
6161 SG_FREE(int_vector);
6164 bool CSGInterface::cmd_set_plif_struct()
6169 get_vector(ids,Nid);
6175 get_string_list(names, Nname,Mname);
6181 get_matrix(all_limits, Mlimits, Nlimits);
6184 int32_t Npenalties=0;
6185 int32_t Mpenalties=0;
6187 get_matrix(all_penalties, Mpenalties, Npenalties);
6190 int32_t Ntransform=0;
6191 int32_t Mtransform=0;
6193 get_string_list(all_transform, Ntransform, Mtransform);
6198 get_vector(min_values,Nmin);
6203 get_vector(max_values,Nmax);
6207 bool* all_use_cache;
6208 get_vector(all_use_cache,Ncache);
6212 int32_t* all_use_svm;
6213 get_vector(all_use_svm,Nsvm);
6218 get_vector(all_do_calc,Ncalc);
6221 SG_ERROR(
"Ncalc!=Nsvm, Ncalc:%i, Nsvm:%i\n",Ncalc,Nsvm)
6223 SG_ERROR(
"Ncalc!=Ncache, Ncalc:%i, Ncache:%i\n",Ncalc,Ncache)
6224 if (Ncalc!=Ntransform)
6225 SG_ERROR(
"Ncalc!=Ntransform, Ncalc:%i, Ntransform:%i\n",Ncalc,Ntransform)
6227 SG_ERROR(
"Ncalc!=Nmin, Ncalc:%i, Nmin:%i\n",Ncalc,Nmin)
6229 SG_ERROR(
"Ncalc!=Nmax, Ncalc:%i, Nmax:%i\n",Ncalc,Nmax)
6230 if (Ncalc!=Npenalties)
6231 SG_ERROR(
"Ncalc!=Npenalties, Ncalc:%i, Npenalties:%i\n",Ncalc,Npenalties)
6233 SG_ERROR(
"Ncalc!=Nlimits, Ncalc:%i, Nlimits:%i\n",Ncalc,Nlimits)
6235 SG_ERROR(
"Ncalc!=Nname, Ncalc:%i, Nname:%i\n",Ncalc,Nname)
6237 SG_ERROR(
"Ncalc!=Nid, Ncalc:%i, Nid:%i\n",Ncalc,Nid)
6238 if (Mlimits!=Mpenalties)
6239 SG_ERROR(
"Mlimits!=Mpenalties, Mlimits:%i, Mpenalties:%i\n",Mlimits,Mpenalties)
6242 int32_t M = Mlimits;
6256 SG_FREE(all_transform);
6257 SG_FREE(all_do_calc);
6262 bool CSGInterface::cmd_get_plif_struct()
6270 int32_t* ids = SG_MALLOC(int32_t, N);
6277 bool* all_use_cache = SG_MALLOC(
bool, N);
6278 int32_t* all_use_svm = SG_MALLOC(int32_t, N);
6279 bool* all_do_calc = SG_MALLOC(
bool, N);
6280 for (int32_t i=0;i<N;i++)
6284 names[i].
slen = strlen(PEN[i]->get_plif_name());
6287 for (int32_t j=0;j<M;j++)
6289 all_limits[i*M+j]=limits[j];
6290 all_penalties[i*M+j]=penalties[j];
6292 all_transform[i].
string = (
char*) PEN[i]->get_transform_type();
6293 all_transform[i].
slen = strlen(PEN[i]->get_transform_type());
6302 set_string_list(names, N);
6303 set_matrix(all_limits, M, N);
6304 set_matrix(all_penalties, M, N);
6305 set_string_list(all_transform, N);
6306 set_vector(min_values,N);
6307 set_vector(max_values,N);
6308 set_vector(all_use_cache,N);
6309 set_vector(all_use_svm,N);
6310 set_vector(all_do_calc,N);
6313 SG_FREE(max_values);
6314 SG_FREE(min_values);
6316 SG_FREE(all_transform);
6317 SG_FREE(all_limits);
6318 SG_FREE(all_penalties);
6319 SG_FREE(all_use_cache);
6320 SG_FREE(all_use_svm);
6321 SG_FREE(all_do_calc);
6338 bool CSGInterface::cmd_signals_set_positions()
6342 bool CSGInterface::cmd_signals_set_labels()
6346 bool CSGInterface::cmd_signals_set_split()
6350 bool CSGInterface::cmd_signals_set_train_mask()
6354 bool CSGInterface::cmd_signals_add_feature()
6358 bool CSGInterface::cmd_signals_add_kernel()
6362 bool CSGInterface::cmd_signals_run()
6367 bool CSGInterface::cmd_init_dyn_prog()
6370 int32_t num_svms=get_int();
6373 ui_structure->set_dyn_prog(h);
6377 bool CSGInterface::cmd_clean_up_dyn_prog()
6379 return ui_structure->cleanup();
6382 bool CSGInterface::cmd_set_model()
6387 CDynProg* h = ui_structure->get_dyn_prog();
6398 get_ndarray(penalties_array,Dim,numDim);
6403 SG_ERROR(
"error computing plif matrix\n")
6404 ui_structure->set_num_states(Dim[0]);
6405 SG_FREE(penalties_array);
6409 bool use_orf = get_bool();
6410 ui_structure->set_use_orf(use_orf);
6417 get_matrix(mod_words, Nmod,Mmod);
6418 if (Nmod != num_svms)
6419 SG_ERROR(
"should be equal: Nmod: %i, num_svms: %i\n",Nmod,num_svms)
6425 int32_t num_states=0;
6426 int32_t feat_dim3=0;
6427 int32_t* state_signals;
6428 get_matrix(state_signals,num_states,feat_dim3);
6429 ASSERT(num_states==Dim[0])
6438 get_matrix(orf_info,Norf,Morf);
6442 ui_structure->set_orf_info(orf_info, Norf, Morf);
6450 bool CSGInterface::cmd_precompute_content_svms()
6456 seq = get_string(seq_len);
6462 get_vector(all_pos, Npos);
6469 get_matrix(weights, Nweights, num_svms);
6471 SG_PRINT(
"Dimension mismatch: got %i, expect %i\n", Nweights, 5440)
6472 ui_structure->set_content_svm_weights(weights, Nweights, num_svms);
6474 CDynProg* h = ui_structure->get_dyn_prog();
6476 SG_ERROR(
"no DynProg object found, use init_dyn_prog first\n")
6489 SG_DEBUG(
"precompute_content_svms done\n")
6493 bool CSGInterface::cmd_get_lin_feat()
6495 CDynProg* h = ui_structure->get_dyn_prog();
6497 SG_ERROR(
"no DynProg object found, use set_model first\n")
6500 int32_t dim1, dim2 = 0;
6503 set_matrix(lin_feat, dim1, dim2);
6507 bool CSGInterface::cmd_set_lin_feat()
6512 seq = get_string(Nseq);
6518 get_vector(all_pos, Npos);
6522 int32_t num_svms, seq_len;
6524 get_matrix(lin_feat, num_svms, seq_len);
6528 SG_ERROR(
"Dimension mismatch: got %i positions and (%ix%i) values\n", Npos, num_svms, seq_len)
6537 CDynProg* h = ui_structure->get_dyn_prog();
6539 SG_ERROR(
"no DynProg object found, use set_model first\n")
6551 bool CSGInterface::cmd_long_transition_settings()
6553 bool use_long_transitions = get_bool();
6554 int32_t threshold = get_int();
6555 int32_t max_len = get_int();
6557 CDynProg* h = ui_structure->get_dyn_prog();
6559 SG_ERROR(
"no DynProg object found, use set_model first\n")
6565 bool CSGInterface::cmd_set_feature_matrix()
6567 int32_t num_states = ui_structure->get_num_states();
6574 get_ndarray(features, Dims, numDims);
6577 SG_ERROR(
"expected a 3 dimensional array, got %i dimensions\n", numDims)
6578 if (Dims[0]!=num_states)
6579 SG_ERROR(
"number of rows (%i) not equal number of states (%i)\n",Dims[0], num_states)
6580 ASSERT(ui_structure->set_feature_matrix(features, Dims))
6582 ASSERT(ui_structure->set_feature_dims(Dims))
6589 bool CSGInterface::cmd_set_feature_matrix_sparse()
6591 int32_t num_pos = ui_structure->get_num_positions();
6592 int32_t num_states = ui_structure->get_num_states();
6596 int32_t dim11, dim12 ;
6598 get_sparse_matrix(features1, dim11, dim12);
6600 int32_t dim21, dim22 ;
6602 get_sparse_matrix(features2, dim21, dim22);
6607 int32_t *Dims = SG_MALLOC(int32_t, 3);
6612 ASSERT(Dims[0]==num_states)
6615 ASSERT(ui_structure->set_feature_matrix_sparse(features1, features2, Dims))
6616 ASSERT(ui_structure->set_feature_dims(Dims))
6624 bool CSGInterface::cmd_init_intron_list()
6627 int32_t Nstart_positions;
6628 int32_t* start_positions;
6629 get_vector(start_positions, Nstart_positions);
6633 int32_t Nend_positions;
6634 int32_t* end_positions;
6635 get_vector(end_positions, Nend_positions);
6641 get_vector(quality, Nquality);
6647 get_vector(all_pos, Nall_pos);
6650 ASSERT(Nquality==Nend_positions)
6651 ASSERT(Nend_positions==Nstart_positions)
6655 intron_list->
init_list(all_pos, Nall_pos);
6657 intron_list->
read_introns(start_positions, end_positions, quality, Nstart_positions);
6659 SG_FREE(start_positions);
6660 SG_FREE(end_positions);
6670 CDynProg* h = ui_structure->get_dyn_prog();
6672 SG_ERROR(
"no DynProg object found, use set_model first\n")
6678 bool CSGInterface::cmd_precompute_tiling_features()
6682 CDynProg* h = ui_structure->get_dyn_prog();
6684 int32_t Nintensities=0;
6686 get_vector(intensities, Nintensities);
6688 int32_t Nprobe_pos=0;
6690 get_vector(probe_pos, Nprobe_pos);
6691 ASSERT(Nprobe_pos==Nintensities)
6693 int32_t Ntiling_plif_ids=0;
6694 int32_t* tiling_plif_ids;
6695 get_vector(tiling_plif_ids, Ntiling_plif_ids);
6702 bool CSGInterface::cmd_best_path_trans()
6704 CDynProg* h = ui_structure->get_dyn_prog();
6711 int32_t* feat_dims = ui_structure->get_feature_dims();
6712 float64_t* features = (ui_structure->get_feature_matrix(
false));
6715 int32_t* orf_info = ui_structure->get_orf_info();
6716 bool use_orf = ui_structure->get_use_orf();
6725 SG_ERROR(
"# transitions from initial state (%i) does not match # states (%i)\n", Np, num_states)
6733 SG_ERROR(
"# transitions to end state (%i) does not match # states (%i)\n", Nq, num_states)
6739 get_vector(all_nbest, Nnbest);
6744 nbest =all_nbest[0];
6745 nother=all_nbest[1];
6748 nbest =all_nbest[0];
6755 int32_t Nseg_path=0;
6756 int32_t Mseg_path=0;
6758 get_matrix(seg_path, Nseg_path, Mseg_path);
6763 int32_t num_a_trans=0;
6765 get_matrix(a_trans, num_a_trans, Na_trans);
6774 get_matrix(loss, Nloss,Mloss);
6800 SG_ERROR(
"svm arrays inconsistent\n")
6805 SG_DEBUG(
"best_path_trans: M: %i, Mseg_path: %i\n", M, Mseg_path)
6822 bool segment_loss_non_zero=
false;
6823 for (int32_t i=0; i<Nloss*Mloss; i++)
6826 segment_loss_non_zero=
true;
6836 if (segment_loss_non_zero)
6838 SG_DEBUG(
"Using version with segment_loss\n")
6846 SG_DEBUG(
"Using version without segment_loss\n")
6863 for (int32_t k=0; k<(nbest+nother); k++)
6865 for (int32_t i=0; i<M; i++)
6867 d_my_path[i*(nbest+nother)+k] = states.
matrix[i+k*M] ;
6868 d_my_pos[i*(nbest+nother)+k] = my_pos.
matrix[i+k*M] ;
6871 set_vector(p_prob.
vector,nbest+nother);
6872 set_vector(d_my_path, (nbest+nother)*M);
6873 set_vector(d_my_pos, (nbest+nother)*M);
6882 bool CSGInterface::cmd_best_path_trans_deriv()
6884 int32_t num_states = ui_structure->get_num_states();
6885 int32_t* feat_dims = ui_structure->get_feature_dims();
6886 float64_t* features = (ui_structure->get_feature_matrix(
false));
6898 SG_ERROR(
"Np!=num_states; Np:%i num_states:%i",Np,num_states)
6906 SG_ERROR(
"Nq!=num_states; Nq:%i num_states:%i",Nq,num_states)
6913 int32_t Nseg_path=0;
6914 int32_t Mseg_path=0;
6916 get_matrix(seg_path,Nseg_path,Mseg_path);
6921 int32_t num_a_trans=0;
6923 get_matrix(a_trans, num_a_trans, Na_trans);
6932 get_matrix(loss, Nloss,Mloss);
6936 int32_t Nmystate_seq=0;
6937 int32_t* mystate_seq=NULL;
6938 get_vector(mystate_seq, Nmystate_seq);
6942 int32_t Nmypos_seq=0;
6943 int32_t* mypos_seq=NULL;
6944 get_vector(mypos_seq, Nmypos_seq);
6949 int32_t max_plif_id = 0 ;
6950 int32_t max_plif_len = 1 ;
6951 for (int32_t i=0; i<Nplif; i++)
6953 if (i>0 && PEN[i]->get_id()!=i)
6954 SG_ERROR(
"PEN[i]->get_id()!=i; PEN[%i]->get_id():%i ,\n",i, PEN[i]->get_id())
6957 if (PEN[i]->get_plif_len()>max_plif_len)
6962 CDynProg* h = ui_structure->get_dyn_prog();
6974 SG_ERROR(
"svm arrays inconsistent\n")
6976 int32_t *my_path = SG_MALLOC(int32_t, Nmypos_seq+1);
6977 memset(my_path, -1, Nmypos_seq*
sizeof(int32_t)) ;
6978 int32_t *my_pos = SG_MALLOC(int32_t, Nmypos_seq+1);
6979 memset(my_pos, -1, Nmypos_seq*
sizeof(int32_t)) ;
6982 for (int32_t i=0; i<Nmypos_seq; i++)
6984 my_path[i] = mystate_seq[i] ;
6985 my_pos[i] = mypos_seq[i] ;
7019 for (int32_t i=0; i<num_states; i++)
7021 for (int32_t j=0; j<num_states; j++)
7022 p_A_deriv[i+j*num_states] = h->
get_a_deriv(i, j) ;
7028 for (int32_t
id=0;
id<=max_plif_id;
id++)
7032 ASSERT(len<=max_plif_len)
7033 for (int32_t j=0; j<max_plif_len; j++)
7034 a_Plif_deriv.
element(
id, j)= deriv[j] ;
7037 set_vector(p_p_deriv, num_states);
7038 set_vector(p_q_deriv, num_states);
7039 set_matrix(p_A_deriv, num_states, num_states);
7040 set_matrix(p_Plif_deriv, (max_plif_id+1), max_plif_len);
7041 set_vector(p_my_scores, Nmypos_seq);
7042 set_vector(p_my_losses, Nmypos_seq);
7047 SG_FREE(p_Plif_deriv);
7058 SG_FREE(mystate_seq);
7064 bool CSGInterface::cmd_precompute_subkernels()
7066 if (m_nrhs!=1 || !create_return_values(0))
7069 return ui_kernel->precompute_subkernels();
7071 bool CSGInterface::cmd_crc()
7073 if (m_nrhs!=2 || !create_return_values(1))
7077 char*
string=get_string(slen);
7079 uint8_t* bstring=SG_MALLOC(uint8_t, slen);
7081 for (int32_t i=0; i<slen; i++)
7082 bstring[i]=
string[i];
7092 bool CSGInterface::cmd_system()
7094 if (m_nrhs<2 || !create_return_values(0))
7097 const int32_t MAX_LEN=10000;
7099 int32_t command_len=0;
7100 char* command=SG_MALLOC(
char, MAX_LEN+1);
7101 memset(command, 0,
sizeof(
char)*MAX_LEN+1);
7102 char* cmd=get_str_from_str_or_direct(len);
7103 strncat(command, cmd, MAX_LEN);
7107 while (m_rhs_counter<m_nrhs)
7109 char* arg=get_str_from_str_or_direct(len);
7110 command_len += len + 1;
7112 if (command_len >= MAX_LEN)
7117 strcat(command,
" ");
7118 strcat(command, arg);
7122 int status=system(command);
7127 bool CSGInterface::cmd_exit()
7133 bool CSGInterface::cmd_exec()
7135 if (m_nrhs<2 || !create_return_values(0))
7139 char* filename=get_str_from_str_or_direct(len);
7140 FILE* file=fopen(filename,
"r");
7144 SG_ERROR(
"Error opening file: %s.\n", filename)
7157 bool CSGInterface::cmd_set_output()
7159 if (m_nrhs<2 || !create_return_values(0))
7163 char* filename=get_str_from_str_or_direct(len);
7169 SG_INFO(
"Setting output file to: %s.\n", filename)
7171 if (strmatch(filename,
"STDERR"))
7172 io->set_target(stderr);
7173 else if (strmatch(filename,
"STDOUT"))
7174 io->set_target(stdout);
7177 file_out=fopen(filename,
"w");
7179 SG_ERROR(
"Error opening output file %s.\n", filename)
7180 io->set_target(file_out);
7186 bool CSGInterface::cmd_set_threshold()
7188 if (m_nrhs!=2 || !create_return_values(0))
7191 float64_t value=get_real_from_real_or_str();
7193 ui_math->set_threshold(value);
7197 bool CSGInterface::cmd_init_random()
7199 if (m_nrhs!=2 || !create_return_values(0))
7202 uint32_t initseed=(uint32_t) get_int_from_int_or_str();
7203 ui_math->init_random(initseed);
7208 bool CSGInterface::cmd_set_num_threads()
7210 if (m_nrhs!=2 || !create_return_values(0))
7213 int32_t num_threads=get_int_from_int_or_str();
7215 parallel->set_num_threads(num_threads);
7216 SG_INFO(
"Set number of threads to %d.\n", num_threads)
7221 bool CSGInterface::cmd_translate_string()
7223 if (m_nrhs!=4 || !create_return_values(1))
7228 get_vector(
string, len);
7230 int32_t order=get_int();
7231 int32_t start=get_int();
7233 const int32_t max_val=2;
7235 uint16_t* obs=SG_MALLOC(uint16_t, len);
7237 for (i=0; i<len; i++)
7239 switch ((
char)
string[i])
7241 case 'A': obs[i]=0;
break;
7242 case 'C': obs[i]=1;
break;
7243 case 'G': obs[i]=2;
break;
7244 case 'T': obs[i]=3;
break;
7245 case 'a': obs[i]=0;
break;
7246 case 'c': obs[i]=1;
break;
7247 case 'g': obs[i]=2;
break;
7248 case 't': obs[i]=3;
break;
7249 default:
SG_ERROR(
"Wrong letter in string.\n")
7254 for (i=len-1; i>=order-1; i--)
7257 for (j=i; j>=i-order+1; j--)
7258 value=(value>>max_val) | ((obs[j])<<(max_val*(order-1)));
7260 obs[i]=(uint16_t) value;
7263 for (i=order-2;i>=0;i--)
7266 for (j=i; j>=i-order+1; j--)
7268 value= (value >> max_val);
7270 value|=(obs[j]) << (max_val * (order-1));
7276 for (i=start; i<len; i++)
7280 set_vector(real_obs, len);
7286 bool CSGInterface::cmd_clear()
7313 bool CSGInterface::cmd_tic()
7319 bool CSGInterface::cmd_toc()
7325 bool CSGInterface::cmd_print()
7327 if (m_nrhs<2 || !create_return_values(0))
7331 char* msg=get_str_from_str_or_direct(len);
7339 bool CSGInterface::cmd_echo()
7341 if (m_nrhs<2 || !create_return_values(0))
7345 char* level=get_str_from_str_or_direct(len);
7347 if (strmatch(level,
"OFF"))
7362 bool CSGInterface::cmd_loglevel()
7364 if (m_nrhs<2 || !create_return_values(0))
7368 char* level=get_str_from_str_or_direct(len);
7370 if (strmatch(level,
"ALL") || strmatch(level,
"GCDEBUG"))
7372 else if (strmatch(level,
"DEBUG"))
7374 else if (strmatch(level,
"INFO"))
7376 else if (strmatch(level,
"NOTICE"))
7378 else if (strmatch(level,
"WARN"))
7380 else if (strmatch(level,
"ERROR"))
7382 else if (strmatch(level,
"CRITICAL"))
7384 else if (strmatch(level,
"ALERT"))
7386 else if (strmatch(level,
"EMERGENCY"))
7389 SG_ERROR(
"Unknown loglevel '%s'.\n", level)
7391 SG_INFO(
"Loglevel set to %s.\n", level)
7397 bool CSGInterface::cmd_syntax_highlight()
7399 if (m_nrhs<2 || !create_return_values(0))
7403 char* hili=get_str_from_str_or_direct(len);
7405 if (strmatch(hili,
"ON"))
7408 io->enable_syntax_highlighting();
7410 else if (strmatch(hili,
"OFF"))
7413 io->disable_syntax_highlighting();
7418 SG_INFO(
"Syntax hilighting set to %s.\n", hili)
7424 bool CSGInterface::cmd_progress()
7426 if (m_nrhs<2 || !create_return_values(0))
7430 char* progress=get_str_from_str_or_direct(len);
7432 if (strmatch(progress,
"ON"))
7433 io->enable_progress();
7434 else if (strmatch(progress,
"OFF"))
7435 io->disable_progress();
7437 SG_ERROR(
"arguments to progress are ON|OFF - found '%s'.\n", progress)
7439 SG_INFO(
"Progress set to %s.\n", progress)
7445 bool CSGInterface::cmd_get_version()
7447 if (m_nrhs!=1 || !create_return_values(1))
7450 set_int(version->get_version_revision());
7455 bool CSGInterface::cmd_help()
7457 if ((m_nrhs!=1 && m_nrhs!=2) || !create_return_values(0))
7465 SG_PRINT(
"Help is available for the following topics.\n" 7466 "-------------------------------------------\n\n");
7469 bool is_group_item=
false;
7483 SG_PRINT(
"\nUse sg('%shelp%s', '%s<topic>%s')" 7484 " to see the list of commands in this group, e.g.\n\n" 7485 "\tsg('%shelp%s', '%sFeatures%s')\n\n" 7486 "to see the list of commands for the 'Features' group.\n" 7487 "\nOr use sg('%shelp%s', '%sall%s')" 7488 " to see a brief listing of all commands.\n\nTo disable syntax" 7489 " highlighting (useful e.g. in the matlab GUI) use\n\n" 7490 "\tsg('syntax_highlight','OFF')\n",
7501 bool in_group=
false;
7503 char* command=get_string(clen);
7505 if (strmatch(
"doxygen", command) || strmatch(
"DOXYGEN", command))
7512 SG_PRINT(
"\\arg \\b %s \\verbatim %s%s%s \\endverbatim\n",
7520 SG_PRINT(
"\n\\section %s_sec %s\n",
7526 if (strmatch(
"all", command) || strmatch(
"ALL", command))
7541 SG_PRINT(
"\nCommands in group %s%s%s\n",
7565 found=strmatch(
sg_methods[i].command, command);
7570 SG_PRINT(
"Usage for %s%s%s\n\n\t%s%s%s%s%s\n",
7583 SG_PRINT(
"Commands in group %s%s%s\n\n",
7597 SG_PRINT(
"Could not find help for command %s.\n", command)
7600 SG_PRINT(
"\n\nUse sg('%shelp%s', '%s<command>%s')" 7601 " to see the usage pattern of a single command, e.g.\n\n" 7602 "\tsg('%shelp%s', '%sclassify%s')\n\n" 7603 " to see the usage pattern of the command 'classify'.\n",
7618 #ifdef TRACE_MEMORY_ALLOCS 7622 bool CSGInterface::cmd_whos()
7624 if ((m_nrhs!=1) || !create_return_values(0))
7627 #ifdef TRACE_MEMORY_ALLOCS 7628 SG_PRINT(
"Blocks allocated by shogun\n")
7629 list_memory_allocs();
7633 SG_PRINT(
"Requires shogun to be compiled with --enable-trace-mallocs\n")
7638 bool CSGInterface::cmd_send_command()
7643 char* arg=get_string(len);
7645 m_legacy_strptr=arg;
7647 char* command=get_str_from_str(len);
7653 if (strmatch(command,
sg_methods[i].command))
7657 m_nrhs=get_num_args_in_str()+1;
7661 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
7682 SG_ERROR(
"Non-supported legacy command %s.\n", command)
7689 bool CSGInterface::cmd_run_python()
7691 SG_ERROR(
"Only available in the elwms interface\n")
7695 bool CSGInterface::cmd_run_octave()
7697 SG_ERROR(
"Only available in the elwms interface\n")
7701 bool CSGInterface::cmd_run_r()
7703 SG_ERROR(
"Only available in the elwms interface\n")
7707 bool CSGInterface::cmd_pr_loqo()
7709 if (m_nrhs!=7 || !create_return_values(2))
7714 get_vector(c, lenc);
7721 get_matrix(H, nH, mH);
7727 get_matrix(A, nA, mA);
7733 get_vector(b, lenb);
7738 get_vector(l, lenl);
7743 get_vector(u, lenu);
7752 pr_loqo(n,m, c, H, A, b, l, u, x, y, 0, 5, 50, 0.05, 100, 0);
7768 void CSGInterface::print_prompt()
7779 char* CSGInterface::get_str_from_str_or_direct(int32_t& len)
7781 if (m_legacy_strptr)
7782 return get_str_from_str(len);
7784 return get_string(len);
7787 int32_t CSGInterface::get_int_from_int_or_str()
7789 if (m_legacy_strptr)
7792 char* str=get_str_from_str(len);
7793 int32_t val=strtol(str, NULL, 10);
7802 float64_t CSGInterface::get_real_from_real_or_str()
7804 if (m_legacy_strptr)
7807 char* str=get_str_from_str(len);
7817 bool CSGInterface::get_bool_from_bool_or_str()
7819 if (m_legacy_strptr)
7822 char* str=get_str_from_str(len);
7823 bool val=strtol(str, NULL, 10)!=0;
7832 void CSGInterface::get_vector_from_int_vector_or_str(int32_t*& vector, int32_t& len)
7834 if (m_legacy_strptr)
7836 len=get_vector_len_from_str(len);
7843 vector=SG_MALLOC(int32_t, len);
7846 for (int32_t i=0; i<len; i++)
7848 str=get_str_from_str(slen);
7849 vector[i]=strtol(str, NULL, 10);
7855 get_vector(vector, len);
7858 void CSGInterface::get_vector_from_real_vector_or_str(
7861 if (m_legacy_strptr)
7863 len=get_vector_len_from_str(len);
7873 for (int32_t i=0; i<len; i++)
7875 str=get_str_from_str(slen);
7876 vector[i]=strtod(str, NULL);
7882 get_vector(vector, len);
7885 int32_t CSGInterface::get_vector_len_from_str(int32_t expected_len)
7887 int32_t num_args=get_num_args_in_str();
7889 if (expected_len==0 || num_args==expected_len)
7891 else if (num_args==2*expected_len)
7894 return expected_len;
7897 SG_ERROR(
"Expected vector length %d does not match actual length %d.\n", expected_len, num_args)
7902 char* CSGInterface::get_str_from_str(int32_t& len)
7904 if (!m_legacy_strptr)
7908 while (m_legacy_strptr[i]!=
'\0' && !isspace(m_legacy_strptr[i]))
7912 char* str=SG_MALLOC(
char, len+1);
7913 for (i=0; i<len; i++)
7914 str[i]=m_legacy_strptr[i];
7918 if (m_legacy_strptr[len]==
'\0')
7919 m_legacy_strptr=NULL;
7922 m_legacy_strptr=m_legacy_strptr+len;
7929 int32_t CSGInterface::get_num_args_in_str()
7931 if (!m_legacy_strptr)
7937 while (m_legacy_strptr[i]!=
'\0')
7939 if (!isspace(m_legacy_strptr[i]) && !in_arg)
7944 else if (isspace(m_legacy_strptr[i]) && in_arg)
7957 bool CSGInterface::handle()
7969 SG_DEBUG(
"command: %s, nrhs %d\n", command, m_nrhs)
7973 if (strmatch(command,
sg_methods[i].command))
7984 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
7995 SG_ERROR(
"Non-supported command %s%s%s.\n",
8014 SG_ERROR(
"Unknown command %s%s%s.\n",
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
#define N_GET_SVM_OBJECTIVE
#define N_COMPUTE_MKL_PRIMAL_OBJECTIVE
#define N_COMPUTE_BY_SUBKERNELS
int32_t get_num_support_vectors()
#define N_RELATIVE_ENTROPY
bool set_element(T e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
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)
SGMatrix< ST > get_feature_matrix()
virtual EFeatureType get_feature_type() const =0
#define N_SET_CONSTRAINT_GENERATOR
#define N_ADD_DOTFEATURES
#define N_INIT_KERNEL_OPTIMIZATION
#define N_HMM_CLASSIFY_EXAMPLE
#define N_SVM_MAX_TRAIN_TIME
Real Labels are real-valued labels.
#define N_SIGNALS_ADD_FEATURE
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()
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)
virtual int32_t get_num_labels() const =0
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)
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
virtual ELabelType get_label_type() const =0
#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
#define N_GET_WD_POS_WEIGHTS
bool is_tree_initialized()
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
#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()
index_t num_vectors
total number of vectors
bool obtain_from_char_features(CStringFeatures< CT > *sf, int32_t start, int32_t p_order, int32_t gap, bool rev)
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.
static const float64_t epsilon
#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()
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 const char * get_name() const =0
bool compute_plif_matrix(SGNDArray< float64_t > penalties_array)
void set_intron_list(CIntronList *intron_list, int32_t num_plifs)
virtual float64_t get_max_value() const
Class SGObject is the base class of all shogun objects.
#define N_COMPUTE_MKL_DUAL_OBJECTIVE
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 load_ascii_file(char *fname, bool remap_to_bin=true, EAlphabet ascii_alphabet=DNA, EAlphabet binary_alphabet=RAWDNA)
void set_prior_probs_from_labels(CLabels *labels)
index_t num_features
total number of features
bool delete_position_weights_rhs()
bool delete_position_weights_lhs()
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
float64_t get_q(T_STATES offset) const
virtual void set_position_weights(SGVector< float64_t > pws)
#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
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)
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.
floatmax_t get_num_symbols()
Multiple Kernel Learning.
static void fill_vector(T *vec, int32_t len, T value)
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)
virtual EFeatureClass get_feature_class() const =0
#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
The class DenseFeatures implements dense feature matrices.
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
const T & element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const
#define N_GET_SPEC_SCORING
Class Preprocessor defines a preprocessor interface.
#define N_SVR_TUBE_EPSILON
virtual int32_t get_max_vector_length()
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)
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()
void set_a(T_STATES line_, T_STATES column, float64_t value)
#define N_SET_SUBKERNEL_WEIGHTS
int32_t get_degree() const
bool set_weights(SGMatrix< float64_t > new_weights)
virtual int32_t get_num_vectors() const =0
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
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)
virtual bool apply_preprocessor(bool force_preprocessing=false)