43 using namespace shogun;
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 (&CSGInterface::cmd_resize_kernel_cache),
325 #endif //USE_SVMLIGHT
328 {
"Distance", NULL, NULL },
331 (&CSGInterface::cmd_set_distance),
336 (&CSGInterface::cmd_init_distance),
341 (&CSGInterface::cmd_get_distance_matrix),
346 {
"Classifier", NULL, NULL },
349 (&CSGInterface::cmd_classify),
354 (&CSGInterface::cmd_classify),
359 (&CSGInterface::cmd_classify_example),
364 (&CSGInterface::cmd_classify_example),
369 (&CSGInterface::cmd_get_classifier),
374 (&CSGInterface::cmd_get_classifier),
379 (&CSGInterface::cmd_new_classifier),
381 "|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM"
382 "|SUBGRADIENTSVM|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF"
383 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA"
384 "|LPM|LPBOOST|SUBGRADIENTLPM|KNN" USAGE_STR)
388 (&CSGInterface::cmd_new_classifier),
390 "|LIBSVM|SVMLIGHT|LIGHT|LIGHT_ONECLASS|SVMLIN|GPBTSVM|MPDSVM|GNPPSVM|GMNPSVM"
391 "|SUBGRADIENTSVM|WDSVMOCAS|SVMOCAS|SVMSGD|SVMBMRM|SVMPERF"
392 "|KERNELPERCEPTRON|PERCEPTRON|LIBLINEAR_LR|LIBLINEAR_L2|LDA"
393 "|LPM|LPBOOST|SUBGRADIENTLPM|KNN" USAGE_STR)
397 (&CSGInterface::cmd_new_classifier),
402 (&CSGInterface::cmd_new_classifier),
407 (&CSGInterface::cmd_load_classifier),
412 (&CSGInterface::cmd_save_classifier),
417 (&CSGInterface::cmd_get_num_svms),
422 (&CSGInterface::cmd_get_svm),
427 (&CSGInterface::cmd_set_svm),
432 (&CSGInterface::cmd_set_linear_classifier),
437 (&CSGInterface::cmd_get_svm_objective),
442 (&CSGInterface::cmd_compute_svm_primal_objective),
447 (&CSGInterface::cmd_compute_svm_dual_objective),
452 (&CSGInterface::cmd_compute_svm_primal_objective),
457 (&CSGInterface::cmd_compute_mkl_dual_objective),
462 (&CSGInterface::cmd_compute_relative_mkl_duality_gap),
467 (&CSGInterface::cmd_compute_absolute_mkl_duality_gap),
472 (&CSGInterface::cmd_do_auc_maximization),
477 (&CSGInterface::cmd_set_perceptron_parameters),
482 (&CSGInterface::cmd_train_classifier),
487 (&CSGInterface::cmd_train_classifier),
492 (&CSGInterface::cmd_train_classifier),
497 (&CSGInterface::cmd_train_classifier),
502 (&CSGInterface::cmd_set_svm_qpsize),
507 (&CSGInterface::cmd_set_svm_max_qpsize),
512 (&CSGInterface::cmd_set_svm_bufsize),
517 (&CSGInterface::cmd_set_svm_C),
522 (&CSGInterface::cmd_set_svm_epsilon),
527 (&CSGInterface::cmd_set_svr_tube_epsilon),
532 (&CSGInterface::cmd_set_svm_nu),
537 (&CSGInterface::cmd_set_svm_mkl_parameters),
542 (&CSGInterface::cmd_set_elasticnet_lambda),
547 (&CSGInterface::cmd_set_mkl_block_norm),
552 (&CSGInterface::cmd_set_max_train_time),
557 (&CSGInterface::cmd_set_svm_shrinking_enabled),
562 (&CSGInterface::cmd_set_svm_batch_computation_enabled),
567 (&CSGInterface::cmd_set_svm_linadd_enabled),
572 (&CSGInterface::cmd_set_svm_bias_enabled),
577 (&CSGInterface::cmd_set_mkl_interleaved_enabled),
582 (&CSGInterface::cmd_set_krr_tau),
587 {
"Preprocessors", NULL, NULL },
590 (&CSGInterface::cmd_add_preproc),
595 (&CSGInterface::cmd_del_preproc),
600 (&CSGInterface::cmd_attach_preproc),
605 (&CSGInterface::cmd_clean_preproc),
609 {
"Converters", NULL, NULL },
612 (&CSGInterface::cmd_set_converter),
617 (&CSGInterface::cmd_embed),
622 {
"HMM", NULL, NULL },
625 (&CSGInterface::cmd_new_hmm),
630 (&CSGInterface::cmd_load_hmm),
635 (&CSGInterface::cmd_save_hmm),
640 (&CSGInterface::cmd_get_hmm),
645 (&CSGInterface::cmd_append_hmm),
650 (&CSGInterface::cmd_append_model),
655 (&CSGInterface::cmd_set_hmm),
660 (&CSGInterface::cmd_set_hmm_as),
665 (&CSGInterface::cmd_set_chop),
670 (&CSGInterface::cmd_set_pseudo),
675 (&CSGInterface::cmd_load_definitions),
680 (&CSGInterface::cmd_hmm_classify),
685 (&CSGInterface::cmd_one_class_linear_hmm_classify),
690 (&CSGInterface::cmd_one_class_hmm_classify),
695 (&CSGInterface::cmd_one_class_hmm_classify_example),
700 (&CSGInterface::cmd_hmm_classify_example),
705 (&CSGInterface::cmd_output_hmm),
710 (&CSGInterface::cmd_output_hmm_defined),
715 (&CSGInterface::cmd_hmm_likelihood),
720 (&CSGInterface::cmd_likelihood),
725 (&CSGInterface::cmd_save_likelihood),
730 (&CSGInterface::cmd_get_viterbi_path),
735 (&CSGInterface::cmd_viterbi_train_defined),
740 (&CSGInterface::cmd_viterbi_train),
745 (&CSGInterface::cmd_baum_welch_train),
750 (&CSGInterface::cmd_baum_welch_train_defined),
755 (&CSGInterface::cmd_baum_welch_trans_train),
760 (&CSGInterface::cmd_linear_train),
765 (&CSGInterface::cmd_save_path),
770 (&CSGInterface::cmd_convergence_criteria),
775 (&CSGInterface::cmd_normalize),
780 (&CSGInterface::cmd_add_states),
785 (&CSGInterface::cmd_permutation_entropy),
790 (&CSGInterface::cmd_relative_entropy),
795 (&CSGInterface::cmd_entropy),
800 (&CSGInterface::cmd_set_feature_matrix),
805 (&CSGInterface::cmd_set_feature_matrix_sparse),
810 (&CSGInterface::cmd_new_plugin_estimator),
815 (&CSGInterface::cmd_train_estimator),
820 (&CSGInterface::cmd_plugin_estimate_classify_example),
825 (&CSGInterface::cmd_plugin_estimate_classify),
830 (&CSGInterface::cmd_set_plugin_estimate),
835 (&CSGInterface::cmd_get_plugin_estimate),
838 {
"Signals", NULL, NULL },
841 (&CSGInterface::cmd_signals_set_model),
846 (&CSGInterface::cmd_signals_set_positions),
851 (&CSGInterface::cmd_signals_set_labels),
856 (&CSGInterface::cmd_signals_set_split),
861 (&CSGInterface::cmd_signals_set_train_mask),
866 (&CSGInterface::cmd_signals_add_feature),
871 (&CSGInterface::cmd_signals_add_kernel),
876 (&CSGInterface::cmd_signals_run),
879 {
"Structure", NULL, NULL },
882 (&CSGInterface::cmd_best_path),
887 (&CSGInterface::cmd_best_path_2struct),
899 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
903 (&CSGInterface::cmd_set_plif_struct),
916 (&CSGInterface::cmd_get_plif_struct),
929 (&CSGInterface::cmd_precompute_subkernels),
934 (&CSGInterface::cmd_precompute_content_svms),
941 (&CSGInterface::cmd_get_lin_feat),
946 (&CSGInterface::cmd_set_lin_feat),
951 (&CSGInterface::cmd_init_dyn_prog),
956 (&CSGInterface::cmd_clean_up_dyn_prog),
961 (&CSGInterface::cmd_init_intron_list),
968 (&CSGInterface::cmd_precompute_tiling_features),
975 (&CSGInterface::cmd_long_transition_settings),
983 (&CSGInterface::cmd_set_model),
992 (&CSGInterface::cmd_best_path_trans),
999 "prob" USAGE_COMMA
"path" USAGE_COMMA
"pos")
1003 (&CSGInterface::cmd_best_path_trans_deriv),
1020 USAGE_COMMA
"q_deriv"
1021 USAGE_COMMA
"cmd_deriv"
1022 USAGE_COMMA
"penalties_deriv"
1023 USAGE_COMMA
"my_scores"
1024 USAGE_COMMA
"my_loss")
1027 {
"POIM", NULL, NULL },
1030 (&CSGInterface::cmd_compute_POIM_WD),
1035 (&CSGInterface::cmd_get_SPEC_consensus),
1040 (&CSGInterface::cmd_get_SPEC_scoring),
1045 (&CSGInterface::cmd_get_WD_consensus),
1050 (&CSGInterface::cmd_get_WD_scoring),
1055 {
"Utility", NULL, NULL },
1058 (&CSGInterface::cmd_crc),
1063 (&CSGInterface::cmd_system),
1068 (&CSGInterface::cmd_exit),
1073 (&CSGInterface::cmd_exit),
1078 (&CSGInterface::cmd_exec),
1083 (&CSGInterface::cmd_set_output),
1088 (&CSGInterface::cmd_set_threshold),
1093 (&CSGInterface::cmd_init_random),
1098 (&CSGInterface::cmd_set_num_threads),
1103 (&CSGInterface::cmd_translate_string),
1105 "string, order, start",
"translation")
1109 (&CSGInterface::cmd_clear),
1114 (&CSGInterface::cmd_tic),
1119 (&CSGInterface::cmd_toc),
1124 (&CSGInterface::cmd_print),
1129 (&CSGInterface::cmd_echo),
1134 (&CSGInterface::cmd_loglevel),
1139 (&CSGInterface::cmd_syntax_highlight),
1144 (&CSGInterface::cmd_progress),
1149 (&CSGInterface::cmd_get_version),
1154 (&CSGInterface::cmd_help),
1159 (&CSGInterface::cmd_whos),
1164 (&CSGInterface::cmd_send_command),
1169 (&CSGInterface::cmd_run_python),
1171 "'Var1', Var1, 'Var2', Var2,..., python_function",
"results")
1175 (&CSGInterface::cmd_run_octave),
1177 "'Var1', Var1, 'Var2', Var2,..., octave_function",
"results")
1181 (&CSGInterface::cmd_run_r),
1183 "'Var1', Var1, 'Var2', Var2,..., r_function",
"results")
1189 CSGInterface::CSGInterface(
bool print_copyright)
1205 if (print_copyright)
1207 version->print_version();
1208 SG_PRINT(
"( seeding random number generator with %u (seed size %d))\n",
1211 SG_PRINT(
"initializing log-table (size=%i*%i*%i=%2.1fMB) ... ) ",
1222 CSGInterface::~CSGInterface()
1224 delete ui_classifier;
1226 delete ui_pluginestimate;
1232 delete ui_structure;
1236 delete ui_converter;
1242 void CSGInterface::reset()
1248 m_legacy_strptr=NULL;
1253 void CSGInterface::translate_arg(CSGInterface* source, CSGInterface* target)
1255 switch (source->get_argument_type())
1258 target->set_int(source->get_int());
1261 target->set_real(source->get_real());
1264 target->set_bool(source->get_bool());
1270 source->get_vector(v, len);
1271 target->set_vector(v, len);
1279 source->get_vector(v, len);
1280 target->set_vector(v, len);
1288 source->get_vector(v, len);
1289 target->set_vector(v, len);
1297 source->get_vector(v, len);
1298 target->set_vector(v, len);
1306 source->get_vector(v, len);
1307 target->set_vector(v, len);
1311 case VECTOR_SHORTREAL:
1315 source->get_vector(v, len);
1316 target->set_vector(v, len);
1324 source->get_vector(v, len);
1325 target->set_vector(v, len);
1333 source->get_vector(v, len);
1334 target->set_vector(v, len);
1342 int32_t max_str_len=0;
1344 source->get_string_list(strs, num_str, max_str_len);
1345 target->set_string_list(strs, num_str);
1352 int32_t max_str_len=0;
1354 source->get_string_list(strs, num_str,max_str_len);
1355 target->set_string_list(strs, num_str);
1362 int32_t max_str_len=0;
1364 source->get_string_list(strs, num_str,max_str_len);
1365 target->set_string_list(strs, num_str);
1372 int32_t max_str_len=0;
1374 source->get_string_list(strs, num_str, max_str_len);
1375 target->set_string_list(strs, num_str);
1382 int32_t max_str_len=0;
1384 source->get_string_list(strs, num_str, max_str_len);
1385 target->set_string_list(strs, num_str);
1393 int32_t* fmatrix=NULL;
1394 source->get_matrix(fmatrix, num_feat, num_vec);
1395 target->set_matrix(fmatrix, num_feat, num_vec);
1404 source->get_matrix(fmatrix, num_feat, num_vec);
1405 target->set_matrix(fmatrix, num_feat, num_vec);
1413 int16_t* fmatrix=NULL;
1414 source->get_matrix(fmatrix, num_feat, num_vec);
1415 target->set_matrix(fmatrix, num_feat, num_vec);
1419 case DENSE_SHORTREAL:
1424 source->get_matrix(fmatrix, num_feat, num_vec);
1425 target->set_matrix(fmatrix, num_feat, num_vec);
1433 uint16_t* fmatrix=NULL;
1434 source->get_matrix(fmatrix, num_feat, num_vec);
1435 target->set_matrix(fmatrix, num_feat, num_vec);
1522 source->get_sparse_matrix(fmatrix, num_feat, num_vec);
1524 for (int32_t i=0; i<num_vec; i++)
1525 nnz+=fmatrix[i].num_feat_entries;
1526 target->set_sparse_matrix(fmatrix, num_feat, num_vec, nnz);
1543 bool CSGInterface::cmd_load_features()
1545 if (m_nrhs<8 || !create_return_values(0))
1549 char* filename=get_str_from_str_or_direct(len);
1550 char* fclass=get_str_from_str_or_direct(len);
1551 char* type=get_str_from_str_or_direct(len);
1552 char* target=get_str_from_str_or_direct(len);
1553 int32_t size=get_int_from_int_or_str();
1554 int32_t comp_features=get_int_from_int_or_str();
1556 bool success=ui_features->load(
1557 filename, fclass, type, target, size, comp_features);
1566 bool CSGInterface::cmd_save_features()
1568 if (m_nrhs<5 || !create_return_values(0))
1572 char* filename=get_str_from_str_or_direct(len);
1573 char* type=get_str_from_str_or_direct(len);
1574 char* target=get_str_from_str_or_direct(len);
1576 bool success=ui_features->save(filename, type, target);
1584 bool CSGInterface::cmd_clean_features()
1586 if (m_nrhs<2 || !create_return_values(0))
1590 char* target=get_str_from_str_or_direct(len);
1592 bool success=ui_features->clean(target);
1598 bool CSGInterface::cmd_get_features()
1600 if (m_nrhs!=2 || !create_return_values(1))
1604 char* target=get_string(tlen);
1607 if (strmatch(target,
"TRAIN"))
1608 feat=ui_features->get_train_features();
1609 else if (strmatch(target,
"TEST"))
1610 feat=ui_features->get_test_features();
1614 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
1632 set_matrix(fmatrix, num_feat, num_vec);
1639 set_matrix(fmatrix, num_feat, num_vec);
1646 set_matrix(fmatrix, num_feat, num_vec);
1653 set_matrix(fmatrix, num_feat, num_vec);
1660 set_matrix(fmatrix, num_feat, num_vec);
1667 set_matrix(fmatrix, num_feat, num_vec);
1674 set_matrix(fmatrix, num_feat, num_vec);
1691 get_num_nonzero_entries();
1708 int32_t max_str_len=0;
1714 set_string_list(fmatrix, num_str);
1721 set_string_list(fmatrix, num_str);
1728 set_string_list(fmatrix, num_str);
1757 bool CSGInterface::cmd_add_features()
1759 if (m_nrhs<3 || !create_return_values(0))
1762 return do_set_features(
true,
false);
1765 bool CSGInterface::cmd_add_multiple_features()
1767 if ((m_nrhs!=4 && m_nrhs<5) || !create_return_values(0))
1770 int32_t repetitions=get_int();
1774 return do_set_features(
true,
false, repetitions);
1777 bool CSGInterface::cmd_add_dotfeatures()
1779 if (m_nrhs<3 || !create_return_values(0))
1782 return do_set_features(
true,
true);
1785 bool CSGInterface::cmd_set_features()
1787 if (m_nrhs<3 || !create_return_values(0))
1790 return do_set_features(
false,
false);
1793 bool CSGInterface::do_set_features(
bool add,
bool check_dot, int32_t repetitions)
1796 char* target=get_string(tlen);
1797 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
1800 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
1807 switch (get_argument_type())
1812 get_sparse_matrix(fmatrix, num_feat, num_vec);
1821 get_matrix(fmatrix, num_feat, num_vec);
1835 int32_t* fmatrix=NULL;
1836 get_matrix(fmatrix, num_feat, num_vec);
1846 int16_t* fmatrix=NULL;
1847 get_matrix(fmatrix, num_feat, num_vec);
1857 uint16_t* fmatrix=NULL;
1858 get_matrix(fmatrix, num_feat, num_vec);
1866 case DENSE_SHORTREAL:
1869 get_matrix(fmatrix, num_feat, num_vec);
1880 SG_ERROR(
"Please specify alphabet!\n");
1883 int32_t max_str_len=0;
1885 get_string_list(fmatrix, num_str, max_str_len);
1887 int32_t alphabet_len=0;
1888 char* alphabet_str=get_string(alphabet_len);
1891 if (strmatch(alphabet_str,
"DNABINFILE"))
1895 ASSERT(fmatrix[0].
string);
1905 SG_ERROR(
"Couldn't load DNA features from file.\n");
1912 bool convert_to_word=
false;
1913 bool convert_to_ulong=
false;
1915 if (strmatch(alphabet_str,
"DNAWORD"))
1918 convert_to_word=
true;
1920 else if (strmatch(alphabet_str,
"DNAULONG"))
1923 convert_to_ulong=
true;
1926 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1937 SG_ERROR(
"Couldnt set byte string features.\n");
1942 if (convert_to_word || convert_to_ulong)
1943 convert_to_bitembedding(feat, convert_to_word, convert_to_ulong);
1946 obtain_from_single_string(feat);
1953 SG_ERROR(
"Please specify alphabet!\n");
1956 int32_t max_str_len=0;
1958 get_string_list(fmatrix, num_str, max_str_len);
1960 int32_t alphabet_len=0;
1961 char* alphabet_str=get_string(alphabet_len);
1964 alphabet=
new CAlphabet(alphabet_str, alphabet_len);
1972 SG_ERROR(
"Couldnt set byte string features.\n");
1979 SG_ERROR(
"Wrong argument type %d.\n", get_argument_type());
1985 SG_ERROR(
"Feature type not supported by DOT Features\n");
1988 if (strmatch(target,
"TRAIN"))
1991 ui_features->set_train_features(feat);
1994 for (int32_t i=0; i<repetitions; i++)
1995 ui_features->add_train_dotfeatures((
CDotFeatures*) feat);
1999 for (int32_t i=0; i<repetitions; i++)
2000 ui_features->add_train_features(feat);
2006 ui_features->set_test_features(feat);
2009 for (int32_t i=0; i<repetitions; i++)
2010 ui_features->add_test_dotfeatures((
CDotFeatures*) feat);
2014 for (int32_t i=0; i<repetitions; i++)
2015 ui_features->add_test_features(feat);
2024 bool CSGInterface::cmd_set_reference_features()
2026 if (m_nrhs<3 || !create_return_values(0))
2030 char* target=get_str_from_str_or_direct(len);
2032 bool success=ui_features->set_reference_features(target);
2038 bool CSGInterface::cmd_del_last_features()
2040 if (m_nrhs<2 || !create_return_values(0))
2044 char* target=get_str_from_str_or_direct(len);
2045 bool success=ui_features->del_last_feature_obj(target);
2051 bool CSGInterface::cmd_convert()
2053 if (m_nrhs<5 || !create_return_values(0))
2057 char* target=get_str_from_str_or_direct(len);
2058 CFeatures* features=ui_features->get_convert_features(target);
2062 SG_ERROR(
"No \"%s\" features available.\n", target);
2065 char* from_class=get_str_from_str_or_direct(len);
2066 char* from_type=get_str_from_str_or_direct(len);
2067 char* to_class=get_str_from_str_or_direct(len);
2068 char* to_type=get_str_from_str_or_direct(len);
2071 if (strmatch(from_class,
"SIMPLE"))
2073 if (strmatch(from_type,
"REAL"))
2075 if (strmatch(to_class,
"SPARSE") &&
2076 strmatch(to_type,
"REAL"))
2078 result=ui_features->convert_simple_real_to_sparse_real(
2085 else if (strmatch(from_type,
"CHAR"))
2087 if (strmatch(to_class,
"STRING") &&
2088 strmatch(to_type,
"CHAR"))
2090 result=ui_features->convert_simple_char_to_string_char(
2093 else if (strmatch(to_class,
"SIMPLE"))
2095 if (strmatch(to_type,
"ALIGN") && m_nrhs==8)
2097 float64_t gap_cost=get_real_from_real_or_str();
2098 result=ui_features->convert_simple_char_to_simple_align(
2108 else if (strmatch(from_type,
"WORD"))
2110 if (strmatch(to_class,
"SIMPLE") &&
2111 strmatch(to_type,
"SALZBERG"))
2113 result=ui_features->convert_simple_word_to_simple_salzberg(
2124 else if (strmatch(from_class,
"SPARSE"))
2126 if (strmatch(from_type,
"REAL"))
2128 if (strmatch(to_class,
"SIMPLE") &&
2129 strmatch(to_type,
"REAL"))
2131 result=ui_features->convert_sparse_real_to_simple_real(
2141 else if (strmatch(from_class,
"STRING"))
2143 if (strmatch(from_type,
"CHAR"))
2145 if (strmatch(to_class,
"STRING"))
2154 order=get_int_from_int_or_str();
2158 start=get_int_from_int_or_str();
2162 gap=get_int_from_int_or_str();
2166 char* rev_str=get_str_from_str_or_direct(len);
2176 if (strmatch(to_type,
"BYTE"))
2178 result=ui_features->convert_string_char_to_string_generic<char,uint8_t>(
2182 else if (strmatch(to_type,
"WORD"))
2184 result=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2188 else if (strmatch(to_type,
"ULONG"))
2190 result=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2201 else if (strmatch(from_type,
"BYTE"))
2203 if (strmatch(to_class,
"STRING"))
2212 order=get_int_from_int_or_str();
2216 start=get_int_from_int_or_str();
2220 gap=get_int_from_int_or_str();
2224 char* rev_str=get_str_from_str_or_direct(len);
2234 if (strmatch(to_type,
"WORD"))
2236 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint16_t>(
2240 else if (strmatch(to_type,
"ULONG"))
2242 result=ui_features->convert_string_char_to_string_generic<uint8_t,uint64_t>(
2253 else if (strmatch(from_type,
"WORD"))
2255 if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"TOP"))
2257 result=ui_features->convert_string_word_to_simple_top(
2260 else if (strmatch(to_class,
"SPEC") && strmatch(to_type,
"WORD") && m_nrhs==7)
2262 bool use_norm=get_bool();
2270 else if (strmatch(to_class,
"SIMPLE") && strmatch(to_type,
"FK"))
2272 result=ui_features->convert_string_word_to_simple_fk(
2281 if (result && ui_features->set_convert_features(result, target))
2282 SG_INFO(
"Conversion was successful.\n");
2291 return (result!=NULL);
2294 void CSGInterface::convert_to_bitembedding(
CFeatures* &features,
bool convert_to_word,
bool convert_to_ulong)
2308 if (convert_to_word)
2310 SG_INFO(
"Converting into word-bitembedding\n");
2311 features=ui_features->convert_string_char_to_string_generic<char,uint16_t>(
2315 if (convert_to_ulong)
2317 SG_INFO(
"Converting into ulong-bitembedding\n");
2318 features=ui_features->convert_string_char_to_string_generic<char,uint64_t>(
2323 void CSGInterface::obtain_from_single_string(
CFeatures* features)
2329 char* str=get_string(len);
2332 if (strmatch(str,
"from_position_list"))
2334 obtain_from_position_list(features);
2336 else if (strmatch(str,
"slide_window"))
2338 obtain_by_sliding_window(features);
2344 bool CSGInterface::obtain_from_position_list(
CFeatures* features)
2346 int32_t winsize=get_int();
2348 int32_t* shifts=NULL;
2349 int32_t num_shift=0;
2350 get_vector(shifts, num_shift);
2356 SG_DEBUG(
"winsize: %d num_shifts: %d skip: %d\n", winsize, num_shift, skip);
2360 for (int32_t i=0; i<num_shift; i++)
2372 obtain_by_position_list(winsize, &positions, skip)>0);
2378 obtain_by_position_list(winsize, &positions, skip)>0);
2384 obtain_by_position_list(winsize, &positions, skip)>0);
2390 obtain_by_position_list(winsize, &positions, skip)>0);
2394 SG_ERROR(
"Unsupported string features type.\n");
2400 bool CSGInterface::obtain_by_sliding_window(
CFeatures* features)
2402 int32_t winsize=get_int();
2403 int32_t shift=get_int();
2425 SG_SERROR(
"Unsupported string features type.\n");
2432 bool CSGInterface::cmd_reshape()
2434 if (m_nrhs<4 || !create_return_values(0))
2438 char* target=get_str_from_str_or_direct(len);
2439 int32_t num_feat=get_int_from_int_or_str();
2440 int32_t num_vec=get_int_from_int_or_str();
2442 bool success=ui_features->reshape(target, num_feat, num_vec);
2448 bool CSGInterface::cmd_load_labels()
2450 if (m_nrhs<4 || !create_return_values(0))
2454 char* filename=get_str_from_str_or_direct(len);
2455 char* target=get_str_from_str_or_direct(len);
2457 bool success=ui_labels->load(filename, target);
2464 bool CSGInterface::cmd_set_labels()
2466 if (m_nrhs!=3 || !create_return_values(0))
2470 char* target=get_string(tlen);
2471 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
2474 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
2479 get_vector(lab, len);
2481 CLabels* labels=ui_labels->infer_labels(lab, len);
2485 if (strmatch(target,
"TRAIN"))
2486 ui_labels->set_train_labels(labels);
2487 else if (strmatch(target,
"TEST"))
2488 ui_labels->set_test_labels(labels);
2492 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
2499 bool CSGInterface::cmd_get_labels()
2501 if (m_nrhs!=2 || !create_return_values(1))
2505 char* target=get_string(tlen);
2508 if (strmatch(target,
"TRAIN"))
2509 labels=ui_labels->get_train_labels();
2510 else if (strmatch(target,
"TEST"))
2511 labels=ui_labels->get_test_labels();
2515 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
2532 bool CSGInterface::cmd_set_kernel_normalization()
2534 if (m_nrhs<2 || !create_return_values(0))
2538 char* normalization=get_string(len);
2548 bool success=ui_kernel->set_normalization(normalization, c, r);
2554 bool CSGInterface::cmd_set_kernel()
2556 if (m_nrhs<2 || !create_return_values(0))
2559 SG_DEBUG(
"SGInterface: set_kernel\n");
2560 CKernel* kernel=create_kernel();
2561 return ui_kernel->set_kernel(kernel);
2564 bool CSGInterface::cmd_add_kernel()
2566 if (m_nrhs<3 || !create_return_values(0))
2569 float64_t weight=get_real_from_real_or_str();
2572 CKernel* kernel=create_kernel();
2574 SG_DEBUG(
"SGInterface: add_kernel\n");
2575 return ui_kernel->add_kernel(kernel, weight);
2578 bool CSGInterface::cmd_del_last_kernel()
2580 if (m_nrhs<1 || !create_return_values(0))
2583 return ui_kernel->del_last_kernel();
2586 CKernel* CSGInterface::create_kernel()
2590 char* type=get_str_from_str_or_direct(len);
2592 SG_DEBUG(
"set_kernel with type: %s\n", type);
2594 if (strmatch(type,
"COMBINED"))
2599 int32_t size=get_int_from_int_or_str();
2600 bool append_subkernel_weights=
false;
2602 append_subkernel_weights=get_bool_from_bool_or_str();
2604 kernel=ui_kernel->create_combined(size, append_subkernel_weights);
2606 else if (strmatch(type,
"DISTANCE"))
2611 int32_t size=get_int_from_int_or_str();
2614 width=get_real_from_real_or_str();
2616 kernel=ui_kernel->create_distance(size, width);
2618 else if (strmatch(type,
"WAVELET"))
2624 char* dtype=get_str_from_str_or_direct(len);
2625 if (strmatch(dtype,
"REAL"))
2627 int32_t size=get_int_from_int_or_str();
2633 Wdilation=get_real_from_real_or_str();
2636 Wtranslation=get_real_from_real_or_str();
2639 kernel=ui_kernel->create_sigmoid(size, Wdilation, Wtranslation);
2644 else if (strmatch(type,
"LINEAR"))
2651 char* dtype=get_str_from_str_or_direct(len);
2652 int32_t size=get_int_from_int_or_str();
2655 scale=get_real_from_real_or_str();
2657 if (strmatch(dtype,
"BYTE"))
2658 kernel=ui_kernel->create_linearbyte(size, scale);
2659 else if (strmatch(dtype,
"WORD"))
2660 kernel=ui_kernel->create_linearword(size, scale);
2661 else if (strmatch(dtype,
"CHAR"))
2662 kernel=ui_kernel->create_linearstring(size, scale);
2663 else if (strmatch(dtype,
"REAL"))
2664 kernel=ui_kernel->create_linear(size, scale);
2665 else if (strmatch(dtype,
"SPARSEREAL"))
2666 kernel=ui_kernel->create_sparselinear(size, scale);
2670 else if (strmatch(type,
"HISTOGRAM"))
2675 char* dtype=get_str_from_str_or_direct(len);
2676 if (strmatch(dtype,
"WORD"))
2678 int32_t size=get_int_from_int_or_str();
2679 kernel=ui_kernel->create_histogramword(size);
2684 else if (strmatch(type,
"SALZBERG"))
2689 char* dtype=get_str_from_str_or_direct(len);
2690 if (strmatch(dtype,
"WORD"))
2692 int32_t size=get_int_from_int_or_str();
2693 kernel=ui_kernel->create_salzbergword(size);
2698 else if (strmatch(type,
"POLYMATCH"))
2703 char* dtype=get_str_from_str_or_direct(len);
2704 int32_t size=get_int_from_int_or_str();
2706 bool inhomogene=
false;
2707 bool normalize=
true;
2711 degree=get_int_from_int_or_str();
2714 inhomogene=get_bool_from_bool_or_str();
2716 normalize=get_bool_from_bool_or_str();
2720 if (strmatch(dtype,
"CHAR"))
2722 kernel=ui_kernel->create_polymatchstring(
2723 size, degree, inhomogene, normalize);
2725 else if (strmatch(dtype,
"WORD"))
2727 kernel=ui_kernel->create_polymatchwordstring(
2728 size, degree, inhomogene, normalize);
2733 else if (strmatch(type,
"MATCH"))
2738 char* dtype=get_str_from_str_or_direct(len);
2739 if (strmatch(dtype,
"WORD"))
2741 int32_t size=get_int_from_int_or_str();
2743 bool normalize=
true;
2746 d=get_int_from_int_or_str();
2748 normalize=get_bool_from_bool_or_str();
2750 kernel=ui_kernel->create_matchwordstring(size, d, normalize);
2755 else if (strmatch(type,
"WEIGHTEDCOMMSTRING") || strmatch(type,
"COMMSTRING"))
2757 char* dtype=get_str_from_str_or_direct(len);
2758 int32_t size=get_int_from_int_or_str();
2759 bool use_sign=
false;
2760 char* norm_str=NULL;
2764 use_sign=get_bool_from_bool_or_str();
2767 norm_str=get_str_from_str_or_direct(len);
2770 if (strmatch(dtype,
"WORD"))
2772 if (strmatch(type,
"WEIGHTEDCOMMSTRING"))
2774 kernel=ui_kernel->create_commstring(
2777 else if (strmatch(type,
"COMMSTRING"))
2779 kernel=ui_kernel->create_commstring(
2783 else if (strmatch(dtype,
"ULONG"))
2785 kernel=ui_kernel->create_commstring(
2792 else if (strmatch(type,
"CHI2"))
2797 char* dtype=get_str_from_str_or_direct(len);
2798 if (strmatch(dtype,
"REAL"))
2800 int32_t size=get_int_from_int_or_str();
2804 width=get_real_from_real_or_str();
2806 kernel=ui_kernel->create_chi2(size, width);
2811 else if (strmatch(type,
"FIXEDDEGREE"))
2816 char* dtype=get_str_from_str_or_direct(len);
2817 if (strmatch(dtype,
"CHAR"))
2819 int32_t size=get_int_from_int_or_str();
2822 d=get_int_from_int_or_str();
2824 kernel=ui_kernel->create_fixeddegreestring(size, d);
2829 else if (strmatch(type,
"LOCALALIGNMENT"))
2834 char* dtype=get_str_from_str_or_direct(len);
2835 if (strmatch(dtype,
"CHAR"))
2837 int32_t size=get_int_from_int_or_str();
2839 kernel=ui_kernel->create_localalignmentstring(size);
2844 else if (strmatch(type,
"OLIGO"))
2849 char* dtype=get_str_from_str_or_direct(len);
2850 if (strmatch(dtype,
"CHAR"))
2852 int32_t size=get_int_from_int_or_str();
2853 int32_t k=get_int_from_int_or_str();
2854 float64_t w=get_real_from_real_or_str();
2856 kernel=ui_kernel->create_oligo(size, k, w);
2861 else if (strmatch(type,
"WEIGHTEDDEGREEPOS2") ||
2862 strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2867 char* dtype=get_str_from_str_or_direct(len);
2868 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2870 int32_t size=get_int_from_int_or_str();
2871 int32_t order=get_int_from_int_or_str();
2872 int32_t max_mismatch=get_int_from_int_or_str();
2873 int32_t length=get_int_from_int_or_str();
2874 int32_t* shifts=NULL;
2876 get_vector_from_int_vector_or_str(shifts, l);
2880 bool use_normalization=
true;
2881 if (strmatch(type,
"WEIGHTEDDEGREEPOS2_NONORM"))
2882 use_normalization=
false;
2884 kernel=ui_kernel->create_weighteddegreepositionstring2(
2885 size, order, max_mismatch, shifts, length,
2893 else if (strmatch(type,
"WEIGHTEDDEGREEPOS3"))
2898 char* dtype=get_str_from_str_or_direct(len);
2899 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2901 int32_t size=get_int_from_int_or_str();
2902 int32_t order=get_int_from_int_or_str();
2903 int32_t max_mismatch=get_int_from_int_or_str();
2904 int32_t length=get_int_from_int_or_str();
2905 int32_t mkl_stepsize=get_int_from_int_or_str();
2906 int32_t* shifts=NULL;
2908 get_vector_from_int_vector_or_str(shifts, l);
2912 if (m_nrhs>9+length)
2914 get_vector_from_real_vector_or_str(
2915 position_weights, length);
2918 kernel=ui_kernel->create_weighteddegreepositionstring3(
2919 size, order, max_mismatch, shifts, length,
2920 mkl_stepsize, position_weights);
2928 else if (strmatch(type,
"WEIGHTEDDEGREEPOS"))
2933 char* dtype=get_str_from_str_or_direct(len);
2934 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2936 int32_t size=get_int_from_int_or_str();
2938 int32_t max_mismatch=0;
2945 order=get_int_from_int_or_str();
2949 max_mismatch=get_int_from_int_or_str();
2953 length=get_int_from_int_or_str();
2957 center=get_int_from_int_or_str();
2960 step=get_real_from_real_or_str();
2966 kernel=ui_kernel->create_weighteddegreepositionstring(
2967 size, order, max_mismatch, length, center, step);
2972 else if (strmatch(type,
"WEIGHTEDDEGREE"))
2977 char* dtype=get_str_from_str_or_direct(len);
2978 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
2980 int32_t size=get_int_from_int_or_str();
2982 int32_t max_mismatch=0;
2983 bool use_normalization=
true;
2984 int32_t mkl_stepsize=1;
2985 bool block_computation=
true;
2986 int32_t single_degree=-1;
2990 order=get_int_from_int_or_str();
2994 max_mismatch=get_int_from_int_or_str();
2998 use_normalization=get_bool_from_bool_or_str();
3002 mkl_stepsize=get_int_from_int_or_str();
3006 block_computation=get_int_from_int_or_str();
3009 single_degree=get_int_from_int_or_str();
3016 kernel=ui_kernel->create_weighteddegreestring(
3017 size, order, max_mismatch, use_normalization,
3018 mkl_stepsize, block_computation, single_degree);
3023 else if (strmatch(type,
"WEIGHTEDDEGREERBF"))
3028 char* dtype=get_str_from_str_or_direct(len);
3029 int32_t size=get_int_from_int_or_str();
3030 int32_t nof_properties=get_int_from_int_or_str();
3035 degree=get_int_from_int_or_str();
3038 width=get_real_from_real_or_str();
3044 kernel=ui_kernel->create_weighteddegreerbf(size, degree, nof_properties, width);
3049 else if (strmatch(type,
"SPECTRUMMISMATCHRBF"))
3054 char* dtype=get_str_from_str_or_direct(len);
3055 if (strmatch(dtype,
"CHAR") || strmatch(dtype,
"STRING"))
3057 int32_t size=get_int_from_int_or_str();
3058 int32_t degree=get_int_from_int_or_str();
3059 int32_t max_mismatch=get_int_from_int_or_str();
3060 float64_t width=get_real_from_real_or_str();
3068 get_matrix(helper_matrix, N, M);
3070 if (N == 128 && M == 128)
3073 memcpy(AA_matrix, helper_matrix, N*M*
sizeof(
float64_t)) ;
3074 kernel=ui_kernel->create_spectrummismatchrbf(size, AA_matrix, max_mismatch, degree, width);
3078 SG_ERROR(
"Matrix size %d %d\n", N, M);
3085 else if (strmatch(type,
"SLIK") || strmatch(type,
"LIK"))
3090 char* dtype=get_str_from_str_or_direct(len);
3091 if (strmatch(dtype,
"CHAR"))
3093 int32_t size=get_int_from_int_or_str();
3095 int32_t inner_degree=3;
3096 int32_t outer_degree=1;
3100 length=get_int_from_int_or_str();
3104 inner_degree=get_int_from_int_or_str();
3107 outer_degree=get_int_from_int_or_str();
3111 if (strmatch(type,
"SLIK"))
3113 kernel=ui_kernel->create_localityimprovedstring(
3114 size, length, inner_degree, outer_degree,
3119 kernel=ui_kernel->create_localityimprovedstring(
3120 size, length, inner_degree, outer_degree,
3127 else if (strmatch(type,
"POLY"))
3132 char* dtype=get_str_from_str_or_direct(len);
3133 int32_t size=get_int_from_int_or_str();
3135 bool inhomogene=
false;
3136 bool normalize=
true;
3140 degree=get_int_from_int_or_str();
3144 inhomogene=get_bool_from_bool_or_str();
3147 normalize=get_bool_from_bool_or_str();
3151 if (strmatch(dtype,
"REAL"))
3153 kernel=ui_kernel->create_poly(
3154 size, degree, inhomogene, normalize);
3156 else if (strmatch(dtype,
"SPARSEREAL"))
3158 kernel=ui_kernel->create_sparsepoly(
3159 size, degree, inhomogene, normalize);
3164 else if (strmatch(type,
"SIGMOID"))
3169 char* dtype=get_str_from_str_or_direct(len);
3170 if (strmatch(dtype,
"REAL"))
3172 int32_t size=get_int_from_int_or_str();
3178 gamma=get_real_from_real_or_str();
3181 coef0=get_real_from_real_or_str();
3184 kernel=ui_kernel->create_sigmoid(size, gamma, coef0);
3189 else if (strmatch(type,
"GAUSSIAN"))
3194 char* dtype=get_str_from_str_or_direct(len);
3195 int32_t size=get_int_from_int_or_str();
3198 width=get_real_from_real_or_str();
3200 if (strmatch(dtype,
"REAL"))
3201 kernel=ui_kernel->create_gaussian(size, width);
3202 else if (strmatch(dtype,
"SPARSEREAL"))
3203 kernel=ui_kernel->create_sparsegaussian(size, width);
3207 else if (strmatch(type,
"GAUSSIANSHIFT"))
3212 char* dtype=get_str_from_str_or_direct(len);
3213 if (strmatch(dtype,
"REAL"))
3215 int32_t size=get_int_from_int_or_str();
3216 float64_t width=get_real_from_real_or_str();
3217 int32_t max_shift=get_int_from_int_or_str();
3218 int32_t shift_step=get_int_from_int_or_str();
3220 kernel=ui_kernel->create_gaussianshift(
3221 size, width, max_shift, shift_step);
3226 else if (strmatch(type,
"CUSTOM"))
3228 if (m_nrhs!=4 || !create_return_values(0))
3234 get_matrix(kmatrix, num_feat, num_vec);
3237 char* ktype=get_string(tlen);
3239 if (!strmatch(ktype,
"DIAG") &&
3240 !strmatch(ktype,
"FULL") &&
3241 !strmatch(ktype,
"FULL2DIAG"))
3244 SG_ERROR(
"Undefined type, not DIAG, FULL or FULL2DIAG.\n");
3247 bool source_is_diag=
false;
3248 bool dest_is_diag=
false;
3250 if (strmatch(ktype,
"FULL2DIAG"))
3252 else if (strmatch(ktype,
"DIAG"))
3254 source_is_diag=
true;
3258 kernel=ui_kernel->create_custom(kmatrix, num_feat, num_vec,
3259 source_is_diag, dest_is_diag);
3261 else if (strmatch(type,
"CONST"))
3266 char* dtype=get_str_from_str_or_direct(len);
3267 if (strmatch(dtype,
"REAL"))
3269 int32_t size=get_int_from_int_or_str();
3272 c=get_real_from_real_or_str();
3274 kernel=ui_kernel->create_const(size, c);
3279 else if (strmatch(type,
"DIAG"))
3284 char* dtype=get_str_from_str_or_direct(len);
3285 if (strmatch(dtype,
"REAL"))
3287 int32_t size=get_int_from_int_or_str();
3290 diag=get_real_from_real_or_str();
3292 kernel=ui_kernel->create_diag(size, diag);
3298 else if (strmatch(type,
"TPPK"))
3303 char* dtype=get_str_from_str_or_direct(len);
3304 if (strmatch(dtype,
"INT"))
3306 int32_t size=get_int_from_int_or_str();
3310 get_matrix(km, rows, cols);
3311 kernel=ui_kernel->create_tppk(size, km, rows, cols);
3320 SG_DEBUG(
"created kernel: %p\n", kernel);
3333 int32_t from_order=0;
3334 bool normalize=
true;
3336 int32_t feature_class_len=0;
3337 char* feature_class_str=get_string(feature_class_len);
3338 ASSERT(feature_class_str);
3340 if (strmatch(feature_class_str,
"WD"))
3343 SG_ERROR(
"Please specify alphabet, WD, order, from_order\n");
3347 from_order=get_int();
3350 else if (strmatch(feature_class_str,
"WSPEC"))
3353 SG_ERROR(
"Please specify alphabet, order, WSPEC, start, normalize\n");
3358 normalize=get_bool();
3381 int32_t feature_class_len=0;
3383 char* feature_class_str=get_string(feature_class_len);
3384 ASSERT(feature_class_str);
3385 if (strmatch(feature_class_str,
"POLY"))
3391 normalize = get_bool();
3396 SG_ERROR(
"Unknown feature class: %s\n", feature_class_str);
3404 bool CSGInterface::cmd_init_kernel()
3410 bool CSGInterface::cmd_clean_kernel()
3412 if (m_nrhs<1 || !create_return_values(0))
3415 return ui_kernel->clean_kernel();
3418 bool CSGInterface::cmd_save_kernel()
3420 if (m_nrhs<2 || !create_return_values(0))
3424 char* filename=get_str_from_str_or_direct(len);
3426 bool success=ui_kernel->save_kernel(filename);
3432 bool CSGInterface::cmd_get_kernel_matrix()
3434 if (m_nrhs>2 || !create_return_values(1))
3441 target=get_string(len);
3442 bool success=ui_kernel->init_kernel(target);
3446 CKernel* kernel=ui_kernel->get_kernel();
3448 SG_ERROR(
"No kernel defined or not initialized.\n");
3459 bool CSGInterface::cmd_set_WD_position_weights()
3461 if (m_nrhs<2 || m_nrhs>3 || !create_return_values(0))
3464 CKernel* kernel=ui_kernel->get_kernel();
3483 get_matrix(weights, dim, len);
3490 if (dim!=1 && len>0)
3491 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n");
3493 ui_kernel->init_kernel(
"TRAIN");
3506 target=get_string(tlen);
3510 SG_ERROR(
"Couldn't find second argument to method.\n");
3513 if (!strmatch(target,
"TRAIN") && !strmatch(target,
"TEST"))
3516 SG_ERROR(
"Second argument none of TRAIN or TEST.\n");
3519 if (strmatch(target,
"TEST"))
3523 if (dim!=1 && len>0)
3526 SG_ERROR(
"Dimension mismatch (should be 1 x seq_length or 0x0\n");
3529 if (dim==0 && len==0)
3531 if (create_return_values(3))
3543 if (create_return_values(3))
3552 ui_kernel->init_kernel(
"TRAIN");
3564 bool CSGInterface::cmd_get_subkernel_weights()
3566 if (m_nrhs!=1 || !create_return_values(1))
3569 CKernel *kernel=ui_kernel->get_kernel();
3578 int32_t num_weights=-1;
3579 weights=((
CCombinedKernel *) kernel)->get_subkernel_weights(num_weights);
3582 set_matrix(weights, 1, num_weights);
3592 get_degree_weights(degree, length);
3597 get_degree_weights(degree, length);
3600 SG_ERROR(
"Setting subkernel weights not supported on this kernel.\n");
3605 set_matrix(weights, degree, length);
3609 bool CSGInterface::cmd_set_subkernel_weights()
3611 if (m_nrhs!=2 || !create_return_values(0))
3614 CKernel* kernel=ui_kernel->get_kernel();
3622 get_matrix(weights, dim, len);
3630 if (dim!=degree || len<1)
3631 SG_ERROR(
"WD: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree);
3643 if (dim!=degree || len<1)
3644 SG_ERROR(
"WDPos: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len, degree);
3654 if (dim!=1 || len!=num_subkernels)
3655 SG_ERROR(
"All: Dimension mismatch (should be 1 x num_subkernels)\n");
3664 bool CSGInterface::cmd_set_subkernel_weights_combined()
3666 if (m_nrhs!=3 || !create_return_values(0))
3669 CKernel* kernel=ui_kernel->get_kernel();
3673 SG_ERROR(
"Only works for combined kernels.\n");
3679 get_matrix(weights, dim, len);
3681 int32_t idx=get_int();
3682 SG_DEBUG(
"using kernel_idx=%i\n", idx);
3686 SG_ERROR(
"No subkernel at idx %d.\n", idx);
3694 if (dim!=degree || len<1)
3695 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n");
3707 if (dim!=degree || len<1)
3708 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n");
3718 if (dim!=1 || len!=num_subkernels)
3719 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n");
3728 bool CSGInterface::cmd_get_dotfeature_weights_combined()
3730 if (m_nrhs!=2 || !create_return_values(1))
3734 char* target=get_string(tlen);
3737 if (strmatch(target,
"TRAIN"))
3738 features=ui_features->get_train_features();
3739 else if (strmatch(target,
"TEST"))
3740 features=ui_features->get_test_features();
3744 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
3751 SG_ERROR(
"Only works for combined dot features.\n");
3759 bool CSGInterface::cmd_set_dotfeature_weights_combined()
3761 if (m_nrhs!=3 || !create_return_values(0))
3765 char* target=get_string(tlen);
3768 if (strmatch(target,
"TRAIN"))
3769 features=ui_features->get_train_features();
3770 else if (strmatch(target,
"TEST"))
3771 features=ui_features->get_test_features();
3775 SG_ERROR(
"Unknown target, neither TRAIN nor TEST.\n");
3782 SG_ERROR(
"Only works for combined dot features.\n");
3787 get_matrix(weights, dim, len);
3794 bool CSGInterface::cmd_set_last_subkernel_weights()
3796 if (m_nrhs!=2 || !create_return_values(0))
3799 CKernel* kernel=ui_kernel->get_kernel();
3803 SG_ERROR(
"Only works for Combined kernels.\n");
3813 get_matrix(weights, dim, len);
3820 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n");
3832 SG_ERROR(
"Dimension mismatch (should be de(seq_length | 1) x degree)\n");
3842 if (dim!=1 || len!=num_subkernels)
3843 SG_ERROR(
"Dimension mismatch (should be 1 x num_subkernels)\n");
3852 bool CSGInterface::cmd_get_WD_position_weights()
3854 if (m_nrhs!=1 || !create_return_values(1))
3857 CKernel* kernel=ui_kernel->get_kernel();
3865 SG_ERROR(
"Couldn't find last kernel.\n");
3869 SG_ERROR(
"Wrong subkernel type.\n");
3880 if (position_weights==NULL)
3881 set_vector(position_weights, 0);
3883 set_vector(position_weights, len);
3888 bool CSGInterface::cmd_get_last_subkernel_weights()
3890 if (m_nrhs!=1 || !create_return_values(1))
3893 CKernel* kernel=ui_kernel->get_kernel();
3898 SG_ERROR(
"Only works for Combined kernels.\n");
3902 SG_ERROR(
"Couldn't find last kernel.\n");
3909 int32_t num_weights=0;
3913 set_vector(weights, num_weights);
3920 get_degree_weights(degree, len);
3923 get_degree_weights(degree, len);
3925 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n");
3930 set_matrix(weights, degree, len);
3935 bool CSGInterface::cmd_compute_by_subkernels()
3937 if (m_nrhs!=1 || !create_return_values(1))
3940 CKernel* kernel=ui_kernel->get_kernel();
3957 SG_ERROR(
"Kernel optimization not initialized.\n");
3965 SG_ERROR(
"Kernel optimization not initialized.\n");
3968 SG_ERROR(
"Only works for Weighted Degree (Position) kernels.\n");
3973 int32_t num_feat=degree*len;
3974 int32_t num=num_feat*num_vec;
3977 for (int32_t i=0; i<num; i++)
3983 for (int32_t i=0; i<num_vec; i++)
3990 for (int32_t i=0; i<num_vec; i++)
3994 set_matrix(result, num_feat, num_vec);
4000 bool CSGInterface::cmd_init_kernel_optimization()
4002 if (m_nrhs<1 || !create_return_values(0))
4005 return ui_kernel->init_kernel_optimization();
4008 bool CSGInterface::cmd_get_kernel_optimization()
4010 if (m_nrhs<1 || !create_return_values(1))
4013 CKernel* kernel=ui_kernel->get_kernel();
4024 int32_t max_order=get_int();
4025 if ((max_order<1) || (max_order>12))
4027 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order);
4032 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4037 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4042 for (int32_t i=0; i<num_suppvec; i++)
4049 num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4053 set_matrix(position_weights, num_sym, num_feat);
4067 set_vector(weights, len);
4076 set_vector(weights, len);
4086 bool CSGInterface::cmd_delete_kernel_optimization()
4088 if (m_nrhs<1 || !create_return_values(0))
4091 return ui_kernel->delete_kernel_optimization();
4094 bool CSGInterface::cmd_use_diagonal_speedup()
4096 if (m_nrhs<2 || !create_return_values(0))
4099 bool speedup=get_bool();
4101 CKernel* kernel=ui_kernel->get_kernel();
4107 SG_DEBUG(
"Identified combined kernel.\n");
4110 SG_ERROR(
"No last kernel defined.\n");
4114 SG_ERROR(
"Currently only commwordstring kernel supports diagonal speedup\n");
4118 SG_INFO(
"Diagonal speedup %s.\n", speedup ?
"enabled" :
"disabled");
4123 bool CSGInterface::cmd_set_kernel_optimization_type()
4125 if (m_nrhs<2 || !create_return_values(0))
4129 char* opt_type=get_str_from_str_or_direct(len);
4131 bool success=ui_kernel->set_optimization_type(opt_type);
4137 bool CSGInterface::cmd_set_solver()
4139 if (m_nrhs<2 || !create_return_values(0))
4143 char* solver=get_str_from_str_or_direct(len);
4145 bool success=ui_classifier->set_solver(solver);
4151 bool CSGInterface::cmd_set_constraint_generator()
4153 if (m_nrhs<2 || !create_return_values(0))
4157 char* cg=get_str_from_str_or_direct(len);
4159 bool success=ui_classifier->set_constraint_generator(cg);
4165 bool CSGInterface::cmd_set_prior_probs()
4167 if (m_nrhs<3 || !create_return_values(0))
4173 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n");
4175 float64_t pos_probs=get_real_from_real_or_str();
4176 float64_t neg_probs=get_real_from_real_or_str();
4183 bool CSGInterface::cmd_set_prior_probs_from_labels()
4185 if (m_nrhs<2 || !create_return_values(0))
4191 SG_ERROR(
"SalzbergWordStringKernel required for setting prior probs!\n");
4195 get_vector(lab, len);
4198 for (int32_t i=0; i<len; i++)
4201 SG_ERROR(
"Couldn't set label %d (of %d): %f.\n", i, len, lab[i]);
4212 bool CSGInterface::cmd_resize_kernel_cache()
4214 if (m_nrhs<2 || !create_return_values(0))
4217 int32_t size=get_int_from_int_or_str();
4218 return ui_kernel->resize_kernel_cache(size);
4220 #endif //USE_SVMLIGHT
4225 bool CSGInterface::cmd_set_distance()
4227 if (m_nrhs<3 || !create_return_values(0))
4232 char* type=get_str_from_str_or_direct(len);
4233 char* dtype=get_str_from_str_or_direct(len);
4235 if (strmatch(type,
"MINKOWSKI") && m_nrhs==4)
4237 float64_t k=get_real_from_real_or_str();
4238 distance=ui_distance->create_minkowski(k);
4240 else if (strmatch(type,
"MANHATTAN"))
4242 if (strmatch(dtype,
"REAL"))
4243 distance=ui_distance->create_generic(
D_MANHATTAN);
4244 else if (strmatch(dtype,
"WORD"))
4247 else if (strmatch(type,
"HAMMING") && strmatch(dtype,
"WORD"))
4249 bool use_sign=
false;
4251 use_sign=get_bool_from_bool_or_str();
4253 distance=ui_distance->create_hammingword(use_sign);
4255 else if (strmatch(type,
"CANBERRA"))
4257 if (strmatch(dtype,
"REAL"))
4258 distance=ui_distance->create_generic(
D_CANBERRA);
4259 else if (strmatch(dtype,
"WORD"))
4262 else if (strmatch(type,
"CHEBYSHEW") && strmatch(dtype,
"REAL"))
4264 distance=ui_distance->create_generic(
D_CHEBYSHEW);
4266 else if (strmatch(type,
"GEODESIC") && strmatch(dtype,
"REAL"))
4268 distance=ui_distance->create_generic(
D_GEODESIC);
4270 else if (strmatch(type,
"JENSEN") && strmatch(dtype,
"REAL"))
4272 distance=ui_distance->create_generic(
D_JENSEN);
4274 else if (strmatch(type,
"CHISQUARE") && strmatch(dtype,
"REAL"))
4276 distance=ui_distance->create_generic(
D_CHISQUARE);
4278 else if (strmatch(type,
"TANIMOTO") && strmatch(dtype,
"REAL"))
4280 distance=ui_distance->create_generic(
D_TANIMOTO);
4282 else if (strmatch(type,
"COSINE") && strmatch(dtype,
"REAL"))
4284 distance=ui_distance->create_generic(
D_COSINE);
4286 else if (strmatch(type,
"BRAYCURTIS") && strmatch(dtype,
"REAL"))
4290 else if (strmatch(type,
"EUCLIDEAN"))
4292 if (strmatch(dtype,
"REAL"))
4293 distance=ui_distance->create_generic(
D_EUCLIDEAN);
4294 else if (strmatch(dtype,
"SPARSEREAL"))
4302 return ui_distance->set_distance(distance);
4305 bool CSGInterface::cmd_init_distance()
4311 bool CSGInterface::cmd_get_distance_matrix()
4313 if (m_nrhs!=2 || !create_return_values(1))
4317 char* target=get_string(len);
4319 bool success=ui_distance->init_distance(target);
4325 SG_ERROR(
"No distance defined or not initialized.\n");
4327 int32_t num_vec_lhs=0;
4328 int32_t num_vec_rhs=0;
4332 set_matrix(dmatrix, num_vec_lhs, num_vec_rhs);
4342 bool CSGInterface::cmd_get_SPEC_consensus()
4344 if (m_nrhs!=1 || !create_return_values(1))
4347 CKernel* kernel=ui_kernel->get_kernel();
4351 SG_ERROR(
"Only works for CommWordString kernels.\n");
4353 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4356 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4360 for (int32_t i=0; i<num_suppvec; i++)
4367 num_feat, num_suppvec, sv_idx, sv_weight);
4371 set_vector(consensus, num_feat);
4377 bool CSGInterface::cmd_get_SPEC_scoring()
4379 if (m_nrhs!=2 || !create_return_values(1))
4382 int32_t max_order=get_int();
4383 CKernel* kernel=ui_kernel->get_kernel();
4389 SG_ERROR(
"Only works for (Weighted) CommWordString kernels.\n");
4391 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4394 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4399 for (int32_t i=0; i<num_suppvec; i++)
4405 if ((max_order<1) || (max_order>8))
4407 SG_WARNING(
"max_order out of range 1..8 (%d). setting to 1\n", max_order);
4414 max_order, num_feat, num_sym, NULL,
4415 num_suppvec, sv_idx, sv_weight);
4418 max_order, num_feat, num_sym, NULL,
4419 num_suppvec, sv_idx, sv_weight);
4423 set_matrix(position_weights, num_sym, num_feat);
4429 bool CSGInterface::cmd_get_WD_consensus()
4431 if (m_nrhs!=1 || !create_return_values(1))
4434 CKernel* kernel=ui_kernel->get_kernel();
4438 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n");
4440 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4443 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4447 for (int32_t i=0; i<num_suppvec; i++)
4454 num_feat, num_suppvec, sv_idx, sv_weight);
4458 set_vector(consensus, num_feat);
4464 bool CSGInterface::cmd_compute_POIM_WD()
4466 if (m_nrhs!=3 || !create_return_values(1))
4469 int32_t max_order=get_int();
4471 int32_t num_dfeat=0;
4473 get_matrix(distribution, num_dfeat, num_dvec);
4478 CKernel* kernel=ui_kernel->get_kernel();
4482 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n");
4492 if (num_dvec!=seqlen || num_dfeat!=num_sym)
4494 SG_ERROR(
"distribution should have (seqlen x num_sym) elements"
4495 "(seqlen: %d vs. %d symbols: %d vs. %d)\n", seqlen,
4496 num_dvec, num_sym, num_dfeat);
4499 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4502 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4505 for (int32_t i=0; i<num_suppvec; i++)
4521 max_order, seqlen, num_sym, NULL,
4522 num_suppvec, sv_idx, sv_weight, distribution);
4526 set_matrix(position_weights, num_sym, seqlen);
4532 bool CSGInterface::cmd_get_WD_scoring()
4534 if (m_nrhs!=2 || !create_return_values(1))
4537 int32_t max_order=get_int();
4539 CKernel* kernel=ui_kernel->get_kernel();
4543 SG_ERROR(
"Only works for Weighted Degree Position kernels.\n");
4545 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4548 int32_t* sv_idx=
SG_MALLOC(int32_t, num_suppvec);
4553 for (int32_t i=0; i<num_suppvec; i++)
4559 if ((max_order<1) || (max_order>12))
4561 SG_WARNING(
"max_order out of range 1..12 (%d). setting to 1\n", max_order);
4567 max_order, num_feat, num_sym, NULL, num_suppvec, sv_idx, sv_weight);
4571 set_matrix(position_weights, num_sym, num_feat);
4580 bool CSGInterface::cmd_classify()
4582 if (m_nrhs!=1 || !create_return_values(1))
4585 if (!ui_kernel->get_kernel() ||
4586 !ui_kernel->get_kernel()->get_kernel_type()==
K_CUSTOM)
4588 CFeatures* feat=ui_features->get_test_features();
4593 CLabels* labels=ui_classifier->classify();
4599 for (int32_t i=0; i<num_vec; i++)
4603 set_vector(result, num_vec);
4609 bool CSGInterface::cmd_classify_example()
4611 if (m_nrhs!=2 || !create_return_values(1))
4614 int32_t idx=get_int();
4617 if (!ui_classifier->classify_example(idx, result))
4618 SG_ERROR(
"Classify_example failed.\n");
4625 bool CSGInterface::cmd_get_classifier()
4627 if (m_nrhs<1 || m_nrhs>2 || !create_return_values(2))
4641 if (!ui_classifier->get_trained_classifier(
4642 weights, rows, cols, bias, brows, bcols, idx))
4647 set_matrix(bias, brows, bcols);
4652 set_matrix(weights, rows, cols);
4658 bool CSGInterface::cmd_new_classifier()
4660 if (m_nrhs<2 || !create_return_values(0))
4664 char* name=get_str_from_str_or_direct(len);
4670 d=get_int_from_int_or_str();
4673 from_d=get_int_from_int_or_str();
4676 bool success=ui_classifier->new_classifier(name, d, from_d);
4682 bool CSGInterface::cmd_save_classifier()
4684 if (m_nrhs<2 || !create_return_values(0))
4688 char* filename=get_str_from_str_or_direct(len);
4690 bool success=ui_classifier->save(filename);
4696 bool CSGInterface::cmd_load_classifier()
4698 if (m_nrhs<3 || !create_return_values(0))
4702 char* filename=get_str_from_str_or_direct(len);
4703 char* type=get_str_from_str_or_direct(len);
4705 bool success=ui_classifier->load(filename, type);
4713 bool CSGInterface::cmd_get_num_svms()
4715 if (m_nrhs!=1 || !create_return_values(1))
4718 set_int(ui_classifier->get_num_svms());
4724 bool CSGInterface::cmd_get_svm()
4726 return cmd_get_classifier();
4729 bool CSGInterface::cmd_set_svm()
4731 if (m_nrhs!=3 || !create_return_values(0))
4737 int32_t num_feat_alphas=0;
4738 int32_t num_vec_alphas=0;
4739 get_matrix(alphas, num_feat_alphas, num_vec_alphas);
4742 SG_ERROR(
"No proper alphas given.\n");
4743 if (num_vec_alphas!=2)
4744 SG_ERROR(
"Not 2 vectors in alphas.\n");
4746 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4748 SG_ERROR(
"No SVM object available.\n");
4754 for (int32_t i=0; i<num_support_vectors; i++)
4764 bool CSGInterface::cmd_set_linear_classifier()
4766 if (m_nrhs!=3 || !create_return_values(0))
4776 SG_ERROR(
"No proper weight vector given.\n");
4780 SG_ERROR(
"No Linear Classifier object available.\n");
4787 bool CSGInterface::cmd_get_svm_objective()
4789 if (m_nrhs!=1 || !create_return_values(1))
4792 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4801 bool CSGInterface::cmd_compute_svm_primal_objective()
4803 return do_compute_objective(SVM_PRIMAL);
4806 bool CSGInterface::cmd_compute_svm_dual_objective()
4808 return do_compute_objective(SVM_DUAL);
4811 bool CSGInterface::cmd_compute_mkl_dual_objective()
4813 return do_compute_objective(MKL_DUAL);
4816 bool CSGInterface::cmd_compute_relative_mkl_duality_gap()
4818 return do_compute_objective(MKL_RELATIVE_DUALITY_GAP);
4821 bool CSGInterface::cmd_compute_absolute_mkl_duality_gap()
4823 return do_compute_objective(MKL_ABSOLUTE_DUALITY_GAP);
4826 bool CSGInterface::do_compute_objective(E_WHICH_OBJ obj)
4828 if (m_nrhs!=1 || !create_return_values(1))
4833 CSVM* svm=(
CSVM*) ui_classifier->get_classifier();
4838 trainlabels=ui_labels->get_train_labels();
4841 SG_ERROR(
"No trainlabels available.\n");
4843 CKernel* kernel=ui_kernel->get_kernel();
4845 SG_ERROR(
"No kernel available.\n");
4847 if (!ui_kernel->is_initialized() || !kernel->
has_features())
4848 SG_ERROR(
"Kernel not initialized.\n");
4864 result=((
CMKL*) svm)->compute_mkl_primal_objective();
4868 result=((
CMKL*) svm)->compute_mkl_dual_objective();
4870 case MKL_RELATIVE_DUALITY_GAP:
4873 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4874 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4875 result=(primal-dual)/dual;
4878 case MKL_ABSOLUTE_DUALITY_GAP:
4881 float64_t primal=((
CMKL*) svm)->compute_mkl_dual_objective();
4882 float64_t dual=((
CMKL*) svm)->compute_mkl_primal_objective();
4887 SG_SERROR(
"Error calling do_compute_objective\n");
4895 bool CSGInterface::cmd_train_classifier()
4897 if (m_nrhs<1 || !create_return_values(0))
4900 CMachine* classifier=ui_classifier->get_classifier();
4902 SG_ERROR(
"No classifier available.\n");
4922 return ui_classifier->train_svm();
4924 return ui_classifier->train_mkl_multiclass();
4928 return ui_classifier->train_mkl();
4931 return ui_classifier->train_krr();
4938 int32_t k=get_int_from_int_or_str();
4940 return ui_classifier->train_knn(k);
4948 int32_t k=get_int_from_int_or_str();
4949 int32_t max_iter=get_int_from_int_or_str();
4951 return ui_classifier->train_clustering(k, max_iter);
4959 int32_t merges=get_int_from_int_or_str();
4961 return ui_classifier->train_clustering(merges);
4968 gamma=get_real_from_real_or_str();
4970 return ui_classifier->train_linear(gamma);
4983 return ui_classifier->train_linear();
4986 return ui_classifier->train_wdocas();
4989 SG_ERROR(
"Unknown classifier type %d.\n", type);
4995 bool CSGInterface::cmd_do_auc_maximization()
4997 if (m_nrhs!=2 || !create_return_values(0))
5000 bool do_auc=get_bool_from_bool_or_str();
5002 return ui_classifier->set_do_auc_maximization(do_auc);
5005 bool CSGInterface::cmd_set_perceptron_parameters()
5007 if (m_nrhs!=3 || !create_return_values(0))
5010 float64_t lernrate=get_real_from_real_or_str();
5011 int32_t maxiter=get_int_from_int_or_str();
5013 return ui_classifier->set_perceptron_parameters(lernrate, maxiter);
5016 bool CSGInterface::cmd_set_svm_qpsize()
5018 if (m_nrhs!=2 || !create_return_values(0))
5021 int32_t qpsize=get_int_from_int_or_str();
5023 return ui_classifier->set_svm_qpsize(qpsize);
5026 bool CSGInterface::cmd_set_svm_max_qpsize()
5028 if (m_nrhs!=2 || !create_return_values(0))
5031 int32_t max_qpsize=get_int_from_int_or_str();
5033 return ui_classifier->set_svm_max_qpsize(max_qpsize);
5036 bool CSGInterface::cmd_set_svm_bufsize()
5038 if (m_nrhs!=2 || !create_return_values(0))
5041 int32_t bufsize=get_int_from_int_or_str();
5043 return ui_classifier->set_svm_bufsize(bufsize);
5046 bool CSGInterface::cmd_set_svm_C()
5048 if (m_nrhs<2 || !create_return_values(0))
5051 float64_t C1=get_real_from_real_or_str();
5055 C2=get_real_from_real_or_str();
5057 return ui_classifier->set_svm_C(C1, C2);
5060 bool CSGInterface::cmd_set_svm_epsilon()
5062 if (m_nrhs!=2 || !create_return_values(0))
5067 return ui_classifier->set_svm_epsilon(epsilon);
5070 bool CSGInterface::cmd_set_svr_tube_epsilon()
5072 if (m_nrhs!=2 || !create_return_values(0))
5075 float64_t tube_epsilon=get_real_from_real_or_str();
5077 return ui_classifier->set_svr_tube_epsilon(tube_epsilon);
5080 bool CSGInterface::cmd_set_svm_nu()
5082 if (m_nrhs!=2 || !create_return_values(0))
5085 float64_t nu=get_real_from_real_or_str();
5087 return ui_classifier->set_svm_nu(nu);
5090 bool CSGInterface::cmd_set_svm_mkl_parameters()
5092 if (m_nrhs<3 || m_nrhs>4 || !create_return_values(0))
5095 float64_t weight_epsilon=get_real_from_real_or_str();
5096 float64_t C_mkl=get_real_from_real_or_str();
5100 mkl_norm=get_real_from_real_or_str();
5102 return ui_classifier->set_svm_mkl_parameters(weight_epsilon, C_mkl, mkl_norm);
5105 bool CSGInterface::cmd_set_elasticnet_lambda()
5107 if (m_nrhs!=2 || !create_return_values(0))
5109 float64_t lambda=get_real_from_real_or_str();
5110 return ui_classifier->set_elasticnet_lambda(lambda);
5113 bool CSGInterface::cmd_set_mkl_block_norm()
5115 if (m_nrhs!=2 || !create_return_values(0))
5117 float64_t bnorm=get_real_from_real_or_str();
5118 return ui_classifier->set_mkl_block_norm(bnorm);
5122 bool CSGInterface::cmd_set_max_train_time()
5124 if (m_nrhs!=2 || !create_return_values(0))
5127 float64_t max_train_time=get_real_from_real_or_str();
5129 return ui_classifier->set_max_train_time(max_train_time);
5132 bool CSGInterface::cmd_set_svm_shrinking_enabled()
5134 if (m_nrhs!=2 || !create_return_values(0))
5137 bool shrinking_enabled=get_bool_from_bool_or_str();
5139 return ui_classifier->set_svm_shrinking_enabled(shrinking_enabled);
5142 bool CSGInterface::cmd_set_svm_batch_computation_enabled()
5144 if (m_nrhs!=2 || !create_return_values(0))
5147 bool batch_computation_enabled=get_bool_from_bool_or_str();
5149 return ui_classifier->set_svm_batch_computation_enabled(
5150 batch_computation_enabled);
5153 bool CSGInterface::cmd_set_svm_linadd_enabled()
5155 if (m_nrhs!=2 || !create_return_values(0))
5158 bool linadd_enabled=get_bool_from_bool_or_str();
5160 return ui_classifier->set_svm_linadd_enabled(linadd_enabled);
5163 bool CSGInterface::cmd_set_svm_bias_enabled()
5165 if (m_nrhs!=2 || !create_return_values(0))
5168 bool bias_enabled=get_bool_from_bool_or_str();
5170 return ui_classifier->set_svm_bias_enabled(bias_enabled);
5173 bool CSGInterface::cmd_set_mkl_interleaved_enabled()
5175 if (m_nrhs!=2 || !create_return_values(0))
5178 bool interleaved_enabled=get_bool_from_bool_or_str();
5180 return ui_classifier->set_mkl_interleaved_enabled(interleaved_enabled);
5183 bool CSGInterface::cmd_set_krr_tau()
5185 if (m_nrhs!=2 || !create_return_values(0))
5188 float64_t tau=get_real_from_real_or_str();
5190 return ui_classifier->set_krr_tau(tau);
5196 bool CSGInterface::cmd_add_preproc()
5198 if (m_nrhs<2 || !create_return_values(0))
5202 char* type=get_str_from_str_or_direct(len);
5205 if (strmatch(type,
"NORMONE"))
5206 preproc=ui_preproc->create_generic(
P_NORMONE);
5207 else if (strmatch(type,
"LOGPLUSONE"))
5209 else if (strmatch(type,
"SORTWORDSTRING"))
5211 else if (strmatch(type,
"SORTULONGSTRING"))
5213 else if (strmatch(type,
"DECOMPRESSCHARSTRING"))
5215 else if (strmatch(type,
"SORTWORD"))
5216 preproc=ui_preproc->create_generic(
P_SORTWORD);
5218 else if (strmatch(type,
"PRUNEVARSUBMEAN"))
5220 bool divide_by_std=
false;
5222 divide_by_std=get_bool_from_bool_or_str();
5224 preproc=ui_preproc->create_prunevarsubmean(divide_by_std);
5228 else if (strmatch(type,
"PCA") && m_nrhs==4)
5230 bool do_whitening=get_bool_from_bool_or_str();
5231 float64_t threshold=get_real_from_real_or_str();
5233 preproc=ui_preproc->create_pca(do_whitening, threshold);
5241 return ui_preproc->add_preproc(preproc);
5244 bool CSGInterface::cmd_del_preproc()
5246 if (m_nrhs!=1 || !create_return_values(0))
5249 return ui_preproc->del_preproc();
5252 bool CSGInterface::cmd_attach_preproc()
5254 if (m_nrhs<2 || !create_return_values(0))
5258 char* target=get_str_from_str_or_direct(len);
5260 bool do_force=
false;
5262 do_force=get_bool_from_bool_or_str();
5264 bool success=ui_preproc->attach_preproc(target, do_force);
5270 bool CSGInterface::cmd_clean_preproc()
5272 if (m_nrhs!=1 || !create_return_values(0))
5275 return ui_preproc->clean_preproc();
5280 bool CSGInterface::cmd_set_converter()
5283 char* type=get_str_from_str_or_direct(len);
5285 if (strmatch(type,
"lle"))
5287 int32_t k = get_int_from_int_or_str();
5288 ui_converter->create_locallylinearembedding(k);
5291 if (strmatch(type,
"npe"))
5293 int32_t k = get_int_from_int_or_str();
5294 ui_converter->create_neighborhoodpreservingembedding(k);
5297 if (strmatch(type,
"ltsa"))
5299 int32_t k = get_int_from_int_or_str();
5300 ui_converter->create_localtangentspacealignment(k);
5303 if (strmatch(type,
"lltsa"))
5305 int32_t k = get_int_from_int_or_str();
5306 ui_converter->create_linearlocaltangentspacealignment(k);
5309 if (strmatch(type,
"hlle"))
5311 int32_t k = get_int_from_int_or_str();
5312 ui_converter->create_hessianlocallylinearembedding(k);
5315 if (strmatch(type,
"laplacian_eigenmaps"))
5317 int32_t k = get_int_from_int_or_str();
5318 int32_t width = get_real_from_real_or_str();
5319 ui_converter->create_laplacianeigenmaps(k,width);
5322 if (strmatch(type,
"lpp"))
5324 int32_t k = get_int_from_int_or_str();
5325 int32_t width = get_real_from_real_or_str();
5326 ui_converter->create_localitypreservingprojections(k,width);
5329 if (strmatch(type,
"diffusion_maps"))
5331 int32_t t = get_int_from_int_or_str();
5332 int32_t width = get_real_from_real_or_str();
5333 ui_converter->create_diffusionmaps(t,width);
5336 if (strmatch(type,
"isomap"))
5338 int32_t k = get_int_from_int_or_str();
5339 ui_converter->create_isomap(k);
5342 if (strmatch(type,
"mds"))
5344 ui_converter->create_multidimensionalscaling();
5350 bool CSGInterface::cmd_embed()
5352 int32_t target_dim = get_int_from_int_or_str();
5361 bool CSGInterface::cmd_new_plugin_estimator()
5363 if (m_nrhs<2 || !create_return_values(0))
5366 float64_t pos_pseudo=get_real_from_real_or_str();
5367 float64_t neg_pseudo=get_real_from_real_or_str();
5369 return ui_pluginestimate->new_estimator(pos_pseudo, neg_pseudo);
5372 bool CSGInterface::cmd_train_estimator()
5374 if (m_nrhs!=1 || !create_return_values(0))
5377 return ui_pluginestimate->train();
5380 bool CSGInterface::cmd_plugin_estimate_classify_example()
5382 if (m_nrhs!=2 || !create_return_values(1))
5385 int32_t idx=get_int();
5386 float64_t result=ui_pluginestimate->apply_one(idx);
5388 set_vector(&result, 1);
5392 bool CSGInterface::cmd_plugin_estimate_classify()
5394 if (m_nrhs!=1 || !create_return_values(1))
5397 CFeatures* feat=ui_features->get_test_features();
5403 CLabels* labels=ui_pluginestimate->apply();
5404 for (int32_t i=0; i<num_vec; i++)
5408 set_vector(result, num_vec);
5414 bool CSGInterface::cmd_set_plugin_estimate()
5416 if (m_nrhs!=3 || !create_return_values(0))
5420 int32_t num_probs=0;
5422 get_matrix(emission_probs, num_probs, num_vec);
5425 SG_ERROR(
"Need at least 1 set of positive and 1 set of negative params.\n");
5428 float64_t* neg_params=&(emission_probs[num_probs]);
5432 get_vector(model_sizes, len);
5434 int32_t seq_length=(int32_t) model_sizes[0];
5435 int32_t num_symbols=(int32_t) model_sizes[1];
5436 if (num_probs!=seq_length*num_symbols)
5437 SG_ERROR(
"Mismatch in number of emission probs and sequence length * number of symbols.\n");
5439 ui_pluginestimate->get_estimator()->set_model_params(
5440 pos_params, neg_params, seq_length, num_symbols);
5445 bool CSGInterface::cmd_get_plugin_estimate()
5447 if (m_nrhs!=1 || !create_return_values(2))
5452 int32_t num_params=0;
5453 int32_t seq_length=0;
5454 int32_t num_symbols=0;
5456 if (!ui_pluginestimate->get_estimator()->get_model_params(
5457 pos_params, neg_params, seq_length, num_symbols))
5460 num_params=seq_length*num_symbols;
5463 for (int32_t i=0; i<num_params; i++)
5464 result[i]=pos_params[i];
5465 for (int32_t i=0; i<num_params; i++)
5466 result[i+num_params]=neg_params[i];
5468 set_matrix(result, num_params, 2);
5474 set_vector(model_sizes, 2);
5479 bool CSGInterface::cmd_convergence_criteria()
5481 if (m_nrhs<3 || !create_return_values(0))
5484 int32_t num_iterations=get_int_from_int_or_str();
5487 return ui_hmm->convergence_criteria(num_iterations, epsilon);
5490 bool CSGInterface::cmd_normalize()
5492 if (m_nrhs<2 || !create_return_values(0))
5495 bool keep_dead_states=get_bool_from_bool_or_str();
5497 return ui_hmm->normalize(keep_dead_states);
5500 bool CSGInterface::cmd_add_states()
5502 if (m_nrhs<3 || !create_return_values(0))
5505 int32_t num_states=get_int_from_int_or_str();
5506 float64_t value=get_real_from_real_or_str();
5508 return ui_hmm->add_states(num_states, value);
5511 bool CSGInterface::cmd_permutation_entropy()
5513 if (m_nrhs<3 || !create_return_values(0))
5516 int32_t width=get_int_from_int_or_str();
5517 int32_t seq_num=get_int_from_int_or_str();
5519 return ui_hmm->permutation_entropy(width, seq_num);
5522 bool CSGInterface::cmd_relative_entropy()
5524 if (m_nrhs!=1 || !create_return_values(1))
5529 bool success=ui_hmm->relative_entropy(entropy, len);
5533 set_vector(entropy, len);
5539 bool CSGInterface::cmd_entropy()
5541 if (m_nrhs!=1 || !create_return_values(1))
5546 bool success=ui_hmm->entropy(entropy, len);
5550 set_vector(entropy, len);
5556 bool CSGInterface::cmd_hmm_classify()
5558 return do_hmm_classify(
false,
false);
5561 bool CSGInterface::cmd_one_class_hmm_classify()
5563 return do_hmm_classify(
false,
true);
5566 bool CSGInterface::cmd_one_class_linear_hmm_classify()
5568 return do_hmm_classify(
true,
true);
5571 bool CSGInterface::do_hmm_classify(
bool linear,
bool one_class)
5573 if (m_nrhs>1 || !create_return_values(1))
5576 CFeatures* feat=ui_features->get_test_features();
5585 labels=ui_hmm->linear_one_class_classify();
5590 labels=ui_hmm->one_class_classify();
5592 labels=ui_hmm->classify();
5598 for (int32_t i=0; i<num_vec; i++)
5602 set_vector(result, num_vec);
5608 bool CSGInterface::cmd_one_class_hmm_classify_example()
5610 return do_hmm_classify_example(
true);
5613 bool CSGInterface::cmd_hmm_classify_example()
5615 return do_hmm_classify_example(
false);
5618 bool CSGInterface::do_hmm_classify_example(
bool one_class)
5620 if (m_nrhs!=2 || !create_return_values(1))
5623 int32_t idx=get_int();
5627 result=ui_hmm->one_class_classify_example(idx);
5629 result=ui_hmm->classify_example(idx);
5636 bool CSGInterface::cmd_output_hmm()
5638 if (m_nrhs!=1 || !create_return_values(0))
5641 return ui_hmm->output_hmm();
5644 bool CSGInterface::cmd_output_hmm_defined()
5646 if (m_nrhs!=1 || !create_return_values(0))
5649 return ui_hmm->output_hmm_defined();
5652 bool CSGInterface::cmd_hmm_likelihood()
5654 if (m_nrhs!=1 || !create_return_values(1))
5657 CHMM* h=ui_hmm->get_current();
5662 set_real(likelihood);
5667 bool CSGInterface::cmd_likelihood()
5669 if (m_nrhs!=1 || !create_return_values(0))
5672 return ui_hmm->likelihood();
5675 bool CSGInterface::cmd_save_likelihood()
5677 if (m_nrhs<2 || !create_return_values(0))
5681 char* filename=get_str_from_str_or_direct(len);
5683 bool is_binary=
false;
5685 is_binary=get_bool_from_bool_or_str();
5687 bool success=ui_hmm->save_likelihood(filename, is_binary);
5693 bool CSGInterface::cmd_get_viterbi_path()
5695 if (m_nrhs!=2 || !create_return_values(2))
5698 int32_t dim=get_int();
5701 CHMM* h=ui_hmm->get_current();
5705 CFeatures* feat=ui_features->get_test_features();
5715 if (!vec || num_feat<=0)
5722 SG_DEBUG(
"computing viterbi path for vector %d (length %d)\n", dim, num_feat);
5726 set_vector(path, num_feat);
5728 set_real(likelihood);
5733 bool CSGInterface::cmd_viterbi_train()
5735 if (m_nrhs!=1 || !create_return_values(0))
5738 return ui_hmm->viterbi_train();
5741 bool CSGInterface::cmd_viterbi_train_defined()
5743 if (m_nrhs!=1 || !create_return_values(0))
5746 return ui_hmm->viterbi_train_defined();
5749 bool CSGInterface::cmd_baum_welch_train()
5751 if (m_nrhs!=1 || !create_return_values(0))
5754 return ui_hmm->baum_welch_train();
5757 bool CSGInterface::cmd_baum_welch_train_defined()
5759 if (m_nrhs!=1 || !create_return_values(0))
5762 return ui_hmm->baum_welch_train_defined();
5766 bool CSGInterface::cmd_baum_welch_trans_train()
5768 if (m_nrhs!=1 || !create_return_values(0))
5771 return ui_hmm->baum_welch_trans_train();
5774 bool CSGInterface::cmd_linear_train()
5776 if (m_nrhs<1 || !create_return_values(0))
5782 char* align=get_str_from_str_or_direct(len);
5784 bool success=ui_hmm->linear_train(align[0]);
5790 return ui_hmm->linear_train();
5793 bool CSGInterface::cmd_save_path()
5795 if (m_nrhs<2 || !create_return_values(0))
5799 char* filename=get_str_from_str_or_direct(len);
5801 bool is_binary=
false;
5803 is_binary=get_bool_from_bool_or_str();
5805 bool success=ui_hmm->save_path(filename, is_binary);
5811 bool CSGInterface::cmd_append_hmm()
5813 if (m_nrhs!=5 || !create_return_values(0))
5816 CHMM* old_h=ui_hmm->get_current();
5831 get_matrix(a, M_a, N_a);
5837 get_matrix(b, M_b, N_b);
5840 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
5842 SG_ERROR(
"Model matrices not matching in size.\n"
5843 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
5844 N_p, N_q, N_a, M_a, N_b, M_b);
5847 CHMM* h=
new CHMM(N, M, NULL, ui_hmm->get_pseudo());
5858 h->
set_a(i,j, a[i+j*N]);
5862 h->
set_b(i,j, b[i+j*N]);
5870 bool CSGInterface::cmd_append_model()
5872 if (m_nrhs<2 || !create_return_values(0))
5874 if (m_nrhs>2 && m_nrhs!=4)
5878 char* filename=get_str_from_str_or_direct(len);
5883 base1=get_int_from_int_or_str();
5884 base2=get_int_from_int_or_str();
5887 bool success=ui_hmm->append_model(filename, base1, base2);
5893 bool CSGInterface::cmd_new_hmm()
5895 if (m_nrhs!=3 || !create_return_values(0))
5898 int32_t n=get_int_from_int_or_str();
5899 int32_t m=get_int_from_int_or_str();
5901 return ui_hmm->new_hmm(n, m);
5904 bool CSGInterface::cmd_load_hmm()
5906 if (m_nrhs!=2 || !create_return_values(0))
5910 char* filename=get_str_from_str_or_direct(len);
5912 bool success=ui_hmm->load(filename);
5918 bool CSGInterface::cmd_save_hmm()
5920 if (m_nrhs<2 || !create_return_values(0))
5924 char* filename=get_str_from_str_or_direct(len);
5926 bool is_binary=
false;
5928 is_binary=get_bool_from_bool_or_str();
5930 bool success=ui_hmm->save(filename, is_binary);
5936 bool CSGInterface::cmd_set_hmm()
5938 if (m_nrhs!=5 || !create_return_values(0))
5952 get_matrix(a, M_a, N_a);
5958 get_matrix(b, M_b, N_b);
5961 if (N_p!=N || N_q!=N || N_a!=N || M_a!=N || N_b!=M || M_b!=N)
5963 SG_ERROR(
"Model matrices not matching in size.\n"
5964 "p:(%d) q:(%d) a:(%d,%d) b(%d,%d)\n",
5965 N_p, N_q, N_a, M_a, N_b, M_b);
5968 CHMM* current=ui_hmm->get_current();
5970 SG_ERROR(
"Need a previously created HMM.\n");
5976 current->
set_p(i, p[i]);
5977 current->
set_q(i, q[i]);
5982 current->
set_a(i,j, a[i+j*N]);
5986 current->
set_b(i,j, b[i+j*N]);
5994 bool CSGInterface::cmd_set_hmm_as()
5996 if (m_nrhs!=2 || !create_return_values(0))
6000 char* target=get_str_from_str_or_direct(len);
6002 bool success=ui_hmm->set_hmm_as(target);
6008 bool CSGInterface::cmd_set_chop()
6010 if (m_nrhs!=2 || !create_return_values(0))
6013 float64_t value=get_real_from_real_or_str();
6014 return ui_hmm->chop(value);
6017 bool CSGInterface::cmd_set_pseudo()
6019 if (m_nrhs!=2 || !create_return_values(0))
6022 float64_t value=get_real_from_real_or_str();
6023 return ui_hmm->set_pseudo(value);
6026 bool CSGInterface::cmd_load_definitions()
6028 if (m_nrhs<2 || !create_return_values(0))
6032 char* filename=get_str_from_str_or_direct(len);
6036 do_init=get_bool_from_bool_or_str();
6038 bool success=ui_hmm->load_definitions(filename, do_init);
6044 bool CSGInterface::cmd_get_hmm()
6046 if (m_nrhs!=1 || !create_return_values(4))
6049 CHMM* h=ui_hmm->get_current();
6053 int32_t N=h->
get_N();
6054 int32_t M=h->
get_M();
6074 a[i+j*N]=h->
get_a(i, j);
6075 set_matrix(a, N, N);
6081 b[i+j*N]=h->
get_b(i, j);
6082 set_matrix(b, N, M);
6088 bool CSGInterface::cmd_best_path()
6090 if (m_nrhs!=3 || !create_return_values(0))
6093 int32_t from=get_int_from_int_or_str();
6094 int32_t to=get_int_from_int_or_str();
6096 return ui_hmm->best_path(from, to);
6099 bool CSGInterface::cmd_best_path_2struct()
6101 if (m_nrhs!=12 || !create_return_values(3))
6104 SG_ERROR(
"Sorry, this parameter list is awful!\n");
6109 void CSGInterface::get_vector(
bool*& vector, int32_t& len)
6111 int32_t* int_vector;
6112 get_vector(int_vector, len);
6117 for (int32_t i=0; i<len; i++)
6118 vector[i]= (int_vector[i]!=0);
6123 void CSGInterface::set_vector(
const bool* vector, int32_t len)
6125 int32_t* int_vector =
SG_MALLOC(int32_t, len);
6126 for (int32_t i=0;i<len;i++)
6133 set_vector(int_vector,len);
6137 bool CSGInterface::cmd_set_plif_struct()
6142 get_vector(ids,Nid);
6148 get_string_list(names, Nname,Mname);
6154 get_matrix(all_limits, Mlimits, Nlimits);
6157 int32_t Npenalties=0;
6158 int32_t Mpenalties=0;
6160 get_matrix(all_penalties, Mpenalties, Npenalties);
6163 int32_t Ntransform=0;
6164 int32_t Mtransform=0;
6166 get_string_list(all_transform, Ntransform, Mtransform);
6171 get_vector(min_values,Nmin);
6176 get_vector(max_values,Nmax);
6180 bool* all_use_cache;
6181 get_vector(all_use_cache,Ncache);
6185 int32_t* all_use_svm;
6186 get_vector(all_use_svm,Nsvm);
6191 get_vector(all_do_calc,Ncalc);
6194 SG_ERROR(
"Ncalc!=Nsvm, Ncalc:%i, Nsvm:%i\n",Ncalc,Nsvm);
6196 SG_ERROR(
"Ncalc!=Ncache, Ncalc:%i, Ncache:%i\n",Ncalc,Ncache);
6197 if (Ncalc!=Ntransform)
6198 SG_ERROR(
"Ncalc!=Ntransform, Ncalc:%i, Ntransform:%i\n",Ncalc,Ntransform);
6200 SG_ERROR(
"Ncalc!=Nmin, Ncalc:%i, Nmin:%i\n",Ncalc,Nmin);
6202 SG_ERROR(
"Ncalc!=Nmax, Ncalc:%i, Nmax:%i\n",Ncalc,Nmax);
6203 if (Ncalc!=Npenalties)
6204 SG_ERROR(
"Ncalc!=Npenalties, Ncalc:%i, Npenalties:%i\n",Ncalc,Npenalties);
6206 SG_ERROR(
"Ncalc!=Nlimits, Ncalc:%i, Nlimits:%i\n",Ncalc,Nlimits);
6208 SG_ERROR(
"Ncalc!=Nname, Ncalc:%i, Nname:%i\n",Ncalc,Nname);
6210 SG_ERROR(
"Ncalc!=Nid, Ncalc:%i, Nid:%i\n",Ncalc,Nid);
6211 if (Mlimits!=Mpenalties)
6212 SG_ERROR(
"Mlimits!=Mpenalties, Mlimits:%i, Mpenalties:%i\n",Mlimits,Mpenalties);
6215 int32_t M = Mlimits;
6235 bool CSGInterface::cmd_get_plif_struct()
6250 bool* all_use_cache =
SG_MALLOC(
bool, N);
6251 int32_t* all_use_svm =
SG_MALLOC(int32_t, N);
6253 for (int32_t i=0;i<N;i++)
6257 names[i].
slen = strlen(PEN[i]->get_plif_name());
6260 for (int32_t j=0;j<M;j++)
6262 all_limits[i*M+j]=limits[j];
6263 all_penalties[i*M+j]=penalties[j];
6265 all_transform[i].
string = (
char*) PEN[i]->get_transform_type();
6266 all_transform[i].
slen = strlen(PEN[i]->get_transform_type());
6275 set_string_list(names, N);
6276 set_matrix(all_limits, M, N);
6277 set_matrix(all_penalties, M, N);
6278 set_string_list(all_transform, N);
6279 set_vector(min_values,N);
6280 set_vector(max_values,N);
6281 set_vector(all_use_cache,N);
6282 set_vector(all_use_svm,N);
6283 set_vector(all_do_calc,N);
6311 bool CSGInterface::cmd_signals_set_positions()
6315 bool CSGInterface::cmd_signals_set_labels()
6319 bool CSGInterface::cmd_signals_set_split()
6323 bool CSGInterface::cmd_signals_set_train_mask()
6327 bool CSGInterface::cmd_signals_add_feature()
6331 bool CSGInterface::cmd_signals_add_kernel()
6335 bool CSGInterface::cmd_signals_run()
6340 bool CSGInterface::cmd_init_dyn_prog()
6343 int32_t num_svms=get_int();
6346 ui_structure->set_dyn_prog(h);
6350 bool CSGInterface::cmd_clean_up_dyn_prog()
6352 return ui_structure->cleanup();
6355 bool CSGInterface::cmd_set_model()
6360 CDynProg* h = ui_structure->get_dyn_prog();
6371 get_ndarray(penalties_array,Dim,numDim);
6376 SG_ERROR(
"error computing plif matrix\n");
6377 ui_structure->set_num_states(Dim[0]);
6382 bool use_orf = get_bool();
6383 ui_structure->set_use_orf(use_orf);
6390 get_matrix(mod_words, Nmod,Mmod);
6391 if (Nmod != num_svms)
6392 SG_ERROR(
"should be equal: Nmod: %i, num_svms: %i\n",Nmod,num_svms);
6398 int32_t num_states=0;
6399 int32_t feat_dim3=0;
6400 int32_t* state_signals;
6401 get_matrix(state_signals,num_states,feat_dim3);
6402 ASSERT(num_states==Dim[0]);
6411 get_matrix(orf_info,Norf,Morf);
6415 ui_structure->set_orf_info(orf_info, Norf, Morf);
6423 bool CSGInterface::cmd_precompute_content_svms()
6429 seq = get_string(seq_len);
6435 get_vector(all_pos, Npos);
6442 get_matrix(weights, Nweights, num_svms);
6444 SG_PRINT(
"Dimension mismatch: got %i, expect %i\n", Nweights, 5440) ;
6445 ui_structure->set_content_svm_weights(weights, Nweights, num_svms);
6447 CDynProg* h = ui_structure->get_dyn_prog();
6449 SG_ERROR(
"no DynProg object found, use init_dyn_prog first\n");
6462 SG_DEBUG(
"precompute_content_svms done\n");
6466 bool CSGInterface::cmd_get_lin_feat()
6468 CDynProg* h = ui_structure->get_dyn_prog();
6470 SG_ERROR(
"no DynProg object found, use set_model first\n");
6473 int32_t dim1, dim2 = 0;
6476 set_matrix(lin_feat, dim1, dim2);
6480 bool CSGInterface::cmd_set_lin_feat()
6485 seq = get_string(Nseq);
6491 get_vector(all_pos, Npos);
6495 int32_t num_svms, seq_len;
6497 get_matrix(lin_feat, num_svms, seq_len);
6501 SG_ERROR(
"Dimension mismatch: got %i positions and (%ix%i) values\n", Npos, num_svms, seq_len) ;
6510 CDynProg* h = ui_structure->get_dyn_prog();
6512 SG_ERROR(
"no DynProg object found, use set_model first\n");
6524 bool CSGInterface::cmd_long_transition_settings()
6526 bool use_long_transitions = get_bool();
6527 int32_t threshold = get_int();
6528 int32_t max_len = get_int();
6530 CDynProg* h = ui_structure->get_dyn_prog();
6532 SG_ERROR(
"no DynProg object found, use set_model first\n");
6538 bool CSGInterface::cmd_set_feature_matrix()
6540 int32_t num_states = ui_structure->get_num_states();
6547 get_ndarray(features, Dims, numDims);
6550 SG_ERROR(
"expected a 3 dimensional array, got %i dimensions\n", numDims);
6551 if (Dims[0]!=num_states)
6552 SG_ERROR(
"number of rows (%i) not equal number of states (%i)\n",Dims[0], num_states);
6553 ASSERT(ui_structure->set_feature_matrix(features, Dims));
6555 ASSERT(ui_structure->set_feature_dims(Dims));
6562 bool CSGInterface::cmd_set_feature_matrix_sparse()
6564 int32_t num_pos = ui_structure->get_num_positions();
6565 int32_t num_states = ui_structure->get_num_states();
6569 int32_t dim11, dim12 ;
6571 get_sparse_matrix(features1, dim11, dim12);
6573 int32_t dim21, dim22 ;
6575 get_sparse_matrix(features2, dim21, dim22);
6585 ASSERT(Dims[0]==num_states)
6588 ASSERT(ui_structure->set_feature_matrix_sparse(features1, features2, Dims));
6589 ASSERT(ui_structure->set_feature_dims(Dims));
6597 bool CSGInterface::cmd_init_intron_list()
6600 int32_t Nstart_positions;
6601 int32_t* start_positions;
6602 get_vector(start_positions, Nstart_positions);
6606 int32_t Nend_positions;
6607 int32_t* end_positions;
6608 get_vector(end_positions, Nend_positions);
6614 get_vector(quality, Nquality);
6620 get_vector(all_pos, Nall_pos);
6623 ASSERT(Nquality==Nend_positions);
6624 ASSERT(Nend_positions==Nstart_positions);
6628 intron_list->
init_list(all_pos, Nall_pos);
6630 intron_list->
read_introns(start_positions, end_positions, quality, Nstart_positions);
6643 CDynProg* h = ui_structure->get_dyn_prog();
6645 SG_ERROR(
"no DynProg object found, use set_model first\n");
6651 bool CSGInterface::cmd_precompute_tiling_features()
6655 CDynProg* h = ui_structure->get_dyn_prog();
6657 int32_t Nintensities=0;
6659 get_vector(intensities, Nintensities);
6661 int32_t Nprobe_pos=0;
6663 get_vector(probe_pos, Nprobe_pos);
6664 ASSERT(Nprobe_pos==Nintensities);
6666 int32_t Ntiling_plif_ids=0;
6667 int32_t* tiling_plif_ids;
6668 get_vector(tiling_plif_ids, Ntiling_plif_ids);
6675 bool CSGInterface::cmd_best_path_trans()
6677 CDynProg* h = ui_structure->get_dyn_prog();
6684 int32_t* feat_dims = ui_structure->get_feature_dims();
6685 float64_t* features = (ui_structure->get_feature_matrix(
false));
6688 int32_t* orf_info = ui_structure->get_orf_info();
6689 bool use_orf = ui_structure->get_use_orf();
6698 SG_ERROR(
"# transitions from initial state (%i) does not match # states (%i)\n", Np, num_states);
6706 SG_ERROR(
"# transitions to end state (%i) does not match # states (%i)\n", Nq, num_states);
6712 get_vector(all_nbest, Nnbest);
6717 nbest =all_nbest[0];
6718 nother=all_nbest[1];
6721 nbest =all_nbest[0];
6728 int32_t Nseg_path=0;
6729 int32_t Mseg_path=0;
6731 get_matrix(seg_path, Nseg_path, Mseg_path);
6736 int32_t num_a_trans=0;
6738 get_matrix(a_trans, num_a_trans, Na_trans);
6747 get_matrix(loss, Nloss,Mloss);
6773 SG_ERROR(
"svm arrays inconsistent\n") ;
6778 SG_DEBUG(
"best_path_trans: M: %i, Mseg_path: %i\n", M, Mseg_path);
6795 bool segment_loss_non_zero=
false;
6796 for (int32_t i=0; i<Nloss*Mloss; i++)
6799 segment_loss_non_zero=
true;
6809 if (segment_loss_non_zero)
6811 SG_DEBUG(
"Using version with segment_loss\n") ;
6819 SG_DEBUG(
"Using version without segment_loss\n") ;
6836 for (int32_t k=0; k<(nbest+nother); k++)
6838 for (int32_t i=0; i<M; i++)
6840 d_my_path[i*(nbest+nother)+k] = states.
matrix[i+k*M] ;
6841 d_my_pos[i*(nbest+nother)+k] = my_pos.
matrix[i+k*M] ;
6844 set_vector(p_prob.
vector,nbest+nother);
6845 set_vector(d_my_path, (nbest+nother)*M);
6846 set_vector(d_my_pos, (nbest+nother)*M);
6855 bool CSGInterface::cmd_best_path_trans_deriv()
6857 int32_t num_states = ui_structure->get_num_states();
6858 int32_t* feat_dims = ui_structure->get_feature_dims();
6859 float64_t* features = (ui_structure->get_feature_matrix(
false));
6871 SG_ERROR(
"Np!=num_states; Np:%i num_states:%i",Np,num_states);
6879 SG_ERROR(
"Nq!=num_states; Nq:%i num_states:%i",Nq,num_states);
6886 int32_t Nseg_path=0;
6887 int32_t Mseg_path=0;
6889 get_matrix(seg_path,Nseg_path,Mseg_path);
6894 int32_t num_a_trans=0;
6896 get_matrix(a_trans, num_a_trans, Na_trans);
6905 get_matrix(loss, Nloss,Mloss);
6909 int32_t Nmystate_seq=0;
6910 int32_t* mystate_seq=NULL;
6911 get_vector(mystate_seq, Nmystate_seq);
6915 int32_t Nmypos_seq=0;
6916 int32_t* mypos_seq=NULL;
6917 get_vector(mypos_seq, Nmypos_seq);
6922 int32_t max_plif_id = 0 ;
6923 int32_t max_plif_len = 1 ;
6924 for (int32_t i=0; i<Nplif; i++)
6926 if (i>0 && PEN[i]->get_id()!=i)
6927 SG_ERROR(
"PEN[i]->get_id()!=i; PEN[%i]->get_id():%i ,\n",i, PEN[i]->get_id());
6930 if (PEN[i]->get_plif_len()>max_plif_len)
6935 CDynProg* h = ui_structure->get_dyn_prog();
6947 SG_ERROR(
"svm arrays inconsistent\n") ;
6949 int32_t *my_path =
SG_MALLOC(int32_t, Nmypos_seq+1);
6950 memset(my_path, -1, Nmypos_seq*
sizeof(int32_t)) ;
6951 int32_t *my_pos =
SG_MALLOC(int32_t, Nmypos_seq+1);
6952 memset(my_pos, -1, Nmypos_seq*
sizeof(int32_t)) ;
6955 for (int32_t i=0; i<Nmypos_seq; i++)
6957 my_path[i] = mystate_seq[i] ;
6958 my_pos[i] = mypos_seq[i] ;
6992 for (int32_t i=0; i<num_states; i++)
6994 for (int32_t j=0; j<num_states; j++)
6995 p_A_deriv[i+j*num_states] = h->
get_a_deriv(i, j) ;
7001 for (int32_t
id=0;
id<=max_plif_id;
id++)
7005 ASSERT(len<=max_plif_len) ;
7006 for (int32_t j=0; j<max_plif_len; j++)
7007 a_Plif_deriv.
element(
id, j)= deriv[j] ;
7010 set_vector(p_p_deriv, num_states);
7011 set_vector(p_q_deriv, num_states);
7012 set_matrix(p_A_deriv, num_states, num_states);
7013 set_matrix(p_Plif_deriv, (max_plif_id+1), max_plif_len);
7014 set_vector(p_my_scores, Nmypos_seq);
7015 set_vector(p_my_losses, Nmypos_seq);
7037 bool CSGInterface::cmd_precompute_subkernels()
7039 if (m_nrhs!=1 || !create_return_values(0))
7042 return ui_kernel->precompute_subkernels();
7044 bool CSGInterface::cmd_crc()
7046 if (m_nrhs!=2 || !create_return_values(1))
7050 char*
string=get_string(slen);
7052 uint8_t* bstring=
SG_MALLOC(uint8_t, slen);
7054 for (int32_t i=0; i<slen; i++)
7055 bstring[i]=
string[i];
7065 bool CSGInterface::cmd_system()
7067 if (m_nrhs<2 || !create_return_values(0))
7072 memset(command, 0,
sizeof(
char)*10000);
7073 char* cmd=get_str_from_str_or_direct(len);
7074 strncat(command, cmd, 10000);
7077 while (m_rhs_counter<m_nrhs)
7079 strncat(command,
" ", 10000);
7080 char* arg=get_str_from_str_or_direct(len);
7081 strncat(command, arg, 10000);
7085 int32_t success=system(command);
7087 return (success==0);
7090 bool CSGInterface::cmd_exit()
7096 bool CSGInterface::cmd_exec()
7098 if (m_nrhs<2 || !create_return_values(0))
7102 char* filename=get_str_from_str_or_direct(len);
7103 FILE* file=fopen(filename,
"r");
7107 SG_ERROR(
"Error opening file: %s.\n", filename);
7120 bool CSGInterface::cmd_set_output()
7122 if (m_nrhs<2 || !create_return_values(0))
7126 char* filename=get_str_from_str_or_direct(len);
7132 SG_INFO(
"Setting output file to: %s.\n", filename);
7134 if (strmatch(filename,
"STDERR"))
7135 io->set_target(stderr);
7136 else if (strmatch(filename,
"STDOUT"))
7137 io->set_target(stdout);
7140 file_out=fopen(filename,
"w");
7142 SG_ERROR(
"Error opening output file %s.\n", filename);
7143 io->set_target(file_out);
7149 bool CSGInterface::cmd_set_threshold()
7151 if (m_nrhs!=2 || !create_return_values(0))
7154 float64_t value=get_real_from_real_or_str();
7156 ui_math->set_threshold(value);
7160 bool CSGInterface::cmd_init_random()
7162 if (m_nrhs!=2 || !create_return_values(0))
7165 uint32_t initseed=(uint32_t) get_int_from_int_or_str();
7166 ui_math->init_random(initseed);
7171 bool CSGInterface::cmd_set_num_threads()
7173 if (m_nrhs!=2 || !create_return_values(0))
7176 int32_t num_threads=get_int_from_int_or_str();
7178 parallel->set_num_threads(num_threads);
7179 SG_INFO(
"Set number of threads to %d.\n", num_threads);
7184 bool CSGInterface::cmd_translate_string()
7186 if (m_nrhs!=4 || !create_return_values(1))
7191 get_vector(
string, len);
7193 int32_t order=get_int();
7194 int32_t start=get_int();
7196 const int32_t max_val=2;
7200 for (i=0; i<len; i++)
7202 switch ((
char)
string[i])
7204 case 'A': obs[i]=0;
break;
7205 case 'C': obs[i]=1;
break;
7206 case 'G': obs[i]=2;
break;
7207 case 'T': obs[i]=3;
break;
7208 case 'a': obs[i]=0;
break;
7209 case 'c': obs[i]=1;
break;
7210 case 'g': obs[i]=2;
break;
7211 case 't': obs[i]=3;
break;
7212 default:
SG_ERROR(
"Wrong letter in string.\n");
7217 for (i=len-1; i>=order-1; i--)
7220 for (j=i; j>=i-order+1; j--)
7221 value=(value>>max_val) | ((obs[j])<<(max_val*(order-1)));
7223 obs[i]=(uint16_t) value;
7226 for (i=order-2;i>=0;i--)
7229 for (j=i; j>=i-order+1; j--)
7231 value= (value >> max_val);
7233 value|=(obs[j]) << (max_val * (order-1));
7239 for (i=start; i<len; i++)
7243 set_vector(real_obs, len);
7249 bool CSGInterface::cmd_clear()
7276 bool CSGInterface::cmd_tic()
7282 bool CSGInterface::cmd_toc()
7288 bool CSGInterface::cmd_print()
7290 if (m_nrhs<2 || !create_return_values(0))
7294 char* msg=get_str_from_str_or_direct(len);
7302 bool CSGInterface::cmd_echo()
7304 if (m_nrhs<2 || !create_return_values(0))
7308 char* level=get_str_from_str_or_direct(len);
7310 if (strmatch(level,
"OFF"))
7325 bool CSGInterface::cmd_loglevel()
7327 if (m_nrhs<2 || !create_return_values(0))
7331 char* level=get_str_from_str_or_direct(len);
7333 if (strmatch(level,
"ALL") || strmatch(level,
"GCDEBUG"))
7335 else if (strmatch(level,
"DEBUG"))
7337 else if (strmatch(level,
"INFO"))
7339 else if (strmatch(level,
"NOTICE"))
7341 else if (strmatch(level,
"WARN"))
7343 else if (strmatch(level,
"ERROR"))
7345 else if (strmatch(level,
"CRITICAL"))
7347 else if (strmatch(level,
"ALERT"))
7349 else if (strmatch(level,
"EMERGENCY"))
7352 SG_ERROR(
"Unknown loglevel '%s'.\n", level);
7354 SG_INFO(
"Loglevel set to %s.\n", level);
7360 bool CSGInterface::cmd_syntax_highlight()
7362 if (m_nrhs<2 || !create_return_values(0))
7366 char* hili=get_str_from_str_or_direct(len);
7368 if (strmatch(hili,
"ON"))
7371 io->enable_syntax_highlighting();
7373 else if (strmatch(hili,
"OFF"))
7376 io->disable_syntax_highlighting();
7381 SG_INFO(
"Syntax hilighting set to %s.\n", hili);
7387 bool CSGInterface::cmd_progress()
7389 if (m_nrhs<2 || !create_return_values(0))
7393 char* progress=get_str_from_str_or_direct(len);
7395 if (strmatch(progress,
"ON"))
7396 io->enable_progress();
7397 else if (strmatch(progress,
"OFF"))
7398 io->disable_progress();
7400 SG_ERROR(
"arguments to progress are ON|OFF - found '%s'.\n", progress);
7402 SG_INFO(
"Progress set to %s.\n", progress);
7408 bool CSGInterface::cmd_get_version()
7410 if (m_nrhs!=1 || !create_return_values(1))
7413 set_int(version->get_version_revision());
7418 bool CSGInterface::cmd_help()
7420 if ((m_nrhs!=1 && m_nrhs!=2) || !create_return_values(0))
7428 SG_PRINT(
"Help is available for the following topics.\n"
7429 "-------------------------------------------\n\n");
7432 bool is_group_item=
false;
7446 SG_PRINT(
"\nUse sg('%shelp%s', '%s<topic>%s')"
7447 " to see the list of commands in this group, e.g.\n\n"
7448 "\tsg('%shelp%s', '%sFeatures%s')\n\n"
7449 "to see the list of commands for the 'Features' group.\n"
7450 "\nOr use sg('%shelp%s', '%sall%s')"
7451 " to see a brief listing of all commands.\n\nTo disable syntax"
7452 " highlighting (useful e.g. in the matlab GUI) use\n\n"
7453 "\tsg('syntax_highlight','OFF')\n",
7464 bool in_group=
false;
7466 char* command=get_string(clen);
7468 if (strmatch(
"doxygen", command) || strmatch(
"DOXYGEN", command))
7475 SG_PRINT(
"\\arg \\b %s \\verbatim %s%s%s \\endverbatim\n",
7483 SG_PRINT(
"\n\\section %s_sec %s\n",
7489 if (strmatch(
"all", command) || strmatch(
"ALL", command))
7504 SG_PRINT(
"\nCommands in group %s%s%s\n",
7528 found=strmatch(
sg_methods[i].command, command);
7533 SG_PRINT(
"Usage for %s%s%s\n\n\t%s%s%s%s%s\n",
7546 SG_PRINT(
"Commands in group %s%s%s\n\n",
7560 SG_PRINT(
"Could not find help for command %s.\n", command);
7563 SG_PRINT(
"\n\nUse sg('%shelp%s', '%s<command>%s')"
7564 " to see the usage pattern of a single command, e.g.\n\n"
7565 "\tsg('%shelp%s', '%sclassify%s')\n\n"
7566 " to see the usage pattern of the command 'classify'.\n",
7581 #ifdef TRACE_MEMORY_ALLOCS
7585 bool CSGInterface::cmd_whos()
7587 if ((m_nrhs!=1) || !create_return_values(0))
7590 #ifdef TRACE_MEMORY_ALLOCS
7591 SG_PRINT(
"Blocks allocated by shogun\n");
7592 list_memory_allocs();
7596 SG_PRINT(
"Requires shogun to be compiled with --enable-trace-mallocs\n");
7601 bool CSGInterface::cmd_send_command()
7606 char* arg=get_string(len);
7608 m_legacy_strptr=arg;
7610 char* command=get_str_from_str(len);
7616 if (strmatch(command,
sg_methods[i].command))
7620 m_nrhs=get_num_args_in_str()+1;
7624 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
7645 SG_ERROR(
"Non-supported legacy command %s.\n", command);
7652 bool CSGInterface::cmd_run_python()
7654 SG_ERROR(
"Only available in the elwms interface\n");
7658 bool CSGInterface::cmd_run_octave()
7660 SG_ERROR(
"Only available in the elwms interface\n");
7664 bool CSGInterface::cmd_run_r()
7666 SG_ERROR(
"Only available in the elwms interface\n");
7670 bool CSGInterface::cmd_pr_loqo()
7672 if (m_nrhs!=7 || !create_return_values(2))
7677 get_vector(c, lenc);
7684 get_matrix(H, nH, mH);
7690 get_matrix(A, nA, mA);
7696 get_vector(b, lenb);
7701 get_vector(l, lenl);
7706 get_vector(u, lenu);
7715 pr_loqo(n,m, c, H, A, b, l, u, x, y, 0, 5, 50, 0.05, 100, 0);
7731 void CSGInterface::print_prompt()
7742 char* CSGInterface::get_str_from_str_or_direct(int32_t& len)
7744 if (m_legacy_strptr)
7745 return get_str_from_str(len);
7747 return get_string(len);
7750 int32_t CSGInterface::get_int_from_int_or_str()
7752 if (m_legacy_strptr)
7755 char* str=get_str_from_str(len);
7756 int32_t val=strtol(str, NULL, 10);
7765 float64_t CSGInterface::get_real_from_real_or_str()
7767 if (m_legacy_strptr)
7770 char* str=get_str_from_str(len);
7780 bool CSGInterface::get_bool_from_bool_or_str()
7782 if (m_legacy_strptr)
7785 char* str=get_str_from_str(len);
7786 bool val=strtol(str, NULL, 10)!=0;
7795 void CSGInterface::get_vector_from_int_vector_or_str(int32_t*& vector, int32_t& len)
7797 if (m_legacy_strptr)
7799 len=get_vector_len_from_str(len);
7809 for (int32_t i=0; i<len; i++)
7811 str=get_str_from_str(slen);
7812 vector[i]=strtol(str, NULL, 10);
7818 get_vector(vector, len);
7821 void CSGInterface::get_vector_from_real_vector_or_str(
7824 if (m_legacy_strptr)
7826 len=get_vector_len_from_str(len);
7836 for (int32_t i=0; i<len; i++)
7838 str=get_str_from_str(slen);
7839 vector[i]=strtod(str, NULL);
7845 get_vector(vector, len);
7848 int32_t CSGInterface::get_vector_len_from_str(int32_t expected_len)
7850 int32_t num_args=get_num_args_in_str();
7852 if (expected_len==0 || num_args==expected_len)
7854 else if (num_args==2*expected_len)
7857 return expected_len;
7860 SG_ERROR(
"Expected vector length %d does not match actual length %d.\n", expected_len, num_args);
7865 char* CSGInterface::get_str_from_str(int32_t& len)
7867 if (!m_legacy_strptr)
7871 while (m_legacy_strptr[i]!=
'\0' && !isspace(m_legacy_strptr[i]))
7876 for (i=0; i<len; i++)
7877 str[i]=m_legacy_strptr[i];
7881 if (m_legacy_strptr[len]==
'\0')
7882 m_legacy_strptr=NULL;
7885 m_legacy_strptr=m_legacy_strptr+len;
7892 int32_t CSGInterface::get_num_args_in_str()
7894 if (!m_legacy_strptr)
7900 while (m_legacy_strptr[i]!=
'\0')
7902 if (!isspace(m_legacy_strptr[i]) && !in_arg)
7907 else if (isspace(m_legacy_strptr[i]) && in_arg)
7920 bool CSGInterface::handle()
7932 SG_DEBUG(
"command: %s, nrhs %d\n", command, m_nrhs);
7936 if (strmatch(command,
sg_methods[i].command))
7947 SG_ERROR(
"Usage: %s%s%s\n\n\t%s%s%s%s%s\n",
7958 SG_ERROR(
"Non-supported command %s%s%s.\n",
7977 SG_ERROR(
"Unknown command %s%s%s.\n",